fixes
This commit is contained in:
+8
-3
@@ -48,11 +48,15 @@ async def test_weather_tool() -> None:
|
|||||||
result = await session.run(user_input="What's the weather in Tokyo?")
|
result = await session.run(user_input="What's the weather in Tokyo?")
|
||||||
|
|
||||||
# Test that the agent calls the weather tool with the correct arguments
|
# Test that the agent calls the weather tool with the correct arguments
|
||||||
result.expect.next_event().is_function_call(name="lookup_weather", arguments={"location": "Tokyo"})
|
result.expect.next_event().is_function_call(
|
||||||
|
name="lookup_weather", arguments={"location": "Tokyo"}
|
||||||
|
)
|
||||||
|
|
||||||
# Test that the tool invocation works and returns the correct output
|
# Test that the tool invocation works and returns the correct output
|
||||||
# To mock the tool output instead, see https://docs.livekit.io/agents/build/testing/#mock-tools
|
# To mock the tool output instead, see https://docs.livekit.io/agents/build/testing/#mock-tools
|
||||||
result.expect.next_event().is_function_call_output(output="sunny with a temperature of 70 degrees.")
|
result.expect.next_event().is_function_call_output(
|
||||||
|
output="sunny with a temperature of 70 degrees."
|
||||||
|
)
|
||||||
|
|
||||||
# Evaluate the agent's response for accurate weather information
|
# Evaluate the agent's response for accurate weather information
|
||||||
await (
|
await (
|
||||||
@@ -89,7 +93,8 @@ async def test_weather_unavailable() -> None:
|
|||||||
)
|
)
|
||||||
result.expect.next_event().is_function_call_output()
|
result.expect.next_event().is_function_call_output()
|
||||||
await result.expect.next_event(type="message").judge(
|
await result.expect.next_event(type="message").judge(
|
||||||
llm, intent="Should inform the user that an error occurred and/or the weather is is currently unavailable."
|
llm,
|
||||||
|
intent="Should inform the user that an error occurred and/or the weather is is currently unavailable.",
|
||||||
)
|
)
|
||||||
|
|
||||||
# leaving this commented, some LLMs may occasionally try to retry.
|
# leaving this commented, some LLMs may occasionally try to retry.
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
@@ -12,6 +13,7 @@ from livekit.agents import (
|
|||||||
WorkerOptions,
|
WorkerOptions,
|
||||||
cli,
|
cli,
|
||||||
metrics,
|
metrics,
|
||||||
|
workflows,
|
||||||
)
|
)
|
||||||
from livekit.agents.llm import function_tool
|
from livekit.agents.llm import function_tool
|
||||||
from livekit.agents.voice import MetricsCollectedEvent
|
from livekit.agents.voice import MetricsCollectedEvent
|
||||||
@@ -48,6 +50,21 @@ class Assistant(Agent):
|
|||||||
|
|
||||||
return "sunny with a temperature of 70 degrees."
|
return "sunny with a temperature of 70 degrees."
|
||||||
|
|
||||||
|
@function_tool
|
||||||
|
async def send_email(self, context: RunContext, subject: str, body: str):
|
||||||
|
"""Use this tool to send an email on behalf of the user.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
subject: The subject of the email
|
||||||
|
body: The body of the email
|
||||||
|
"""
|
||||||
|
|
||||||
|
email_result = await workflows.GetEmailAgent(chat_ctx=self.chat_ctx)
|
||||||
|
send_to_email_address = email_result.email_address
|
||||||
|
|
||||||
|
await asyncio.sleep(1) # simulate sending the email
|
||||||
|
return "Email sent to " + send_to_email_address
|
||||||
|
|
||||||
|
|
||||||
def prewarm(proc: JobProcess):
|
def prewarm(proc: JobProcess):
|
||||||
proc.userdata["vad"] = silero.VAD.load()
|
proc.userdata["vad"] = silero.VAD.load()
|
||||||
|
|||||||
Reference in New Issue
Block a user