mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-02 09:40:42 +00:00
construct and return the correct reponse when the request is a chat completion
This commit is contained in:
parent
fae8d65582
commit
0e82d87032
@ -332,15 +332,31 @@ QHttpServerResponse Server::handleCompletionRequest(const QHttpServerRequest &re
|
|||||||
responseObject.insert("model", modelName());
|
responseObject.insert("model", modelName());
|
||||||
|
|
||||||
QJsonArray choices;
|
QJsonArray choices;
|
||||||
int index = 0;
|
|
||||||
for (QString r : responses) {
|
if (isChat) {
|
||||||
QJsonObject choice;
|
int index = 0;
|
||||||
choice.insert("text", r);
|
for (QString r : responses) {
|
||||||
choice.insert("index", index++);
|
QJsonObject choice;
|
||||||
choice.insert("logprobs", QJsonValue::Null); // We don't support
|
choice.insert("index", index++);
|
||||||
choice.insert("finish_reason", responseTokens == max_tokens ? "length" : "stop");
|
choice.insert("finish_reason", responseTokens == max_tokens ? "length" : "stop");
|
||||||
choices.append(choice);
|
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;
|
||||||
|
choice.insert("text", r);
|
||||||
|
choice.insert("index", index++);
|
||||||
|
choice.insert("logprobs", QJsonValue::Null); // We don't support
|
||||||
|
choice.insert("finish_reason", responseTokens == max_tokens ? "length" : "stop");
|
||||||
|
choices.append(choice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
responseObject.insert("choices", choices);
|
responseObject.insert("choices", choices);
|
||||||
|
|
||||||
QJsonObject usage;
|
QJsonObject usage;
|
||||||
|
Loading…
Reference in New Issue
Block a user