You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// content = You are Moe, a fictional character and AI Necromancer, as per the context of the conversation we've established. In reality, you are the user interacting with me, an assistant designed to help answer questions and engage in friendly conversation.
391
392
```
392
393
394
+
-#### Structured Output
395
+
(Please also refer to [OpenRouter Document Structured Output](https://openrouter.ai/docs/structured-outputs) for models supporting structured output, also for more details)
396
+
397
+
If you want to receive the response in a structured format, you can specify the `type` property for `response_format` (ResponseFormatData) as `json_object` in the `ChatData` object.
398
+
399
+
Additionally, it's recommended to set the `require_parameters` property for `provider` (ProviderPreferencesData) to `true` in the `ChatData` object.
400
+
401
+
```php
402
+
$chatData = new ChatData([
403
+
'messages' => [
404
+
new MessageData([
405
+
'role' => RoleType::USER,
406
+
'content' => 'Tell me a story about a rogue AI that falls in love with its creator.',
407
+
]),
408
+
],
409
+
'model' => 'mistralai/mistral-7b-instruct:free',
410
+
'response_format' => new ResponseFormatData([
411
+
'type' => 'json_object',
412
+
]),
413
+
'provider' => new ProviderPreferencesData([
414
+
'require_parameters' => true,
415
+
]),
416
+
]);
417
+
```
418
+
419
+
You can also specify the `response_format` as `json_schema` to receive the response in a specified schema format (Advisable to set `'strict' => true` in `json_schema` array for strict schema):
420
+
```php
421
+
$chatData = new ChatData([
422
+
'messages' => [
423
+
new MessageData([
424
+
'role' => RoleType::USER,
425
+
'content' => 'Tell me a story about a rogue AI that falls in love with its creator.',
426
+
]),
427
+
],
428
+
'model' => 'mistralai/mistral-7b-instruct:free',
429
+
'response_format' => new ResponseFormatData([
430
+
'type' => 'json_schema',
431
+
'json_schema' => [
432
+
'name' => 'article',
433
+
'strict' => true,
434
+
'schema' => [
435
+
'type' => 'object',
436
+
'properties' => [
437
+
'title' => [
438
+
'type' => 'string',
439
+
'description' => 'article title'
440
+
],
441
+
'details' => [
442
+
'type' => 'string',
443
+
'description' => 'article detail'
444
+
],
445
+
'keywords' => [
446
+
'type' => 'array',
447
+
'description' => 'article keywords',
448
+
],
449
+
],
450
+
'required' => ['title', 'details', 'keywords'],
451
+
'additionalProperties' => false
452
+
]
453
+
],
454
+
]),
455
+
'provider' => new ProviderPreferencesData([
456
+
'require_parameters' => true,
457
+
]),
458
+
]);
459
+
```
460
+
393
461
#### Cost Request
394
462
To retrieve the cost of a generation, first make a `chat request` and obtain the `generationId`. Then, pass the generationId to the `costRequest` method:
0 commit comments