From a238a0bbed4608acc7045505c0c9aac665980d45 Mon Sep 17 00:00:00 2001 From: Zubeir Mohamed Date: Thu, 1 Aug 2024 22:04:48 +0100 Subject: [PATCH] Add name validation for OAI error prevention (#310) * Name validation * Fix build * Add validation only for oai provider * Use preexisting * Fix formatting --------- Co-authored-by: Zubeir Mohamed --- python/src/agnext/components/models/_openai_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/src/agnext/components/models/_openai_client.py b/python/src/agnext/components/models/_openai_client.py index de0cc9734682..4424acb7a2fe 100644 --- a/python/src/agnext/components/models/_openai_client.py +++ b/python/src/agnext/components/models/_openai_client.py @@ -120,6 +120,7 @@ def type_to_role(message: LLMMessage) -> ChatCompletionRole: def user_message_to_oai(message: UserMessage) -> ChatCompletionUserMessageParam: + assert_valid_name(message.source) if isinstance(message.content, str): return ChatCompletionUserMessageParam( content=message.content, @@ -177,6 +178,7 @@ def tool_message_to_oai( def assistant_message_to_oai( message: AssistantMessage, ) -> ChatCompletionAssistantMessageParam: + assert_valid_name(message.source) if isinstance(message.content, list): return ChatCompletionAssistantMessageParam( tool_calls=[func_call_to_oai(x) for x in message.content],