-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
739 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Sarm copy tests.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import json | ||
from unittest.mock import AsyncMock | ||
|
||
from openai.types.chat import ChatCompletionMessage | ||
from openai.types.chat.chat_completion import ChatCompletion, Choice | ||
from openai.types.chat.chat_completion_message_tool_call import ( | ||
ChatCompletionMessageToolCall, | ||
Function, | ||
) | ||
|
||
|
||
def create_mock_response(message, function_calls=[], model="gpt-4o-mini"): | ||
role = message.get("role", "assistant") | ||
content = message.get("content", "") | ||
tool_calls = ( | ||
[ | ||
ChatCompletionMessageToolCall( | ||
id="mock_tc_id", | ||
type="function", | ||
function=Function( | ||
name=call.get("name", ""), | ||
arguments=json.dumps(call.get("args", {})), | ||
), | ||
) | ||
for call in function_calls | ||
] | ||
if function_calls | ||
else None | ||
) | ||
|
||
return ChatCompletion( | ||
id="mock_cc_id", | ||
created=1234567890, | ||
model=model, | ||
object="chat.completion", | ||
choices=[ | ||
Choice( | ||
message=ChatCompletionMessage( | ||
role=role, content=content, tool_calls=tool_calls | ||
), | ||
finish_reason="stop", | ||
index=0, | ||
) | ||
], | ||
) | ||
|
||
|
||
class MockOpenAIClient: | ||
def __init__(self): | ||
self.chat = AsyncMock() | ||
self.chat.completions = AsyncMock() | ||
|
||
def set_response(self, response: ChatCompletion): | ||
""" | ||
Set the mock to return a specific response. | ||
:param response: A ChatCompletion response to return. | ||
""" | ||
self.chat.completions.create.return_value = response | ||
|
||
def set_sequential_responses(self, responses: list[ChatCompletion]): | ||
""" | ||
Set the mock to return different responses sequentially. | ||
:param responses: A list of ChatCompletion responses to return in order. | ||
""" | ||
self.chat.completions.create.side_effect = responses | ||
|
||
def assert_create_called_with(self, **kwargs): | ||
self.chat.completions.create.assert_called_with(**kwargs) |
Oops, something went wrong.