Skip to content

Commit c0a6c9f

Browse files
committed
use openai response_format
1 parent 051a223 commit c0a6c9f

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

config/translator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
],
1515
'openai' => [
1616
'model' => 'gpt-4o',
17-
'prompt' => "
18-
Translate the following json to the locale '{targetLocale}' while preserving the keys.
19-
Your answer must always be a valid and parsable json string.
20-
",
17+
'prompt' => "Translate the following json to the locale '{targetLocale}' while preserving the keys.",
2118
],
2219
],
2320
],

src/Services/Grammar/OpenAiService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function fixAll(array $texts): array
2222
->flatMap(function (Collection $chunk) {
2323
$response = OpenAI::chat()->create([
2424
'model' => $this->model,
25+
'response_format' => ['type' => 'json_object'],
2526
'messages' => [
2627
[
2728
'role' => 'system',

src/Services/Translate/OpenAiService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function translateAll(array $texts, string $targetLocale): array
2222
->flatMap(function (Collection $chunk) use ($targetLocale) {
2323
$response = OpenAI::chat()->create([
2424
'model' => $this->model,
25+
'response_format' => ['type' => 'json_object'],
2526
'messages' => [
2627
[
2728
'role' => 'system',

0 commit comments

Comments
 (0)