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:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user