mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-18 14:39:48 +00:00
use OpenAIMessageParam for OpenAI message compatibility
This commit is contained in:
parent
172ef0c9c2
commit
279ac3bc51
2 changed files with 9 additions and 8 deletions
|
|
@ -50,6 +50,7 @@ from llama_stack.apis.inference import (
|
|||
CompletionMessage,
|
||||
Inference,
|
||||
Message,
|
||||
OpenAIMessageParam,
|
||||
SamplingParams,
|
||||
StopReason,
|
||||
SystemMessage,
|
||||
|
|
@ -516,18 +517,13 @@ class ChatAgent(ShieldRunnerMixin):
|
|||
if self.agent_config.name:
|
||||
span.set_attribute("agent_name", self.agent_config.name)
|
||||
# Convert messages to OpenAI format
|
||||
openai_messages = []
|
||||
openai_messages: list[OpenAIMessageParam] = []
|
||||
for message in input_messages:
|
||||
openai_message = await convert_message_to_openai_dict_new(message)
|
||||
openai_messages.append(openai_message)
|
||||
|
||||
# Convert tool definitions to OpenAI format
|
||||
openai_tools = None
|
||||
if self.tool_defs:
|
||||
openai_tools = []
|
||||
for tool_def in self.tool_defs:
|
||||
openai_tool = convert_tooldef_to_openai_tool(tool_def)
|
||||
openai_tools.append(openai_tool)
|
||||
openai_tools = [convert_tooldef_to_openai_tool(x) for x in (self.tool_defs or [])]
|
||||
|
||||
# Extract tool_choice from tool_config for OpenAI compatibility
|
||||
# Note: tool_choice can only be provided when tools are also provided
|
||||
|
|
|
|||
|
|
@ -1267,6 +1267,11 @@ async def prepare_openai_completion_params(**params):
|
|||
elif isinstance(value, dict):
|
||||
new_value = {k: await _prepare_value(v) for k, v in value.items()}
|
||||
elif isinstance(value, BaseModel):
|
||||
# Special handling for OpenAIMessageParam, preserve as Pydantic objects
|
||||
if hasattr(value, 'role') and hasattr(value, 'content'):
|
||||
new_value = value
|
||||
else:
|
||||
# Other BaseModel objects get converted to dicts
|
||||
new_value = value.model_dump(exclude_none=True)
|
||||
return new_value
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue