Skip to content

Commit

Permalink
Add name validation for OAI error prevention (#310)
Browse files Browse the repository at this point in the history
* Name validation

* Fix build

* Add validation only for oai provider

* Use preexisting

* Fix formatting

---------

Co-authored-by: Zubeir Mohamed <[email protected]>
  • Loading branch information
zubeirom and Zubeir Mohamed authored Aug 1, 2024
1 parent 7367b0a commit a238a0b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/src/agnext/components/models/_openai_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit a238a0b

Please sign in to comment.