Using local search to check model existence (fixes #42).
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Alexey Skobkin 2024-11-06 19:39:21 +03:00
parent 3406bc2601
commit a49ce5ab28
Signed by: skobkin
GPG key ID: 4389E670595BF8A8
2 changed files with 27 additions and 30 deletions

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
"github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai"
"log/slog" "log/slog"
"slices"
"strconv" "strconv"
) )
@ -113,36 +114,33 @@ func (l *LlmConnector) Summarize(text string, model string) (string, error) {
return resp.Choices[0].Message.Content, nil return resp.Choices[0].Message.Content, nil
} }
func (l *LlmConnector) GetModels() []string { func (l *LlmConnector) HasAllModels(modelIds []string) (bool, map[string]bool) {
var result []string modelList, err := l.client.ListModels(context.Background())
models, err := l.client.ListModels(context.Background())
if err != nil { if err != nil {
slog.Error("llm: Model list request failed", "error", err) slog.Error("llm: Model list request failed", "error", err)
return result
} }
slog.Info("Model list retrieved", "models", models) slog.Info("llm: Returned model list", "models", modelList)
slog.Info("llm: Checking for requested models", "requested", modelIds)
for _, model := range models.Models { requestedModelsCount := len(modelIds)
result = append(result, model.ID) searchResult := make(map[string]bool, requestedModelsCount)
for _, modelId := range modelIds {
searchResult[modelId] = false
} }
return result for _, model := range modelList.Models {
if slices.Contains(modelIds, model.ID) {
searchResult[model.ID] = true
}
} }
func (l *LlmConnector) HasModel(id string) bool { for _, v := range searchResult {
model, err := l.client.GetModel(context.Background(), id) if !v {
if err != nil { return false, searchResult
slog.Error("llm: Model request failed", "error", err) }
} }
slog.Debug("llm: Returned model", "model", model) return true, searchResult
if model.ID != "" {
return true
}
return false
} }

View file

@ -28,12 +28,11 @@ func main() {
slog.Info("Checking models availability") slog.Info("Checking models availability")
for _, model := range []string{models.TextRequestModel, models.SummarizeModel} { hasAll, searchResult := llmc.HasAllModels([]string{models.TextRequestModel, models.SummarizeModel})
if !llmc.HasModel(model) { if !hasAll {
slog.Error("Model not unavailable", "model", model) slog.Error("Not all models are available", "result", searchResult)
os.Exit(1) os.Exit(1)
} }
}
slog.Info("All needed models are available") slog.Info("All needed models are available")