diff --git a/app/app.go b/app/app.go index fabe47a..0aeda97 100644 --- a/app/app.go +++ b/app/app.go @@ -14,18 +14,9 @@ import ( "github.com/urfave/cli/v2" ) -//go:embed Modelfile.explain -var explainModelfile string - -//go:embed Modelfile.suggest -var suggestModelfile string - type TlmApp struct { writer *fs.File - explainModelfile string - suggestModelfile string - App *cli.App } @@ -34,14 +25,14 @@ func New(version, buildSha string) *TlmApp { con.LoadOrCreateConfig() o, _ := ollama.ClientFromEnvironment() - sug := suggest.New(o) - exp := explain.New(o) - ins := install.New(o, suggestModelfile, explainModelfile) + sug := suggest.New(o, version) + exp := explain.New(o, version) + ins := install.New(o, sug, exp) cliApp := &cli.App{ Name: "tlm", Usage: "terminal copilot, powered by CodeLLaMa.", - UsageText: "tlm explain \ntlm suggest ", + UsageText: "tlm explain ''\ntlm suggest ''", Version: version, CommandNotFound: notFound, Before: beforeRun(), diff --git a/app/Modelfile.explain b/explain/Modelfile.explain similarity index 100% rename from app/Modelfile.explain rename to explain/Modelfile.explain diff --git a/explain/api.go b/explain/api.go index 3ade066..2ad7e8c 100644 --- a/explain/api.go +++ b/explain/api.go @@ -44,7 +44,7 @@ func (e *Explain) StreamExplanationFor(mode, prompt string) error { } err := e.api.Generate(context.Background(), &ollama.GenerateRequest{ - Model: "explain:7b", + Model: e.tag, Prompt: "Explain command: " + prompt, Options: e.getParametersFor(mode), }, onResponseFunc) diff --git a/explain/cli.go b/explain/cli.go index 677ed44..207f623 100644 --- a/explain/cli.go +++ b/explain/cli.go @@ -25,7 +25,7 @@ func (e *Explain) before(_ *cli.Context) error { found := false for _, model := range list.Models { - if model.Name == e.modelfileName { + if model.Name == e.tag { found = true break } diff --git a/explain/explain.go b/explain/explain.go index 5d5b7b9..2e7b903 100644 --- a/explain/explain.go +++ b/explain/explain.go @@ -1,15 +1,30 @@ package explain import ( + _ "embed" + "fmt" ollama "github.com/jmorganca/ollama/api" ) +//go:embed Modelfile.explain +var modelFile string + type Explain struct { - api *ollama.Client - modelfileName string + api *ollama.Client + + tag string + modelfile string +} + +func (e *Explain) Tag() string { + return e.tag +} + +func (e *Explain) Modelfile() string { + return e.modelfile } -func New(api *ollama.Client) *Explain { - e := &Explain{api: api, modelfileName: "explain:7b"} - return e +func New(api *ollama.Client, version string) *Explain { + modelfileName := fmt.Sprintf("tlm:%s-e", version) + return &Explain{api: api, tag: modelfileName, modelfile: modelFile} } diff --git a/explain/explain_test.go b/explain/explain_test.go index 2c9b8d3..a2f8cbc 100644 --- a/explain/explain_test.go +++ b/explain/explain_test.go @@ -13,5 +13,5 @@ func TestExplain(t *testing.T) { con.LoadOrCreateConfig() o, _ := ollama.ClientFromEnvironment() - explain.New(o) + explain.New(o, "") } diff --git a/install/api.go b/install/api.go index e0e3409..da95401 100644 --- a/install/api.go +++ b/install/api.go @@ -18,7 +18,7 @@ func (i *Install) installModelfile(name, modelfile string) error { return err } -func (i *Install) deployTlm(suggestModelfile, explainModelfile string) { +func (i *Install) deployTlm() { var err error _ = spinner.New().Type(spinner.Line).Title(" Getting latest CodeLLaMa").Action(func() { @@ -34,18 +34,19 @@ func (i *Install) deployTlm(suggestModelfile, explainModelfile string) { // 6. Install the modelfile (Suggest) _ = spinner.New().Type(spinner.Line).Title(" Creating Modelfile for suggestions").Action(func() { - err = i.installModelfile("suggest:7b", suggestModelfile) + err = i.installModelfile(i.suggest.Tag(), i.explain.Modelfile()) time.Sleep(1 * time.Second) if err != nil { fmt.Println("- Creating Modelfile for suggestions. " + shell.Err()) + fmt.Println("\n" + err.Error()) os.Exit(-1) } }).Run() fmt.Println("- Creating Modelfile for suggestions. " + shell.Ok()) - // 7. Install the modelfile (Suggest) + // 7. Install the modelfile (Explain) _ = spinner.New().Type(spinner.Line).Title(" Creating Modelfile for explanations").Action(func() { - err = i.installModelfile("explain:7b", explainModelfile) + err = i.installModelfile(i.explain.Tag(), i.explain.Modelfile()) time.Sleep(1 * time.Second) if err != nil { fmt.Println("- Creating Modelfile for explanations. " + shell.Err()) diff --git a/install/deploy_cli.go b/install/deploy_cli.go index ceb6a0e..ed58836 100644 --- a/install/deploy_cli.go +++ b/install/deploy_cli.go @@ -23,7 +23,7 @@ func (i *Install) deployAction(_ *cli.Context) error { } fmt.Println(fmt.Sprintf("Ollama version: %s\n", version)) - i.deployTlm(i.suggestModelfile, i.explainModelfile) + i.deployTlm() fmt.Println("\nDone..") return nil diff --git a/install/install.go b/install/install.go index f40d9fd..230a75d 100644 --- a/install/install.go +++ b/install/install.go @@ -2,22 +2,27 @@ package install import ( ollama "github.com/jmorganca/ollama/api" + "github.com/yusufcanb/tlm/explain" + "github.com/yusufcanb/tlm/suggest" ) +var repositoryOwner = "yusufcanb" +var repositoryName = "tlm" + type Install struct { api *ollama.Client - suggestModelfile string - explainModelfile string + suggest *suggest.Suggest + explain *explain.Explain ReleaseManager *ReleaseManager } -func New(api *ollama.Client, suggestModelfile string, explainModelfile string) *Install { +func New(api *ollama.Client, suggest *suggest.Suggest, explain *explain.Explain) *Install { return &Install{ - api: api, - suggestModelfile: suggestModelfile, - explainModelfile: explainModelfile, - ReleaseManager: NewReleaseManager("yusufcanb", "tlm"), + api: api, + suggest: suggest, + explain: explain, + ReleaseManager: NewReleaseManager(repositoryOwner, repositoryName), } } diff --git a/install/install_test.go b/install/install_test.go index 500e25e..0ab0906 100644 --- a/install/install_test.go +++ b/install/install_test.go @@ -3,7 +3,9 @@ package install_test import ( ollama "github.com/jmorganca/ollama/api" "github.com/yusufcanb/tlm/config" + "github.com/yusufcanb/tlm/explain" "github.com/yusufcanb/tlm/install" + "github.com/yusufcanb/tlm/suggest" "testing" ) @@ -18,7 +20,7 @@ func TestInstall(t *testing.T) { con.LoadOrCreateConfig() o, _ := ollama.ClientFromEnvironment() - install.New(o, "", "") + install.New(o, suggest.New(o, ""), explain.New(o, "")) } func TestReleaseManager_CanUpgrade(t *testing.T) { diff --git a/app/Modelfile.suggest b/suggest/Modelfile.suggest similarity index 100% rename from app/Modelfile.suggest rename to suggest/Modelfile.suggest diff --git a/suggest/api.go b/suggest/api.go index 191b6a1..887f1d9 100644 --- a/suggest/api.go +++ b/suggest/api.go @@ -110,7 +110,7 @@ func (s *Suggest) getCommandSuggestionFor(mode, term string, prompt string) (str stream := false req := &ollama.GenerateRequest{ - Model: "suggest:7b", + Model: s.tag, Prompt: builder.String(), Stream: &stream, Options: s.getParametersFor(mode), diff --git a/suggest/api_test.go b/suggest/api_test.go index c3b3e85..728fcb7 100644 --- a/suggest/api_test.go +++ b/suggest/api_test.go @@ -12,7 +12,7 @@ func TestRefineCommand(t *testing.T) { con.LoadOrCreateConfig() o, _ := ollama.ClientFromEnvironment() - s := New(o) + s := New(o, "") if s.refineCommand("ls -al") != "ls -al" { t.Error("no change should be made if the command is already okay") diff --git a/suggest/cli.go b/suggest/cli.go index 305ecbd..615c88a 100644 --- a/suggest/cli.go +++ b/suggest/cli.go @@ -30,7 +30,7 @@ func (s *Suggest) before(_ *cli.Context) error { found := false for _, model := range list.Models { - if model.Name == s.modelfileName { + if model.Name == s.tag { found = true break } @@ -102,7 +102,7 @@ func (s *Suggest) action(c *cli.Context) error { if form.action == Explain { fmt.Println(shell.SuccessMessage("┃ > ") + "Explaining..." + "\n") - exp := explain.New(s.api) + exp := explain.New(s.api, "") err = exp.StreamExplanationFor(Stable, form.command) if err != nil { return err diff --git a/suggest/suggest.go b/suggest/suggest.go index 98fa9cc..ec81bc6 100644 --- a/suggest/suggest.go +++ b/suggest/suggest.go @@ -1,14 +1,29 @@ package suggest import ( + _ "embed" + "fmt" ollama "github.com/jmorganca/ollama/api" ) +//go:embed Modelfile.suggest +var suggestModelfile string + type Suggest struct { - api *ollama.Client - modelfileName string + api *ollama.Client + tag string + modelfile string +} + +func (s *Suggest) Tag() string { + return s.tag +} + +func (s *Suggest) Modelfile() string { + return s.modelfile } -func New(api *ollama.Client) *Suggest { - return &Suggest{api: api, modelfileName: "suggest:7b"} +func New(api *ollama.Client, version string) *Suggest { + tag := fmt.Sprintf("tlm:%s-s", version) + return &Suggest{api: api, tag: tag, modelfile: suggestModelfile} } diff --git a/suggest/suggest_test.go b/suggest/suggest_test.go index f24bdce..0a795c3 100644 --- a/suggest/suggest_test.go +++ b/suggest/suggest_test.go @@ -12,5 +12,5 @@ func TestSuggest(t *testing.T) { con.LoadOrCreateConfig() o, _ := ollama.ClientFromEnvironment() - suggest.New(o) + suggest.New(o, "") }