[WIP] AWS Nova Sonic service - allow passing in tools into initializer
This commit is contained in:
@@ -97,7 +97,10 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection):
|
|||||||
access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
|
access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
|
||||||
region=os.getenv("AWS_REGION"),
|
region=os.getenv("AWS_REGION"),
|
||||||
voice_id="tiffany", # matthew, tiffany, amy
|
voice_id="tiffany", # matthew, tiffany, amy
|
||||||
# instruction=system_instruction # you could pass instruction here rather than in context
|
# you could choose to pass instruction here rather than via context
|
||||||
|
# instruction=system_instruction
|
||||||
|
# you could choose to pass tools here rather than via context
|
||||||
|
# tools=tools
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register function for function calls
|
# Register function for function calls
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, List
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from aws_sdk_bedrock_runtime.client import (
|
from aws_sdk_bedrock_runtime.client import (
|
||||||
BedrockRuntimeClient,
|
BedrockRuntimeClient,
|
||||||
@@ -28,6 +28,7 @@ from smithy_aws_core.credentials_resolvers.static import StaticCredentialsResolv
|
|||||||
from smithy_aws_core.identity import AWSCredentialsIdentity
|
from smithy_aws_core.identity import AWSCredentialsIdentity
|
||||||
from smithy_core.aio.eventstream import DuplexEventStream
|
from smithy_core.aio.eventstream import DuplexEventStream
|
||||||
|
|
||||||
|
from pipecat.adapters.schemas.tools_schema import ToolsSchema
|
||||||
from pipecat.adapters.services.aws_nova_sonic_adapter import AWSNovaSonicLLMAdapter
|
from pipecat.adapters.services.aws_nova_sonic_adapter import AWSNovaSonicLLMAdapter
|
||||||
from pipecat.frames.frames import (
|
from pipecat.frames.frames import (
|
||||||
BotStoppedSpeakingFrame,
|
BotStoppedSpeakingFrame,
|
||||||
@@ -115,7 +116,8 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
region: str,
|
region: str,
|
||||||
model: str = "amazon.nova-sonic-v1:0",
|
model: str = "amazon.nova-sonic-v1:0",
|
||||||
voice_id: str = "matthew", # matthew, tiffany, amy
|
voice_id: str = "matthew", # matthew, tiffany, amy
|
||||||
instruction: str = None,
|
instruction: Optional[str] = None,
|
||||||
|
tools: Optional[ToolsSchema] = None,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@@ -126,6 +128,7 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
self._client: BedrockRuntimeClient = None
|
self._client: BedrockRuntimeClient = None
|
||||||
self._voice_id = voice_id
|
self._voice_id = voice_id
|
||||||
self._instruction = instruction
|
self._instruction = instruction
|
||||||
|
self._tools = tools
|
||||||
self._context: AWSNovaSonicLLMContext = None
|
self._context: AWSNovaSonicLLMContext = None
|
||||||
self._stream: DuplexEventStream[
|
self._stream: DuplexEventStream[
|
||||||
InvokeModelWithBidirectionalStreamInput,
|
InvokeModelWithBidirectionalStreamInput,
|
||||||
@@ -269,11 +272,16 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
history = self._context.get_messages_for_initializing_history()
|
history = self._context.get_messages_for_initializing_history()
|
||||||
|
|
||||||
# Send prompt start event, specifying tools
|
# Send prompt start event, specifying tools
|
||||||
tools = self._context.tools
|
# Tools from context take priority over tools from __init__()
|
||||||
|
tools = (
|
||||||
|
self._context.tools
|
||||||
|
if self._context.tools
|
||||||
|
else self.get_llm_adapter().from_standard_tools(self._tools)
|
||||||
|
)
|
||||||
await self._send_prompt_start_event(tools)
|
await self._send_prompt_start_event(tools)
|
||||||
|
|
||||||
# Send system instruction
|
# Send system instruction
|
||||||
# Instruction from context takes priority
|
# Instruction from context takes priority over instruction from __init__()
|
||||||
instruction = history.instruction if history.instruction else self._instruction
|
instruction = history.instruction if history.instruction else self._instruction
|
||||||
if instruction:
|
if instruction:
|
||||||
await self._send_text_event(text=instruction, role=Role.SYSTEM)
|
await self._send_text_event(text=instruction, role=Role.SYSTEM)
|
||||||
|
|||||||
Reference in New Issue
Block a user