Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Modelfile naming convention changed #23

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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 <command>\ntlm suggest <prompt>",
UsageText: "tlm explain '<command>'\ntlm suggest '<prompt>'",
Version: version,
CommandNotFound: notFound,
Before: beforeRun(),
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion explain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion explain/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 20 additions & 5 deletions explain/explain.go
Original file line number Diff line number Diff line change
@@ -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}
}
2 changes: 1 addition & 1 deletion explain/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ func TestExplain(t *testing.T) {
con.LoadOrCreateConfig()

o, _ := ollama.ClientFromEnvironment()
explain.New(o)
explain.New(o, "")
}
9 changes: 5 additions & 4 deletions install/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion install/deploy_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
4 changes: 3 additions & 1 deletion install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion suggest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion suggest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions suggest/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions suggest/suggest.go
Original file line number Diff line number Diff line change
@@ -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}
}
2 changes: 1 addition & 1 deletion suggest/suggest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ func TestSuggest(t *testing.T) {
con.LoadOrCreateConfig()

o, _ := ollama.ClientFromEnvironment()
suggest.New(o)
suggest.New(o, "")
}
Loading