|
218 | 218 | ->withSchema($schema) |
219 | 219 | ->using(Provider::Anthropic, 'claude-3-5-sonnet-latest') |
220 | 220 | ->withPrompt('What is the answer?') |
221 | | - ->withProviderOptions(['citations' => true, 'useToolCalling' => true]) |
| 221 | + ->withProviderOptions(['citations' => true, 'use_tool_calling' => true]) |
222 | 222 | ->asStructured() |
223 | 223 | )->toThrow(InvalidArgumentException::class, 'Citations are not supported with tool calling mode'); |
224 | 224 | }); |
225 | 225 |
|
226 | 226 | it('returns structured output with default JSON mode', function (): void { |
| 227 | + FixtureResponse::fakeResponseSequence( |
| 228 | + 'v1/messages', |
| 229 | + 'anthropic/structured-with-default-json' |
| 230 | + ); |
| 231 | + |
227 | 232 | $schema = new ObjectSchema('output', 'the output object', [ |
228 | 233 | new StringSchema('answer', 'A simple answer'), |
229 | 234 | ], ['answer']); |
|
237 | 242 | expect($response->structured)->toBeArray(); |
238 | 243 | expect($response->structured)->toHaveKey('answer'); |
239 | 244 | expect($response->structured['answer'])->toBeString(); |
240 | | -})->skip(fn (): bool => ! env('ANTHROPIC_API_KEY'), 'Skipping live test - ANTHROPIC_API_KEY environment variable is not configured. Set your API key to run this test.'); |
| 245 | +}); |
| 246 | + |
| 247 | +it('works with thinking mode when use_tool_calling is true', function (): void { |
| 248 | + FixtureResponse::fakeResponseSequence( |
| 249 | + 'v1/messages', |
| 250 | + 'anthropic/structured-with-use-tool-calling' |
| 251 | + ); |
241 | 252 |
|
242 | | -it('works with thinking mode when useToolCalling is true', function (): void { |
243 | 253 | $schema = new ObjectSchema('output', 'the output object', [ |
244 | 254 | new StringSchema('answer', 'The answer about life, universe and everything'), |
245 | 255 | ], ['answer']); |
|
249 | 259 | ->using(Provider::Anthropic, 'claude-3-7-sonnet-latest') |
250 | 260 | ->withSystemPrompt('You are a helpful assistant.') |
251 | 261 | ->withPrompt('What is the meaning of life, the universe and everything in popular fiction?') |
252 | | - ->withProviderOptions(['thinking' => ['enabled' => true], 'useToolCalling' => true]) |
| 262 | + ->withProviderOptions(['thinking' => ['enabled' => true], 'use_tool_calling' => true]) |
253 | 263 | ->asStructured(); |
254 | 264 |
|
255 | 265 | expect($response->structured)->toBeArray(); |
|
262 | 272 |
|
263 | 273 | // Check that __thinking is not in structured data (it should be moved to additionalContent) |
264 | 274 | expect($response->structured)->not->toHaveKey('__thinking'); |
265 | | -})->skip(fn (): bool => ! env('ANTHROPIC_API_KEY'), 'Skipping live test - ANTHROPIC_API_KEY environment variable is not configured. Set your API key to run this test.'); |
| 275 | +}); |
266 | 276 |
|
267 | 277 | it('handles Chinese output with double quotes using tool calling', function (): void { |
268 | 278 | FixtureResponse::fakeResponseSequence('v1/messages', 'anthropic/structured-chinese-tool-calling'); |
|
283 | 293 | ->using(Provider::Anthropic, 'claude-3-5-sonnet-latest') |
284 | 294 | ->withSystemPrompt('Respond in Chinese. Use double quotes around temperature values and clothing items.') |
285 | 295 | ->withPrompt('What is the weather like today and what should I wear? The temperature is 15°C.') |
286 | | - ->withProviderOptions(['useToolCalling' => true]) |
| 296 | + ->withProviderOptions(['use_tool_calling' => true]) |
287 | 297 | ->asStructured(); |
288 | 298 |
|
289 | 299 | expect($response->structured)->toBeArray(); |
|
302 | 312 | expect($response->structured['recommendation'])->toContain('建議'); |
303 | 313 | expect($response->structured['coat_required'])->toBe(true); |
304 | 314 | }); |
305 | | - |
306 | | -it('handles Chinese output with double quotes using tool calling (live test)', function (): void { |
307 | | - $schema = new ObjectSchema( |
308 | | - 'output', |
309 | | - 'the output object', |
310 | | - [ |
311 | | - new StringSchema('weather', 'The weather forecast in Chinese with double quotes for temperature'), |
312 | | - new StringSchema('recommendation', 'Clothing recommendation in Chinese with quoted items'), |
313 | | - new BooleanSchema('coat_required', 'whether a coat is required'), |
314 | | - ], |
315 | | - ['weather', 'recommendation', 'coat_required'] |
316 | | - ); |
317 | | - |
318 | | - $response = Prism::structured() |
319 | | - ->withSchema($schema) |
320 | | - ->using(Provider::Anthropic, 'claude-3-5-sonnet-latest') |
321 | | - ->withSystemPrompt('Respond in Chinese. Use double quotes around temperature values and clothing items.') |
322 | | - ->withPrompt('What is the weather like today and what should I wear? The temperature is 15°C.') |
323 | | - ->withProviderOptions(['useToolCalling' => true]) |
324 | | - ->asStructured(); |
325 | | - |
326 | | - expect($response->structured)->toBeArray(); |
327 | | - expect($response->structured)->toHaveKeys([ |
328 | | - 'weather', |
329 | | - 'recommendation', |
330 | | - 'coat_required', |
331 | | - ]); |
332 | | - expect($response->structured['weather'])->toBeString(); |
333 | | - expect($response->structured['recommendation'])->toBeString(); |
334 | | - expect($response->structured['coat_required'])->toBeBool(); |
335 | | - |
336 | | - // Verify that Chinese text with quotes is properly handled |
337 | | - expect($response->structured['weather'])->toContain('°C'); |
338 | | - expect($response->structured['recommendation'])->toBeString(); |
339 | | -})->skip(fn (): bool => ! env('ANTHROPIC_API_KEY'), 'Skipping live test - ANTHROPIC_API_KEY environment variable is not configured. Set your API key to run this test.'); |
0 commit comments