fixe response message returned

This commit is contained in:
Thommy Bucaille 2023-12-29 04:51:33 +01:00
parent 1e24358f78
commit 43e6d5df11
1 changed files with 15 additions and 12 deletions

View File

@ -599,14 +599,14 @@ class ChatController extends BaseController
// 'user' => Helper::isCLI() ? "system" : Auth::user()->username,
"prompt" => implode("\n", array_map(function ($message) {
$text = "";
if($message['role'] === "user") {
if ($message['role'] === "user") {
$text = "### Instruction:\n" . Auth::user()->username . ": ";
}elseif($message['role'] === "system") {
} elseif ($message['role'] === "system") {
$text = "### Context:\n";
}elseif($message['role'] === "assistant") {
} elseif ($message['role'] === "assistant") {
$text = "### Response:\nScotty: ";
}// TODO Handle tool
} // TODO Handle tool
// Clean extra whitespaces
$message['content'] = preg_replace('/\s+/', ' ', $message['content']);
$text .= $message['content'];
@ -623,12 +623,9 @@ class ChatController extends BaseController
"repeat_penalty" => 1.18
]
]);
$data = json_decode($response->getBody()->getContents(), true);
$result = (object)[
'choices' => $data['choices'],
];
return $this->handleResponse($result);
$data = json_decode($response->getBody()->getContents(), true);
return $this->handleResponse((object)$data);
} catch (\Throwable $th) {
// If Rate limit reached
if ($th->getCode() == 429) {
@ -645,8 +642,14 @@ class ChatController extends BaseController
$message = $response->choices[0]->text;
return [
"role" => "assistant",
"content" => $message,
(object)[
"choices" => (object)[
"message" => (object)[
"role" => "assistant",
"content" => $message,
]
]
]
];
// TODO: Handle tool