Skip to content

Commit 4827e6c

Browse files
committed
fix: fix format for vision endpoint for OpenAI
1 parent 931d4e1 commit 4827e6c

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

core/components/modai/src/Services/OpenAI.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,30 +202,48 @@ public function getVision(string $prompt, string $image, VisionConfig $config):
202202
{
203203
$apiKey = $this->getApiKey();
204204

205-
$input = $config->getOptions();
205+
$input = $config->getOptions(function ($options) {
206+
$gptConfig = [];
207+
208+
foreach ($options as $key => $value) {
209+
switch ($key) {
210+
case 'max_tokens':
211+
$gptConfig['max_output_tokens'] = $value;
212+
break;
213+
case 'temperature':
214+
$value = floatval($value);
215+
if ($value >= 0) {
216+
$gptConfig['temperature'] = $value;
217+
}
218+
break;
219+
default:
220+
$gptConfig[$key] = $value;
221+
}
222+
}
223+
224+
return $gptConfig;
225+
});
226+
206227
$input['model'] = $config->getModel();
207-
$input['messages'] = [
228+
$input['input'] = [
208229
[
209230
'role' => 'user',
210231
'content' => [
211232
[
212-
"type" => "text",
233+
"type" => "input_text",
213234
"text" => $prompt,
214235
],
215236
[
216-
"type" => "image_url",
217-
"image_url" => ["url" => $image],
237+
'type' => 'input_image',
238+
'detail' => 'auto',
239+
'image_url' => $image,
218240
],
219241
]
220242
]
221243
];
222244

223245
if ($config->isStream()) {
224246
$input['stream'] = true;
225-
226-
$input['stream_options'] = [
227-
'include_usage' => true,
228-
];
229247
}
230248

231249
return AIResponse::new(self::getServiceName(), $config->getRawModel())

0 commit comments

Comments
 (0)