gskaro-v1/internal/llm/models.go

39 lines
896 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package llm
import (
"encoding/json"
"fmt"
"net/http"
)
type OllamaTagsResponse struct {
Models []struct {
Name string `json:"name"`
} `json:"models"`
}
// Получить список моделей с указанного хоста
func GetModelsFromHost(host string) ([]string, error) {
resp, err := http.Get(host + "/api/tags")
if err != nil {
return nil, fmt.Errorf("ошибка запроса к %s/api/tags: %w", host, err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("Ollama вернула статус %s", resp.Status)
}
var data OllamaTagsResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, fmt.Errorf("ошибка разбора JSON: %w", err)
}
out := make([]string, 0, len(data.Models))
for _, m := range data.Models {
out = append(out, m.Name)
}
return out, nil
}