MCPcopy
hub / github.com/openai/swarm / create_mock_response

Function create_mock_response

tests/mock_client.py:8–41  ·  view source on GitHub ↗
(message, function_calls=[], model="gpt-4o")

Source from the content-addressed store, hash-verified

6
7
8def create_mock_response(message, function_calls=[], model="gpt-4o"):
9 role = message.get("role", "assistant")
10 content = message.get("content", "")
11 tool_calls = (
12 [
13 ChatCompletionMessageToolCall(
14 id="mock_tc_id",
15 type="function",
16 function=Function(
17 name=call.get("name", ""),
18 arguments=json.dumps(call.get("args", {})),
19 ),
20 )
21 for call in function_calls
22 ]
23 if function_calls
24 else None
25 )
26
27 return ChatCompletion(
28 id="mock_cc_id",
29 created=1234567890,
30 model=model,
31 object="chat.completion",
32 choices=[
33 Choice(
34 message=ChatCompletionMessage(
35 role=role, content=content, tool_calls=tool_calls
36 ),
37 finish_reason="stop",
38 index=0,
39 )
40 ],
41 )
42
43
44class MockOpenAIClient:

Callers 5

mock_openai_clientFunction · 0.90
test_tool_callFunction · 0.90
test_execute_tools_falseFunction · 0.90
test_handoffFunction · 0.90
mock_client.pyFile · 0.85

Calls

no outgoing calls

Tested by 4

mock_openai_clientFunction · 0.72
test_tool_callFunction · 0.72
test_execute_tools_falseFunction · 0.72
test_handoffFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…