mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-09-11 13:29:08 +00:00
feat: add openai-compatible api models (#2683)
Signed-off-by: Shiranui <supersonic@livemail.tw> Signed-off-by: Jared Van Bortel <jared@nomic.ai> Co-authored-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
@@ -322,6 +322,7 @@ bool ChatLLM::loadModel(const ModelInfo &modelInfo)
|
||||
QVariantMap modelLoadProps;
|
||||
if (modelInfo.isOnline) {
|
||||
QString apiKey;
|
||||
QString requestUrl;
|
||||
QString modelName;
|
||||
{
|
||||
QFile file(filePath);
|
||||
@@ -332,11 +333,24 @@ bool ChatLLM::loadModel(const ModelInfo &modelInfo)
|
||||
QJsonObject obj = doc.object();
|
||||
apiKey = obj["apiKey"].toString();
|
||||
modelName = obj["modelName"].toString();
|
||||
if (modelInfo.isCompatibleApi) {
|
||||
QString baseUrl(obj["baseUrl"].toString());
|
||||
QUrl apiUrl(QUrl::fromUserInput(baseUrl));
|
||||
if (!Network::isHttpUrlValid(apiUrl)) {
|
||||
return false;
|
||||
}
|
||||
QString currentPath(apiUrl.path());
|
||||
QString suffixPath("%1/chat/completions");
|
||||
apiUrl.setPath(suffixPath.arg(currentPath));
|
||||
requestUrl = apiUrl.toString();
|
||||
} else {
|
||||
requestUrl = modelInfo.url();
|
||||
}
|
||||
}
|
||||
m_llModelType = LLModelType::API_;
|
||||
ChatAPI *model = new ChatAPI();
|
||||
model->setModelName(modelName);
|
||||
model->setRequestURL(modelInfo.url());
|
||||
model->setRequestURL(requestUrl);
|
||||
model->setAPIKey(apiKey);
|
||||
m_llModelInfo.resetModel(this, model);
|
||||
} else if (!loadNewModel(modelInfo, modelLoadProps)) {
|
||||
|
Reference in New Issue
Block a user