Add (openai): debugging points for inspector

This commit is contained in:
2023-09-25 20:41:58 +08:00
parent 2ddc688926
commit 0f47295328

View File

@@ -97,23 +97,31 @@ public static function chatCompletion($system_prompt, $user_prompt, $model)
dump($system_prompt); dump($system_prompt);
dump($user_prompt); dump($user_prompt);
$response = Http::timeout(800)->withToken(config('platform.ai.openai.api_key')) try {
->post('https://api.openai.com/v1/chat/completions', [ $response = Http::timeout(800)->withToken(config('platform.ai.openai.api_key'))
'model' => $model, ->post('https://api.openai.com/v1/chat/completions', [
'max_tokens' => 2500, 'model' => $model,
'messages' => [ 'max_tokens' => 2500,
['role' => 'system', 'content' => $system_prompt], 'messages' => [
['role' => 'user', 'content' => $user_prompt], ['role' => 'system', 'content' => $system_prompt],
], ['role' => 'user', 'content' => $user_prompt],
]); ],
]);
dump($response->body); dump($response->body());
$json_response = json_decode($response->body()); $json_response = json_decode($response->body());
$reply = $json_response?->choices[0]?->message?->content; $reply = $json_response?->choices[0]?->message?->content;
return $reply; return $reply;
}
catch(Exception $e) {
inspector()->reportException($e);
}
return null;
} }
} }