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
Copy file name to clipboardExpand all lines: includes/OpenAIApi.php
+25-26Lines changed: 25 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ public function __construct($apiKey, $logger = NULL) {
27
27
$this->client = $this->initializeClient($apiKey);
28
28
29
29
// Initialize the logger
30
-
$this->logger = $logger ?: watchdog('openai', 'There was an issue obtaining a response from OpenAI.');
30
+
$this->logger = $logger ?: watchdog('openai', 'There was an issue obtaining a response from OpenAI construct.');
31
31
}
32
32
33
33
privatefunctioninitializeClient($apiKey) {
@@ -68,7 +68,8 @@ public function getModels(): array {
68
68
continue;
69
69
}
70
70
71
-
if (!preg_match('/^(gpt|text|tts|whisper|dall-e)/i', $model['id'])) {
71
+
if (!preg_match('/^(gpt|text|tts|whisper|dall-e|o1)/i',
72
+
$model['id'])) {
72
73
continue;
73
74
}
74
75
@@ -110,16 +111,6 @@ public function filterModels(array $model_type): array {
110
111
return$models;
111
112
}
112
113
113
-
/**
114
-
* Get the latest embedding model.
115
-
*
116
-
* @return string
117
-
* The embedding model in OpenAI.
118
-
*/
119
-
publicfunctionembeddingModel(): string {
120
-
return'text-embedding-ada-002';
121
-
}
122
-
123
114
/**
124
115
* Return a ready to use answer from the completion endpoint.
125
116
*
@@ -176,7 +167,7 @@ public function completions(string $model, string $prompt, $temperature, $max_to
176
167
returntrim($result['choices'][0]['text']);
177
168
}
178
169
} catch (TransporterException | \Exception$e) {
179
-
watchdog('openai', 'There was an issue obtaining a response from OpenAI. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
170
+
watchdog('openai', 'There was an issue obtaining a response from OpenAI completions. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
180
171
}
181
172
}
182
173
@@ -234,7 +225,7 @@ public function chat(string $model, array $messages, $temperature, $max_tokens =
watchdog('openai', 'There was an issue obtaining a response from OpenAI. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
228
+
watchdog('openai', 'There was an issue obtaining a response from OpenAI chat. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
238
229
return'';
239
230
}
240
231
}
@@ -276,7 +267,7 @@ public function images(string $model, string $prompt, string $size, string $resp
276
267
$response = $response->toArray();
277
268
return$response['data'][0][$response_format];
278
269
} catch (TransporterException | \Exception$e) {
279
-
watchdog('openai', 'There was an issue obtaining a response from OpenAI. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
270
+
watchdog('openai', 'There was an issue obtaining a response from OpenAI Images. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
280
271
return'';
281
272
}
282
273
}
@@ -305,7 +296,7 @@ public function textToSpeech(string $model, string $input, string $voice, string
305
296
'response_format' => $response_format,
306
297
]);
307
298
} catch (TransporterException | \Exception$e) {
308
-
watchdog('openai', 'There was an issue obtaining a response from OpenAI. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
299
+
watchdog('openai', 'There was an issue obtaining a response from OpenAI textToSpeech. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
309
300
return'';
310
301
}
311
302
}
@@ -341,7 +332,7 @@ public function speechToText(string $model, string $file, string $task = 'transc
341
332
$result = $response->toArray();
342
333
return$result['text'];
343
334
} catch (TransporterException | \Exception$e) {
344
-
watchdog('openai', 'There was an issue obtaining a response from OpenAI. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
335
+
watchdog('openai', 'There was an issue obtaining a response from OpenAI speechToText. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
345
336
return'';
346
337
}
347
338
}
@@ -359,14 +350,14 @@ public function moderation(string $input): array {
359
350
try {
360
351
$response = $this->client->moderations()->create(
361
352
[
362
-
'model' => 'text-moderation-latest',
353
+
'model' => 'omni-moderation-latest',
363
354
'input' => trim($input),
364
355
],
365
356
);
366
357
367
358
return$response->toArray();
368
359
} catch (TransporterException | \Exception$e) {
369
-
watchdog('openai', 'There was an issue obtaining a response from OpenAI. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
360
+
watchdog('openai', 'There was an issue obtaining a response from OpenAI moderation. The error was @error.', array('@error' => $e->getMessage()), WATCHDOG_ERROR);
370
361
return [];
371
362
}
372
363
}
@@ -375,23 +366,33 @@ public function moderation(string $input): array {
0 commit comments