Updating deps, fixing model existence checking for prefixed models #43

Merged
skobkin merged 3 commits from update_deps into main 2024-11-06 16:43:04 +00:00
2 changed files with 27 additions and 30 deletions
Showing only changes of commit a49ce5ab28 - Show all commits

View file

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

View file

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