issue 215: Use OpenAI official API to list available models

Changed list_models() to use the OpenAI-compatible /v1/models endpoint
instead of the Ollama-specific /api/tags endpoint. Updated ModelInfo and
ModelListResponse structs to match the OpenAI API response format.
This commit is contained in:
2026-08-12 19:19:20 -05:00
committed by Jacob Gamble
parent 34f317d38a
commit afbf1c5484
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)) 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
+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::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;
} }