mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-18 03:25:46 +00:00
construct and return the correct reponse when the request is a chat completion
This commit is contained in:
parent
05d156fb97
commit
337c7fecac
@ -332,6 +332,20 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
|
||||
responseObject.insert("model", modelName());
|
||||
|
||||
QJsonArray choices;
|
||||
|
||||
if (isChat) {
|
||||
int index = 0;
|
||||
for (QString r : responses) {
|
||||
QJsonObject choice;
|
||||
choice.insert("index", index++);
|
||||
choice.insert("finish_reason", responseTokens == max_tokens ? "length" : "stop");
|
||||
QJsonObject message;
|
||||
message.insert("role", "assistant");
|
||||
message.insert("content", r);
|
||||
choice.insert("message", message);
|
||||
choices.append(choice);
|
||||
}
|
||||
} else {
|
||||
int index = 0;
|
||||
for (QString r : responses) {
|
||||
QJsonObject choice;
|
||||
@ -341,6 +355,8 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
|
||||
choice.insert("finish_reason", responseTokens == max_tokens ? "length" : "stop");
|
||||
choices.append(choice);
|
||||
}
|
||||
}
|
||||
|
||||
responseObject.insert("choices", choices);
|
||||
|
||||
QJsonObject usage;
|
||||
|
Loading…
Reference in New Issue
Block a user