-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix OpenAI Assistants API example (#915)
- Loading branch information
Showing
3 changed files
with
64 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import logging | ||
|
||
from dotenv import load_dotenv | ||
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli, llm | ||
from livekit.agents.pipeline import VoicePipelineAgent | ||
from livekit.plugins import deepgram, openai, silero | ||
from livekit.plugins.openai.beta import ( | ||
AssistantCreateOptions, | ||
AssistantLLM, | ||
AssistantOptions, | ||
OnFileUploadedInfo, | ||
) | ||
|
||
load_dotenv() | ||
logger = logging.getLogger("openai_assistant") | ||
|
||
|
||
async def entrypoint(ctx: JobContext): | ||
"""This example demonstrates a VoicePipelineAgent that uses OpenAI's Assistant API as the LLM""" | ||
initial_ctx = llm.ChatContext() | ||
|
||
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY) | ||
participant = await ctx.wait_for_participant() | ||
|
||
# When you add a ChatMessage that contain images, AssistantLLM will upload them | ||
# to OpenAI's Assistant API. | ||
# It's up to you to remove them if desired or otherwise manage them going forward. | ||
def on_file_uploaded(info: OnFileUploadedInfo): | ||
logger.info(f"{info.type} uploaded: {info.openai_file_object}") | ||
|
||
agent = VoicePipelineAgent( | ||
vad=silero.VAD.load(), | ||
stt=deepgram.STT(), | ||
llm=AssistantLLM( | ||
assistant_opts=AssistantOptions( | ||
create_options=AssistantCreateOptions( | ||
model="gpt-4o", | ||
instructions="You are a voice assistant created by LiveKit. Your interface with users will be voice.", | ||
name="KITT", | ||
) | ||
), | ||
on_file_uploaded=on_file_uploaded, | ||
), | ||
tts=openai.TTS(), | ||
chat_ctx=initial_ctx, | ||
) | ||
agent.start(ctx.room, participant) | ||
await agent.say("Hey, how can I help you today?", allow_interruptions=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/beta/README.md
This file was deleted.
Oops, something went wrong.