From c17ec41a9aca0440b1eb7060f2e3acf56a6c560e Mon Sep 17 00:00:00 2001 From: dgaloop Date: Mon, 20 Jan 2025 20:00:00 +0400 Subject: [PATCH] Initial o1 support for playground with agent --- pydantic_ai_slim/pydantic_ai/models/openai.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pydantic_ai_slim/pydantic_ai/models/openai.py b/pydantic_ai_slim/pydantic_ai/models/openai.py index 83143aaf03..6bb57b1d06 100644 --- a/pydantic_ai_slim/pydantic_ai/models/openai.py +++ b/pydantic_ai_slim/pydantic_ai/models/openai.py @@ -181,12 +181,13 @@ async def _completions_create( openai_messages = list(chain(*(self._map_message(m) for m in messages))) model_settings = model_settings or {} + is_model_o1 = "o1" in self.model_name return await self.client.chat.completions.create( model=self.model_name, messages=openai_messages, n=1, - parallel_tool_calls=True if self.tools else NOT_GIVEN, + parallel_tool_calls=True if self.tools and not is_model_o1 else NOT_GIVEN, tools=self.tools or NOT_GIVEN, tool_choice=tool_choice or NOT_GIVEN, stream=stream, @@ -250,7 +251,7 @@ def _map_message(cls, message: ModelMessage) -> Iterable[chat.ChatCompletionMess def _map_user_message(cls, message: ModelRequest) -> Iterable[chat.ChatCompletionMessageParam]: for part in message.parts: if isinstance(part, SystemPromptPart): - yield chat.ChatCompletionSystemMessageParam(role='system', content=part.content) + yield chat.ChatCompletionSystemMessageParam(role='developer', content=part.content) elif isinstance(part, UserPromptPart): yield chat.ChatCompletionUserMessageParam(role='user', content=part.content) elif isinstance(part, ToolReturnPart):