issue 215: Use OpenAI official API to list available models #58

Merged
darthrubik merged 1 commits from bugfix/fix-list-models into master 2026-08-12 19:21:44 -05:00
2 changed files with 7 additions and 7 deletions
+4 -4
View File
@@ -505,14 +505,14 @@ struct ChatResponse {
DRH_DEFINE_TYPE_MIXED(ChatResponse, (choices), (usage))
struct ModelInfo {
std::string name;
std::string id;
};
DRH_DEFINE_TYPE_REQUIRED(ModelInfo, name)
DRH_DEFINE_TYPE_REQUIRED(ModelInfo, id)
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
+3 -3
View File
@@ -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::string url = base_url_ + "/api/tags";
std::string url = base_url_ + "/v1/models";
auto response_result = http_request(url, "GET", "");
if (!response_result) {
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();
std::vector<std::string> models;
for (const auto& m : resp.models) {
models.push_back(m.name);
for (const auto& m : resp.data) {
models.push_back(m.id);
}
return models;
}