MCPcopy Create free account
hub / github.com/MiniMax-AI/Mini-Agent / test_openai_tool_calling

Function test_openai_tool_calling

tests/test_llm_clients.py:168–224  ·  view source on GitHub ↗

Test OpenAI client with tool calling.

()

Source from the content-addressed store, hash-verified

166
167@pytest.mark.asyncio
168async def test_openai_tool_calling():
169 """Test OpenAI client with tool calling."""
170 print("\n=== Testing OpenAI Tool Calling ===")
171
172 config = load_config()
173
174 # Create OpenAI client
175 client = OpenAIClient(
176 api_key=config["api_key"],
177 api_base="https://api.minimaxi.com/v1",
178 model=config.get("model", "MiniMax-M2.5"),
179 )
180
181 # Define tool using dict format (will be converted internally for OpenAI)
182 tools = [
183 {
184 "name": "get_weather",
185 "description": "Get weather of a location",
186 "input_schema": {
187 "type": "object",
188 "properties": {
189 "location": {
190 "type": "string",
191 "description": "The city and state, e.g. San Francisco, US",
192 }
193 },
194 "required": ["location"],
195 },
196 }
197 ]
198
199 # Messages requesting tool use
200 messages = [
201 Message(role="user", content="What's the weather in New York?"),
202 ]
203
204 try:
205 response = await client.generate(messages=messages, tools=tools)
206
207 print(f"Response: {response.content}")
208 print(f"Thinking: {response.thinking}")
209 print(f"Tool calls: {response.tool_calls}")
210
211 if response.tool_calls:
212 assert len(response.tool_calls) > 0
213 assert response.tool_calls[0].function.name == "get_weather"
214 print("✅ OpenAI tool calling test passed")
215 else:
216 print("⚠️ Warning: LLM didn't use tools, but request succeeded")
217
218 return True
219 except Exception as e:
220 print(f"❌ OpenAI tool calling test failed: {e}")
221 import traceback
222
223 traceback.print_exc()
224 return False
225

Callers 1

mainFunction · 0.85

Calls 5

generateMethod · 0.95
OpenAIClientClass · 0.90
MessageClass · 0.90
getMethod · 0.80
load_configFunction · 0.70

Tested by

no test coverage detected