icy-kangaroo-1183
02/17/2025, 6:40 AMgray-monkey-83525
02/17/2025, 6:40 AMicy-kangaroo-1183
02/17/2025, 6:42 AMicy-kangaroo-1183
02/17/2025, 6:43 AMgray-monkey-83525
02/17/2025, 6:43 AMicy-kangaroo-1183
02/17/2025, 7:29 AMicy-kangaroo-1183
02/17/2025, 7:29 AMicy-kangaroo-1183
02/17/2025, 7:30 AMgray-monkey-83525
02/17/2025, 7:30 AMfrom livekit import rtc
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli
from livekit.agents.pipeline import VoicePipelineAgent
from livekit.plugins import openai, deepgram, silero
async def entrypoint(ctx: JobContext):
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
participant = await ctx.wait_for_participant()
agent = VoicePipelineAgent(
vad=silero.VAD.load(),
stt=deepgram.STT(),
llm=openai.LLM(),
tts=openai.TTS(),
chat_ctx=llm.ChatContext().append(role="system", text="You are a helpful assistant."),
)
agent.start(ctx.room, participant)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
2. FastAPI Setup: Create a FastAPI application to handle HTTP requests and communicate with the voice AI agent.
from fastapi import FastAPI, HTTPException
import requests
app = FastAPI()
@app.post("/send-to-agent/")
async def send_to_agent(user_input: str):
# Example of sending data to the voice AI agent
try:
response = requests.post("http://voice-agent-service/api/process", json={"input": user_input})
return response.json()
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.get("/")
async def read_root():
return {"Hello": "World"}
3. Communication Between FastAPI and Voice Agent: Use HTTP requests or WebSockets to send data between FastAPI and the voice AI agent. The example above shows a simple HTTP POST request to send user input to the agent.
4. WebRTC Integration: Ensure that the voice AI agent can join a LiveKit room to handle real-time voice interactions. This is managed by the LiveKit framework and does not require additional code in FastAPI.
5. Data Exchange: Use a shared database or message queue if needed to maintain session state and context between the chatbot and the voice agent.
This setup allows you to keep the voice AI agent and FastAPI application separate, ensuring that each can handle its specific tasks efficiently. If you need more detailed guidance on any specific part, let me know!
Sources:
- https://docs.livekit.io/sip/examples/sip-participant-attributes/
- https://livekit-users.slack.com/archives/C07FY8WHGPM/p1733211463.305549 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.icy-kangaroo-1183
02/17/2025, 9:38 AMicy-kangaroo-1183
02/17/2025, 9:38 AMgray-monkey-83525
02/17/2025, 9:38 AM