Skip to content

Commit

Permalink
U260924 (#1586)
Browse files Browse the repository at this point in the history
* updated title

* updated env vars

* use env var

* fixed code indentation

---------

Co-authored-by: saudsami <[email protected]>
  • Loading branch information
digitallysavvy and saudsami authored Sep 26, 2024
1 parent d3662d5 commit 911718e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
3 changes: 2 additions & 1 deletion open-ai-integration/overview/product-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: >
---

<ProductOverview
title="OpenAI Integration"
title="Conversational AI powered by Agora and OpenAI"
img="/images/real-time-stt/real-time-stt.png"
quickStartLink="/open-ai-integration/get-started/quickstart"
productFeatures={[
Expand Down Expand Up @@ -52,4 +52,5 @@ description: >
Integrating Agora’s real-time audio communication with OpenAI’s Large Language Models (LLMs) unlocks the potential for powerful, interactive voice-based applications. By combining Agora’s robust real-time audio streaming capabilities with the conversational intelligence of OpenAI’s LLMs, you can create seamless voice-enabled experiences, such as voice-powered AI assistants or interactive dialogue systems. This integration enables dynamic, responsive audio interactions, enhancing user engagement across a broad range of use cases—from customer support bots to collaborative voice-driven applications.

Most importantly, by combining the strengths of Agora and OpenAI, this integration enables the most natural form of language interaction, lowering the barrier for users to harness the power of AI and making advanced technologies more accessible than ever before.

</ProductOverview>
75 changes: 37 additions & 38 deletions shared/open-ai-integration/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,42 @@ Follow these steps to set up your Python integration project:

1. Create a new folder for the project.

```bash
mkdir realtime-agent
cd realtime-agent/
```bash
mkdir realtime-agent
cd realtime-agent/

```
```

1. Create the following structure for your project:

```
/realtime-agent
├── __init__.py
├── .env
├── agent.py
├── agora
│   ├── __init__.py
│   ├── requirements.txt
│   └── rtc.py
└── realtimeapi
├── __init__.py
├── client.py
├── messages.py
└── util.py
```

<Admonition type="info" title="Note">
This project uses the OpenAI [`realtimeapi-examples`](https://openai.com/api/) package.Download the project and unzip it into your `realtime-agent` folder.
</Admonition>

The following descriptions provide an overview of the key files in the project:

- `agent.py`: The primary script responsible for executing the `RealtimeKitAgent`. It integrates Agora's functionality from the `agora/rtc.py` module and OpenAI's capabilities from the `realtimeapi` package.
- `agora/rtc.py`: Contains an implementation of the server-side Agora Python Voice SDK.
- `realtimeapi/`: Contains the classes and methods that interact with OpenAI’s Realtime API.

The [Complete code](#complete-integration-code) for `agent.py` and `rtc.py` is provided at the bottom of this page.
```
/realtime-agent
├── __init__.py
├── .env
├── agent.py
├── agora
│   ├── __init__.py
│   ├── requirements.txt
│   └── rtc.py
└── realtimeapi
├── __init__.py
├── client.py
├── messages.py
└── util.py
```

<Admonition type="info" title="Note">
This project uses the OpenAI [`realtimeapi-examples`](https://openai.com/api/) package.Download the project and unzip it into your
`realtime-agent` folder.
</Admonition>

The following descriptions provide an overview of the key files in the project:

- `agent.py`: The primary script responsible for executing the `RealtimeKitAgent`. It integrates Agora's functionality from the `agora/rtc.py` module and OpenAI's capabilities from the `realtimeapi` package.
- `agora/rtc.py`: Contains an implementation of the server-side Agora Python Voice SDK.
- `realtimeapi/`: Contains the classes and methods that interact with OpenAI’s Realtime API.

The [Complete code](#complete-integration-code) for `agent.py` and `rtc.py` is provided at the bottom of this page.

1. Open your `.env` file and add the following keys:

Expand All @@ -68,9 +69,6 @@ Follow these steps to set up your Python integration project:
# OpenAI API key for authentication
OPENAI_API_KEY=your_openai_api_key_here
# API base URI for the Realtime API
REALTIME_API_BASE_URI=wss://api.openai.com
```

1. Install the dependencies:
Expand All @@ -88,7 +86,8 @@ The `RealtimeKitAgent` class integrates Agora's audio communication capabilities
The `setup_and_run_agent` method sets up the `RealtimeKitAgent` by connecting to an Agora channel using the provided `RtcEngine` and initializing a session with the OpenAI Realtime API client. It sends configuration messages to set up the session and define conversation parameters, such as the system message and output audio format, before starting the agent's operations. The method uses asynchronous execution to handle both listening for the session start and sending conversation configuration updates concurrently. It ensures that the connection is properly managed and cleaned up after use, even in cases of exceptions, early exits, or shutdowns.
<Admonition type="info" title="Note">
UIDs in the Python SDK are set using a string value. Agora recommends using only numerical values for UID strings to ensure compatibility with all Agora products and extensions.
UIDs in the Python SDK are set using a string value. Agora recommends using only numerical values for UID strings to ensure compatibility
with all Agora products and extensions.
</Admonition>
```python
Expand Down Expand Up @@ -695,19 +694,19 @@ async def shutdown(loop, signal=None):
print(f"Received exit signal {signal.name}...")

tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]

print(f"Cancelling {len(tasks)} outstanding tasks")
for task in tasks:
task.cancel()

await asyncio.gather(*tasks, return_exceptions=True)
loop.stop()

if __name__ == "__main__": # Load environment variables and run the agent
if **name** == "**main**": # Load environment variables and run the agent
load_dotenv()
asyncio.run(
RealtimeKitAgent.entry_point(
engine=RtcEngine(appid="aab8b8f5a8cd4469a63042fcfafe7063"),
engine=RtcEngine(appid=os.getenv("AGORA_APP_ID")),
inference_config=InferenceConfig(
system_message="""\\
You are a helpful assistant. If asked about the weather, make sure to use the provided tool to get that information. \\
Expand Down

0 comments on commit 911718e

Please sign in to comment.