Merge pull request 'issue 215: Use OpenAI official API to list available models' (#58) from bugfix/fix-list-models into master
Reviewed-on: https://192.168.8.63/git/darthrubik/drharness/pulls/58
This commit was merged in pull request #58.
This commit is contained in:
@@ -505,14 +505,14 @@ struct ChatResponse {
|
|||||||
DRH_DEFINE_TYPE_MIXED(ChatResponse, (choices), (usage))
|
DRH_DEFINE_TYPE_MIXED(ChatResponse, (choices), (usage))
|
||||||
|
|
||||||
struct ModelInfo {
|
struct ModelInfo {
|
||||||
std::string name;
|
std::string id;
|
||||||
};
|
};
|
||||||
DRH_DEFINE_TYPE_REQUIRED(ModelInfo, name)
|
DRH_DEFINE_TYPE_REQUIRED(ModelInfo, id)
|
||||||
|
|
||||||
struct ModelListResponse {
|
struct ModelListResponse {
|
||||||
std::vector<ModelInfo> models;
|
std::vector<ModelInfo> data;
|
||||||
};
|
};
|
||||||
DRH_DEFINE_TYPE_REQUIRED(ModelListResponse, models)
|
DRH_DEFINE_TYPE_REQUIRED(ModelListResponse, data)
|
||||||
|
|
||||||
// Tool parameter structs
|
// Tool parameter structs
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ std::expected<Message, std::string> OllamaClient::chat(const std::vector<Message
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::expected<std::vector<std::string>, std::string> OllamaClient::list_models() const {
|
std::expected<std::vector<std::string>, std::string> OllamaClient::list_models() const {
|
||||||
std::string url = base_url_ + "/api/tags";
|
std::string url = base_url_ + "/v1/models";
|
||||||
auto response_result = http_request(url, "GET", "");
|
auto response_result = http_request(url, "GET", "");
|
||||||
if (!response_result) {
|
if (!response_result) {
|
||||||
return std::unexpected(response_result.error());
|
return std::unexpected(response_result.error());
|
||||||
@@ -269,8 +269,8 @@ std::expected<std::vector<std::string>, std::string> OllamaClient::list_models()
|
|||||||
}
|
}
|
||||||
auto resp = result.value();
|
auto resp = result.value();
|
||||||
std::vector<std::string> models;
|
std::vector<std::string> models;
|
||||||
for (const auto& m : resp.models) {
|
for (const auto& m : resp.data) {
|
||||||
models.push_back(m.name);
|
models.push_back(m.id);
|
||||||
}
|
}
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user