Store enabled tools in lmcli.Context

This commit is contained in:
Matt Low 2024-03-12 08:01:53 +00:00
parent 7d56726c78
commit 2c7bdd8ebf
2 changed files with 16 additions and 14 deletions

View File

@ -8,7 +8,6 @@ import (
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/tools"
"git.mlow.ca/mlow/lmcli/pkg/util"
"github.com/charmbracelet/lipgloss"
)
@ -27,19 +26,11 @@ func FetchAndShowCompletion(ctx *lmcli.Context, messages []model.Message) ([]mod
return nil, err
}
var toolBag []model.Tool
for _, toolName := range *ctx.Config.Tools.EnabledTools {
tool, ok := tools.AvailableTools[toolName]
if ok {
toolBag = append(toolBag, tool)
}
}
requestParams := model.RequestParameters{
Model: *ctx.Config.Defaults.Model,
MaxTokens: *ctx.Config.Defaults.MaxTokens,
Temperature: *ctx.Config.Defaults.Temperature,
ToolBag: toolBag,
ToolBag: ctx.EnabledTools,
}
var apiReplies []model.Message

View File

@ -5,19 +5,22 @@ import (
"os"
"path/filepath"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/provider"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/provider/anthropic"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/provider/openai"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/tools"
"git.mlow.ca/mlow/lmcli/pkg/util/tty"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Context struct {
Config Config
Config *Config
Store ConversationStore
Chroma *tty.ChromaHighlighter
EnabledTools []model.Tool
}
func NewContext() (*Context, error) {
@ -32,14 +35,22 @@ func NewContext() (*Context, error) {
if err != nil {
return nil, fmt.Errorf("Error establishing connection to store: %v", err)
}
s, err := NewSQLStore(db)
store, err := NewSQLStore(db)
if err != nil {
Fatal("%v\n", err)
}
hl := tty.NewChromaHighlighter("markdown", *config.Chroma.Formatter, *config.Chroma.Style)
chroma := tty.NewChromaHighlighter("markdown", *config.Chroma.Formatter, *config.Chroma.Style)
return &Context{*config, s, hl}, nil
var enabledTools []model.Tool
for _, toolName := range *config.Tools.EnabledTools {
tool, ok := tools.AvailableTools[toolName]
if ok {
enabledTools = append(enabledTools, tool)
}
}
return &Context{config, store, chroma, enabledTools}, nil
}
func (c *Context) GetModels() (models []string) {