feat: connect to beaver
This commit is contained in:
@ -1,10 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from collections.abc import Sequence
|
||||
from typing import Any
|
||||
|
||||
from beaver_terminal_client import BeaverTerminalClient
|
||||
try:
|
||||
from beaver_terminal_client import BeaverTerminalClient
|
||||
except ModuleNotFoundError:
|
||||
from custom.beaver_terminal_client import BeaverTerminalClient
|
||||
from livekit.agents import llm
|
||||
from livekit.agents.types import (
|
||||
DEFAULT_API_CONNECT_OPTIONS,
|
||||
@ -14,6 +18,9 @@ from livekit.agents.types import (
|
||||
)
|
||||
from livekit.agents.utils import shortuuid
|
||||
|
||||
logger = logging.getLogger("beaver-llm")
|
||||
|
||||
|
||||
def latest_user_text(chat_ctx: llm.ChatContext) -> str:
|
||||
for message in reversed(chat_ctx.messages()):
|
||||
if message.role != "user":
|
||||
@ -49,6 +56,27 @@ class BeaverLLM(llm.LLM):
|
||||
def provider(self) -> str:
|
||||
return "beaver"
|
||||
|
||||
@property
|
||||
def session_id(self) -> str | None:
|
||||
return self._client.session_id
|
||||
|
||||
async def connect(self, *, warmup_text: str | None = None) -> str | None:
|
||||
warmup_reply: str | None = None
|
||||
async with self._lock:
|
||||
await self._client.connect()
|
||||
if warmup_text and warmup_text.strip():
|
||||
warmup_reply = await self._client.send_text(warmup_text.strip())
|
||||
|
||||
if warmup_reply is None:
|
||||
logger.info("Beaver handshake completed session_id=%s", self.session_id)
|
||||
else:
|
||||
logger.info(
|
||||
"Beaver handshake warmup completed session_id=%s reply_len=%s",
|
||||
self.session_id,
|
||||
len(warmup_reply),
|
||||
)
|
||||
return warmup_reply
|
||||
|
||||
def chat(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user