Skip to content

Commit 64e7584

Browse files
committed
OpenAI çeviri yapılandırması güncellendi; yeni bir 'pattern' dizisi eklendi ve 'system_message' içeriği profesyonel çeviri vurgusu ile güncellendi. Kullanıcı mesajı formatında da değişiklik yapıldı.
1 parent e4aafd6 commit 64e7584

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

config/translator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020
],
2121
],
2222

23+
'pattern' => [
24+
'source' => '{source}',
25+
'target' => '{target}',
26+
'text' => '{text}',
27+
],
28+
2329
'openai' => [
2430
'api_key' => env('OPENAI_API_KEY', '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'),
2531
'base_url' => env('OPENAI_BASE_URL', 'https://api.openai.com/v1'),
2632
'model' => env('OPENAI_MODEL', 'gpt-4o-mini'),
27-
'system_message' => 'You are an assistant who translates the text from English to Turkish. Just return the translated output.',
33+
'system_message' => 'You are an experienced translator, professionally translate the incoming content into the desired language and just give the output.',
34+
// Important: patterns in user_message must match the patterns defined above ({source}, {target}, {text})
2835
'user_message' => 'Translate the following text from {source} to {target}: {text}',
2936
],
3037
];

src/Translators/OpenAITranslator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public function handle(string $source, string $target, string $text): string
1818

1919
$client = \OpenAI::factory()->withApiKey($apiKey)->withBaseUri(config('translator.openai.base_url'))->make();
2020

21+
$pattern = config('translator.pattern');
22+
$sourcePattern = $pattern['source'] ?? '{source}';
23+
$targetPattern = $pattern['target'] ?? '{target}';
24+
$textPattern = $pattern['text'] ?? '{text}';
25+
2126
$response = $client->chat()->create([
2227
'model' => config('translator.openai.model'),
2328
'messages' => [
@@ -27,7 +32,7 @@ public function handle(string $source, string $target, string $text): string
2732
],
2833
[
2934
'role' => 'user',
30-
'content' => str_replace(['{source}', '{target}', '{text}'], [$source, $target, $text], config('translator.openai.user_message')),
35+
'content' => str_replace([$sourcePattern, $targetPattern, $textPattern], [mb_strtolower($source), mb_strtolower($target), $text], config('translator.openai.user_message')),
3136
],
3237
],
3338
]);

0 commit comments

Comments
 (0)