openai-php / laravel

⚡️ OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with OpenAI API
MIT License
2.75k stars 185 forks source link

Character Encoding Issue #44

Closed ignacio-dev closed 1 year ago

ignacio-dev commented 1 year ago

Not sure if this issue has to do with this package, or with the API itself (if not related to this package, please let me know and I will delete this issue from here).

But basically, all characters with tildes are being omitted.

For example, some Spanish words like "canción" are returning as "cancin".

gehrisandro commented 1 year ago

It works for me:

$client = OpenAI::client('****');

$response = $client->chat()->create([
    'model' => 'gpt-3.5-turbo',
    'messages' => [
        ['role' => 'user', 'content' => 'Translate to spanish: "song"'],
    ],
]);

dd($response->toArray());

// output
array:6 [
  "id" => "chatcmpl-7KCInnSn7CuzFDOOnBW5azJuWqIA9"
  "object" => "chat.completion"
  "created" => 1685048205
  "model" => "gpt-3.5-turbo-0301"
  "choices" => array:1 [
    0 => array:3 [
      "index" => 0
      "message" => array:2 [
        "role" => "assistant"
        "content" => "canción" // <------- SEE HERE
      ]
      "finish_reason" => "stop"
    ]
  ]
  "usage" => array:3 [
    "prompt_tokens" => 15
    "completion_tokens" => 3
    "total_tokens" => 18
  ]
]