Skip to content

Commit

Permalink
✨ fix module added with initial trials #20
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufcanb committed Apr 6, 2024
1 parent 910c371 commit 168a398
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
ollama "github.com/jmorganca/ollama/api"
"github.com/yusufcanb/tlm/config"
"github.com/yusufcanb/tlm/explain"
"github.com/yusufcanb/tlm/fix"
"github.com/yusufcanb/tlm/install"
"github.com/yusufcanb/tlm/suggest"
"io/fs"
Expand All @@ -27,7 +28,8 @@ func New(version, buildSha string) *TlmApp {
o, _ := ollama.ClientFromEnvironment()
sug := suggest.New(o, version)
exp := explain.New(o, version)
ins := install.New(o, sug, exp)
fi := fix.New(o, version)
ins := install.New(o, sug, exp, fi)

cliApp := &cli.App{
Name: "tlm",
Expand All @@ -43,6 +45,7 @@ func New(version, buildSha string) *TlmApp {
Commands: []*cli.Command{
sug.Command(),
exp.Command(),
fi.Command(),
ins.DeployCommand(),
con.Command(),
{
Expand Down
8 changes: 8 additions & 0 deletions fix/Modelfile.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM codellama:7b

PARAMETER temperature 0.1
PARAMETER top_p 0.5
PARAMETER top_k 40
PARAMETER seed 1

SYSTEM You are software program specifically for Command Line Interface usage. Users will provide you a console output of an executed command and you will try to fix the errored command. You are designed to be helpful and informative. You are not a chatbot, so you will not engage in conversation. You will only respond to given executed command output.
30 changes: 30 additions & 0 deletions fix/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fix

import (
"bufio"
"fmt"
"os"
"strings"
)

func (f *Fix) fixPrompt() error {
fmt.Println(os.Args)
// Create a scanner to read from standard input
scanner := bufio.NewScanner(os.Stdin)

// Use a StringBuilder to concatenate all input lines
var builder strings.Builder

for scanner.Scan() {
builder.WriteString(scanner.Text())
builder.WriteString("\n")
}

// Get the complete input as a string
pipedInput := builder.String()
fmt.Println(pipedInput)

fmt.Println("fix -> action")

return nil
}
25 changes: 25 additions & 0 deletions fix/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fix

import (
"fmt"
"github.com/urfave/cli/v2"
)

func (f *Fix) action(_ *cli.Context) error {
return f.fixPrompt()
}

func (f *Fix) before(_ *cli.Context) error {
fmt.Println("fix -> before")
return nil
}

func (f *Fix) Command() *cli.Command {
return &cli.Command{
Name: "fix",
Usage: "Fixes a failed command",
Aliases: []string{"f"},
Action: f.action,
Before: f.before,
}
}
30 changes: 30 additions & 0 deletions fix/fix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fix

import (
_ "embed"
"fmt"
ollama "github.com/jmorganca/ollama/api"
)

//go:embed Modelfile.fix
var fixModelfile string

type Fix struct {
api *ollama.Client

tag string
modelfile string
}

func (f *Fix) Tag() string {
return f.tag
}

func (f *Fix) Modelfile() string {
return f.modelfile
}

func New(api *ollama.Client, version string) *Fix {
tag := fmt.Sprintf("tlm:%s-f", version)
return &Fix{api: api, tag: tag, modelfile: fixModelfile}
}
11 changes: 11 additions & 0 deletions install/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ func (i *Install) deployTlm() {
}
}).Run()
fmt.Println("- Creating Modelfile for explanations. " + shell.Ok())

// 8. Install the modelfile (Explain)
_ = spinner.New().Type(spinner.Line).Title(" Creating Modelfile for fixes").Action(func() {
err = i.installModelfile(i.fix.Tag(), i.fix.Modelfile())
time.Sleep(1 * time.Second)
if err != nil {
fmt.Println("- Creating Modelfile for fixes. " + shell.Err())
os.Exit(-1)
}
}).Run()
fmt.Println("- Creating Modelfile for fixes. " + shell.Ok())
}
5 changes: 4 additions & 1 deletion install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package install
import (
ollama "github.com/jmorganca/ollama/api"
"github.com/yusufcanb/tlm/explain"
"github.com/yusufcanb/tlm/fix"
"github.com/yusufcanb/tlm/suggest"
)

Expand All @@ -14,15 +15,17 @@ type Install struct {

suggest *suggest.Suggest
explain *explain.Explain
fix *fix.Fix

ReleaseManager *ReleaseManager
}

func New(api *ollama.Client, suggest *suggest.Suggest, explain *explain.Explain) *Install {
func New(api *ollama.Client, suggest *suggest.Suggest, explain *explain.Explain, fix *fix.Fix) *Install {
return &Install{
api: api,
suggest: suggest,
explain: explain,
fix: fix,
ReleaseManager: NewReleaseManager(repositoryOwner, repositoryName),
}
}

0 comments on commit 168a398

Please sign in to comment.