Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move src/examples to examples #70

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Currently implemented services:

If you'd like to [implement a service]((https://github.com/daily-co/daily-ai-sdk/tree/main/src/dailyai/services)), we welcome PRs! Our goal is to support lots of services in all of the above categories, plus new categories (like real-time video) as they emerge.

## Step 1: Get started
## Getting started

Today, the easiest way to get started with `dailyai` is to use [Daily](https://www.daily.co/) as your transport service. This toolkit started life as an internal SDK at Daily and millions of minutes of AI conversation have been served using it and its earlier prototype incarnations. (The [transport base class](https://github.com/daily-co/daily-ai-sdk/blob/main/src/dailyai/services/base_transport_service.py) is easy to extend, though, so feel free to submit PRs if you'd like to implement another transport service.)

Expand All @@ -56,21 +56,20 @@ pip install dailyai

# set up an .env file with API keys
cp dot-env.template .env

# sign up for a free Daily account, if you don't already have one, and
# join the Daily room URL directly from a browser tab, then run one of the
# samples
python src/examples/foundational/02-llm-say-one-thing.py
```

## Code examples

There are two directories of examples:

- [foundational](https://github.com/daily-co/daily-ai-sdk/tree/main/src/examples/foundational) — demos that build on each other, introducing one or two concepts at a time
- [starter apps](https://github.com/daily-co/daily-ai-sdk/tree/main/src/examples/starter-apps) — complete applications that you can use as starting points for development
- [foundational](https://github.com/daily-co/daily-ai-sdk/tree/main/examples/foundational) — demos that build on each other, introducing one or two concepts at a time
- [starter apps](https://github.com/daily-co/daily-ai-sdk/tree/main/examples/starter-apps) — complete applications that you can use as starting points for development

To run the example below you to sign up for a [free Daily account](https://dashboard.daily.co/u/signup) (so you can hear the LLM talking) and create a Daily room. After that, join the room's URL directly from a browser tab and run:

```
python examples/foundational/02-llm-say-one-thing.py
```

## Hacking on the framework itself

Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Learn about the thinking behind the SDK's design.

## [Example Code](examples/)

The repo includes several example apps in the `src/examples` directory. The docs explain how they work.
The repo includes several example apps in the `examples` directory. The docs explain how they work.

## [API Reference](api/)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/01-say-one-thing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if __name__ == "__main__":

### `configure()`

The `configure()` function comes from `src/examples/foundational/support/runner.py`, and it allows you to configure the examples from the command line directly, or using environment variables:
The `configure()` function comes from `examples/foundational/support/runner.py`, and it allows you to configure the examples from the command line directly, or using environment variables:

```bash
python 01-say-one-thing.py -u https://YOUR_DOMAIN.daily.co/YOUR_ROOM -k YOUR_API_KEY
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Daily AI SDK Examples

The docs in this folder pair with the example apps located in `src/examples/foundational`. They are designed to serve as a quick references for building different kinds of AI apps. But the examples also build on one another, so it can be really helpful to walk through them in order.
The docs in this folder pair with the example apps located in `examples/foundational`. They are designed to serve as a quick references for building different kinds of AI apps. But the examples also build on one another, so it can be really helpful to walk through them in order.

To start, you can learn about the overall structure of the examples in [01 - Say One Thing](01-say-one-thing.md).
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService

from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.open_ai_services import OpenAILLMService

from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.fal_ai_services import FalImageGenService

from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from dailyai.services.deepgram_ai_services import DeepgramTTSService
from dailyai.pipeline.frames import EndFrame, EndPipeFrame, LLMMessagesQueueFrame, TextFrame
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.fal_ai_services import FalImageGenService

from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
LLMAssistantContextAggregator,
LLMUserContextAggregator,
)
from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
from dailyai.services.open_ai_services import OpenAILLMService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.fal_ai_services import FalImageGenService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.open_ai_services import OpenAILLMService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.fal_ai_services import FalImageGenService
from dailyai.pipeline.frames import AudioFrame, EndFrame, ImageFrame, LLMMessagesQueueFrame, TextFrame
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
TranscriptionQueueFrame,
)
from dailyai.services.ai_services import AIService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
)
from typing import AsyncGenerator

from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.whisper_ai_services import WhisperSTTService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import urllib
import requests

from dotenv import load_dotenv
load_dotenv()


def configure():
parser = argparse.ArgumentParser(description="Daily AI SDK Bot Sample")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from dailyai.pipeline.frames import Frame, AudioFrame, LLMResponseEndFrame, LLMMessagesQueueFrame
from typing import AsyncGenerator

from examples.support.runner import configure
from runner import configure

from dotenv import load_dotenv
load_dotenv()

sounds = {}
sound_files = [
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions src/examples/server/auth.py → examples/server/auth.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import time
import urllib

from dotenv import load_dotenv
import requests
from flask import jsonify
import os

load_dotenv()


def get_meeting_token(room_name, daily_api_key, token_expiry):
api_path = os.getenv('DAILY_API_PATH') or 'https://api.daily.co/v1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from flask import Flask, jsonify, request, redirect
from flask_cors import CORS
from examples.server.auth import get_meeting_token

from dotenv import load_dotenv
from auth import get_meeting_token

from dotenv import load_dotenv
load_dotenv()

app = Flask(__name__)
Expand Down Expand Up @@ -95,7 +95,7 @@ def start_bot(bot_path, args=None):

@app.route("/spin-up-kitty", methods=["GET", "POST"])
def spin_up_kitty():
return start_bot("./src/examples/foundational/10-wake-word.py")
return start_bot("./examples/foundational/10-wake-word.py")


@app.route("/healthz")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.open_ai_services import OpenAILLMService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from dailyai.services.open_ai_services import OpenAILLMService
from dailyai.services.deepgram_ai_services import DeepgramTTSService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from examples.support.runner import configure
from dailyai.pipeline.frames import (
OpenAILLMContextFrame,
TranscriptionQueueFrame,
Expand All @@ -36,6 +35,11 @@
ChatCompletionToolParam,
)

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format="%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)
Expand Down
58 changes: 58 additions & 0 deletions examples/starter-apps/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import argparse
import os
import time
import urllib
import requests


def configure():
parser = argparse.ArgumentParser(description="Daily AI SDK Bot Sample")
parser.add_argument(
"-u",
"--url",
type=str,
required=False,
help="URL of the Daily room to join")
parser.add_argument(
"-k",
"--apikey",
type=str,
required=False,
help="Daily API Key (needed to create an owner token for the room)",
)

args, unknown = parser.parse_known_args()

url = args.url or os.getenv("DAILY_SAMPLE_ROOM_URL")
key = args.apikey or os.getenv("DAILY_API_KEY")

if not url:
raise Exception(
"No Daily room specified. use the -u/--url option from the command line, or set DAILY_SAMPLE_ROOM_URL in your environment to specify a Daily room URL.")

if not key:
raise Exception("No Daily API key specified. use the -k/--apikey option from the command line, or set DAILY_API_KEY in your environment to specify a Daily API key, available from https://dashboard.daily.co/developers.")

# Create a meeting token for the given room with an expiration 1 hour in
# the future.
room_name: str = urllib.parse.urlparse(url).path[1:]
expiration: float = time.time() + 60 * 60

res: requests.Response = requests.post(
f"https://api.daily.co/v1/meeting-tokens",
headers={
"Authorization": f"Bearer {key}"},
json={
"properties": {
"room_name": room_name,
"is_owner": True,
"exp": expiration}},
)

if res.status_code != 200:
raise Exception(
f"Failed to create meeting token: {res.status_code} {res.text}")

token: str = res.json()["token"]

return (url, token)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
UserResponseAggregator,
LLMResponseAggregator,
)
from examples.support.runner import configure
from dailyai.pipeline.frames import (
EndPipeFrame,
LLMMessagesQueueFrame,
Expand All @@ -43,6 +42,11 @@
)
from dailyai.services.ai_services import FrameLogger, AIService

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
logger.setLevel(logging.DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
from dailyai.services.azure_ai_services import AzureTTSService
from dailyai.services.open_ai_services import OpenAILLMService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from examples.support.runner import configure

from runner import configure

from dotenv import load_dotenv
load_dotenv()

logging.basicConfig(format=f"%(levelno)s %(asctime)s %(message)s")
logger = logging.getLogger("dailyai")
Expand Down