and fixing anthropic demos

This commit is contained in:
Kwindla Hultman Kramer
2024-08-14 23:14:20 -07:00
parent 2b26d7182f
commit 253765c611
3 changed files with 15 additions and 10 deletions

View File

@@ -62,7 +62,7 @@ async def main():
)
llm = AnthropicLLMService(
api_key=os.getenv("OPENAI_API_KEY"),
api_key=os.getenv("ANTHROPIC_API_KEY"),
model="claude-3-5-sonnet-20240620"
)
llm.register_function("get_weather", get_weather)
@@ -86,10 +86,12 @@ async def main():
# todo: test with very short initial user message
messages = [{"role": "system",
"content": "You are a helpful assistant who can report the weather in any location in the universe. Respond concisely. Your response will be turned into speech so use only simple words and punctuation."},
{"role": "user",
"content": " Start the conversation by introducing yourself."}]
# messages = [{"role": "system",
# "content": "You are a helpful assistant who can report the weather in any location in the universe. Respond concisely. Your response will be turned into speech so use only simple words and punctuation."},
# {"role": "user",
# "content": " Start the conversation by introducing yourself."}]
messages = [{"role": "user", "content": "Say 'hello' to start the conversation."}]
context = OpenAILLMContext(messages, tools)
context_aggregator = llm.create_context_aggregator(context)
@@ -109,7 +111,7 @@ async def main():
async def on_first_participant_joined(transport, participant):
transport.capture_participant_transcription(participant["id"])
# Kick off the conversation.
await task.queue_frames([LLMMessagesFrame(messages)])
await task.queue_frames([context_aggregator.user().get_context_frame()])
runner = PipelineRunner()

View File

@@ -137,7 +137,8 @@ If you need to use a tool, simply use the tool. Do not tell the user the tool yo
"""
messages = [{"role": "system",
"content": system_prompt,
"content": system_prompt},
{"role": "user",
"content": "Start the conversation by introducing yourself."}]
context = OpenAILLMContext(messages, tools)
@@ -161,7 +162,7 @@ If you need to use a tool, simply use the tool. Do not tell the user the tool yo
transport.capture_participant_transcription(video_participant_id)
transport.capture_participant_video(video_participant_id, framerate=0)
# Kick off the conversation.
await task.queue_frames([LLMMessagesFrame(messages)])
await task.queue_frames([context_aggregator.user().get_context_frame()])
runner = PipelineRunner()
await runner.run(task)

View File

@@ -110,7 +110,7 @@ class AnthropicLLMService(LLMService):
await self.start_ttfb_metrics()
response = await self._client.messages.create(
system=context.system,
system=context.system or [],
messages=messages,
tools=context.tools or [],
model=self._model,
@@ -255,7 +255,9 @@ class AnthropicLLMContext(OpenAILLMContext):
@classmethod
def from_messages(cls, messages: List[dict]) -> "AnthropicLLMContext":
return cls(messages=messages)
self = cls(messages=messages)
self._restructure_from_openai_messages()
return self
@classmethod
def from_image_frame(cls, frame: VisionImageRawFrame) -> "AnthropicLLMContext":