Skip to content

Commit 6157217

Browse files
davidzhaojayeshp19
andauthored
updated examples to follow APIs in the latest version (#1393)
Co-authored-by: Jayesh Parmar <[email protected]>
1 parent 5b8881e commit 6157217

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

examples/multimodal-agent/openai_agent.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,20 @@ async def get_weather(
6868
# fnc_ctx=fnc_ctx,
6969
# )
7070

71-
# create a chat context with chat history
71+
# create a chat context with chat history, these will be synchronized with the server
72+
# upon session establishment
7273
chat_ctx = llm.ChatContext()
73-
chat_ctx.append(text="I'm planning a trip to Paris next month.", role="user")
74-
chat_ctx.append(
75-
text="How exciting! Paris is a beautiful city. I'd be happy to suggest some must-visit places and help you plan your trip.",
76-
role="assistant",
77-
)
78-
chat_ctx.append(text="What are the must-visit places in Paris?", role="user")
79-
chat_ctx.append(
80-
text="The must-visit places in Paris are the Eiffel Tower, Louvre Museum, Notre-Dame Cathedral, and Montmartre.",
81-
role="assistant",
82-
)
74+
# chat_ctx.append(text="I'm planning a trip to Paris next month.", role="user")
75+
# chat_ctx.append(
76+
# text="How exciting! Paris is a beautiful city. I'd be happy to suggest some must-visit places and help you plan your trip.",
77+
# role="assistant",
78+
# )
8379

8480
agent = multimodal.MultimodalAgent(
8581
model=openai.realtime.RealtimeModel(
8682
voice="alloy",
8783
temperature=0.8,
88-
instructions="You are a helpful assistant",
84+
instructions="You are a helpful assistant, greet the user and help them with their trip planning",
8985
turn_detection=openai.realtime.ServerVadOptions(
9086
threshold=0.6, prefix_padding_ms=200, silence_duration_ms=500
9187
),
@@ -94,6 +90,7 @@ async def get_weather(
9490
chat_ctx=chat_ctx,
9591
)
9692
agent.start(ctx.room, participant)
93+
agent.generate_reply()
9794

9895
@agent.on("agent_speech_committed")
9996
@agent.on("agent_speech_interrupted")

examples/voice-pipeline-agent/gemini_voice_agent.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from typing import Annotated
23

34
from dotenv import load_dotenv
45
from livekit.agents import (
@@ -51,6 +52,17 @@ async def entrypoint(ctx: JobContext):
5152
participant = await ctx.wait_for_participant()
5253
logger.info(f"starting voice assistant for participant {participant.identity}")
5354

55+
fnc_ctx = llm.FunctionContext()
56+
57+
@fnc_ctx.ai_callable()
58+
async def get_weather(
59+
location: Annotated[
60+
str, llm.TypeInfo(description="The location to get the weather for")
61+
],
62+
):
63+
"""Called when the user asks about the weather. This function will return the weather for the given location."""
64+
return f"The weather in {location} is sunny."
65+
5466
agent = VoicePipelineAgent(
5567
vad=ctx.proc.userdata["vad"],
5668
stt=google.STT(),
@@ -59,6 +71,7 @@ async def entrypoint(ctx: JobContext):
5971
voice_name="en-US-Journey-D",
6072
),
6173
chat_ctx=initial_ctx,
74+
fnc_ctx=fnc_ctx,
6275
)
6376

6477
agent.start(ctx.room, participant)

0 commit comments

Comments
 (0)