fix for message handling bug on initialization
This commit is contained in:
@@ -124,7 +124,21 @@ Remember, your responses should be short. Just one or two sentences, usually."""
|
|||||||
# llm.register_function(None, fetch_weather_from_api)
|
# llm.register_function(None, fetch_weather_from_api)
|
||||||
llm.register_function("get_current_weather", fetch_weather_from_api)
|
llm.register_function("get_current_weather", fetch_weather_from_api)
|
||||||
|
|
||||||
context = OpenAILLMContext([{"role": "user", "content": "Say hello!"}], tools)
|
context = OpenAILLMContext(
|
||||||
|
[{"role": "user", "content": "Say hello!"}],
|
||||||
|
# [{"role": "user", "content": [{"type": "text", "text": "Say hello!"}]}],
|
||||||
|
# [
|
||||||
|
# {
|
||||||
|
# "role": "user",
|
||||||
|
# "content": [
|
||||||
|
# {"type": "text", "text": "Say"},
|
||||||
|
# {"type": "text", "text": "yo what's up!"},
|
||||||
|
# ],
|
||||||
|
# }
|
||||||
|
# ],
|
||||||
|
tools,
|
||||||
|
)
|
||||||
|
|
||||||
context_aggregator = llm.create_context_aggregator(context)
|
context_aggregator = llm.create_context_aggregator(context)
|
||||||
|
|
||||||
pipeline = Pipeline(
|
pipeline = Pipeline(
|
||||||
|
|||||||
@@ -45,9 +45,24 @@ class OpenAIRealtimeLLMContext(OpenAILLMContext):
|
|||||||
|
|
||||||
# todo
|
# todo
|
||||||
# - finish implementing all frames
|
# - finish implementing all frames
|
||||||
# - add message conversion functions to OpenAILLMContext base class
|
|
||||||
|
|
||||||
def from_standard_message(self, message):
|
def from_standard_message(self, message):
|
||||||
|
if message.get("role") == "user":
|
||||||
|
content = message.get("content")
|
||||||
|
if isinstance(message.get("content"), list):
|
||||||
|
content = ""
|
||||||
|
for c in message.get("content"):
|
||||||
|
if c.get("type") == "text":
|
||||||
|
content += " " + c.get("text")
|
||||||
|
else:
|
||||||
|
logger.error(
|
||||||
|
f"Unhandled content type in context message: {c.get('type')} - {message}"
|
||||||
|
)
|
||||||
|
return events.ConversationItem(
|
||||||
|
role="user",
|
||||||
|
type="message",
|
||||||
|
content=[events.ItemContent(type="input_text", text=content)],
|
||||||
|
)
|
||||||
if message.get("role") == "assistant" and message.get("tool_calls"):
|
if message.get("role") == "assistant" and message.get("tool_calls"):
|
||||||
tc = message.get("tool_calls")[0]
|
tc = message.get("tool_calls")[0]
|
||||||
return events.ConversationItem(
|
return events.ConversationItem(
|
||||||
@@ -83,7 +98,7 @@ class OpenAIRealtimeLLMContext(OpenAILLMContext):
|
|||||||
|
|
||||||
# If we have just a single "user" item, we can just send it normally
|
# If we have just a single "user" item, we can just send it normally
|
||||||
if len(messages) == 1 and messages[0].get("role") == "user":
|
if len(messages) == 1 and messages[0].get("role") == "user":
|
||||||
return messages
|
return [self.from_standard_message(messages[0])]
|
||||||
|
|
||||||
# Otherwise, let's pack everything into a single "user" message with a bit of
|
# Otherwise, let's pack everything into a single "user" message with a bit of
|
||||||
# explanation for the LLM
|
# explanation for the LLM
|
||||||
|
|||||||
Reference in New Issue
Block a user