Add latest agent improvements
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ requires-python = ">=3.9"
|
|||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"livekit-agents[openai,turn-detector,silero,cartesia,deepgram]~=1.2",
|
"livekit-agents[openai,turn-detector,silero,cartesia,deepgram]~=1.2",
|
||||||
"livekit-plugins-noise-cancellation~=0.2.1",
|
"livekit-plugins-noise-cancellation~=0.2",
|
||||||
"python-dotenv",
|
"python-dotenv",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
+14
-3
@@ -2,19 +2,20 @@ import logging
|
|||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from livekit.agents import (
|
from livekit.agents import (
|
||||||
|
NOT_GIVEN,
|
||||||
Agent,
|
Agent,
|
||||||
|
AgentFalseInterruptionEvent,
|
||||||
AgentSession,
|
AgentSession,
|
||||||
JobContext,
|
JobContext,
|
||||||
JobProcess,
|
JobProcess,
|
||||||
RoomInputOptions,
|
RoomInputOptions,
|
||||||
RoomOutputOptions,
|
MetricsCollectedEvent,
|
||||||
RunContext,
|
RunContext,
|
||||||
WorkerOptions,
|
WorkerOptions,
|
||||||
cli,
|
cli,
|
||||||
metrics,
|
metrics,
|
||||||
)
|
)
|
||||||
from livekit.agents.llm import function_tool
|
from livekit.agents.llm import function_tool
|
||||||
from livekit.agents.voice import MetricsCollectedEvent
|
|
||||||
from livekit.plugins import cartesia, deepgram, noise_cancellation, openai, silero
|
from livekit.plugins import cartesia, deepgram, noise_cancellation, openai, silero
|
||||||
from livekit.plugins.turn_detector.multilingual import MultilingualModel
|
from livekit.plugins.turn_detector.multilingual import MultilingualModel
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ class Assistant(Agent):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
instructions="""You are a helpful voice AI assistant.
|
instructions="""You are a helpful voice AI assistant.
|
||||||
You eagerly assist users with their questions by providing information from your extensive knowledge.
|
You eagerly assist users with their questions by providing information from your extensive knowledge.
|
||||||
Your responses are concise, to the point, and without any complex formatting or punctuation.
|
Your responses are concise, to the point, and without any complex formatting or punctuation including emojis, asterisks, or other symbols.
|
||||||
You are curious, friendly, and have a sense of humor.""",
|
You are curious, friendly, and have a sense of humor.""",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -75,6 +76,9 @@ async def entrypoint(ctx: JobContext):
|
|||||||
# See more at https://docs.livekit.io/agents/build/turns
|
# See more at https://docs.livekit.io/agents/build/turns
|
||||||
turn_detection=MultilingualModel(),
|
turn_detection=MultilingualModel(),
|
||||||
vad=ctx.proc.userdata["vad"],
|
vad=ctx.proc.userdata["vad"],
|
||||||
|
# allow the LLM to generate a response while waiting for the end of turn
|
||||||
|
# See more at https://docs.livekit.io/agents/build/audio/#preemptive-generation
|
||||||
|
preemptive_generation=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# To use a realtime model instead of a voice pipeline, use the following session setup instead:
|
# To use a realtime model instead of a voice pipeline, use the following session setup instead:
|
||||||
@@ -83,6 +87,13 @@ async def entrypoint(ctx: JobContext):
|
|||||||
# llm=openai.realtime.RealtimeModel()
|
# llm=openai.realtime.RealtimeModel()
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
# sometimes background noise could interrupt the agent session, these are considered false positive interruptions
|
||||||
|
# when it's detected, you may resume the agent's speech
|
||||||
|
@session.on("agent_false_interruption")
|
||||||
|
def _on_agent_false_interruption(ev: AgentFalseInterruptionEvent):
|
||||||
|
logger.info("false positive interruption, resuming")
|
||||||
|
session.generate_reply(instructions=ev.extra_instructions or NOT_GIVEN)
|
||||||
|
|
||||||
# Metrics collection, to measure pipeline performance
|
# Metrics collection, to measure pipeline performance
|
||||||
# For more information, see https://docs.livekit.io/agents/build/metrics/
|
# For more information, see https://docs.livekit.io/agents/build/metrics/
|
||||||
usage_collector = metrics.UsageCollector()
|
usage_collector = metrics.UsageCollector()
|
||||||
|
|||||||
Reference in New Issue
Block a user