Test OpenAI client with tool calling.
()
| 166 | |
| 167 | @pytest.mark.asyncio |
| 168 | async 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 |
no test coverage detected