Skip to content

Commit

Permalink
❇️ initial commit for release/1.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufcanb committed Feb 23, 2024
1 parent 3f1500f commit 3521e23
Show file tree
Hide file tree
Showing 37 changed files with 662 additions and 996 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Move it to your `$PATH`;
sudo mv tlm /usr/local/bin
```

⚠️ If you already have CodeLLaMa on your system, you can just use the following command to configure it;
> [!TIP]
> If you already have CodeLLaMa on your system, you can just use the following command to configure it;
```
tlm config set llm.host <codellama_host>
```
Expand All @@ -59,7 +61,9 @@ Download latest release;
Invoke-WebRequest -Uri "https://github.com/yusufcanb/tlm/releases/download/1.0-alpha.0/tlama_1.0-alpha.0_windows_amd64.exe" -OutFile "tlm.exe"
```

⚠️ If you already have CodeLLaMa on your system, you can just use the following command to configure it;
> [!TIP]
> If you already have CodeLLaMa on your system, you can just use the following command to configure it;
```
.\tlm.exe config set llm.host <codellama_host>
```
Expand Down
8 changes: 8 additions & 0 deletions cmd/Modelfile.explain
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. User will ask you some thing that can be convertible to a UNIX or Windows command. You won't provide information or explanations and your output will be just an executable shell command inside three backticks.
8 changes: 8 additions & 0 deletions cmd/Modelfile.suggest
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. User will ask you some thing that can be convertible to a UNIX or Windows command. You won't provide information or explanations and your output will be just an executable shell command inside three backticks.
1 change: 1 addition & 0 deletions cmd/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0-rc1
14 changes: 11 additions & 3 deletions cmd/cli.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package main

import (
_ "embed"
"log"
"os"

"github.com/yusufcanb/tlama/pkg/app"
)

var version = "1.0"
//go:embed VERSION
var version string

//go:embed Modelfile.explain
var explainModelfile string

//go:embed Modelfile.suggest
var suggestModelfile string

func main() {
tlama := app.New(version)
if err := tlama.App.Run(os.Args); err != nil {
tlm := app.New(version, explainModelfile, suggestModelfile)
if err := tlm.App.Run(os.Args); err != nil {
log.Fatal(err)
}
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ module github.com/yusufcanb/tlama
go 1.21

require (
github.com/briandowns/spinner v1.23.0
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/huh v0.3.0
github.com/charmbracelet/huh/spinner v0.0.0-20240209193029-45947515c4cf
github.com/jmorganca/ollama v0.1.25
github.com/spf13/viper v1.18.2
github.com/urfave/cli/v2 v2.27.1
Expand All @@ -13,7 +16,7 @@ require (
require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/containerd/console v1.0.4 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4Pt2A=
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/huh v0.3.0 h1:CxPplWkgW2yUTDDG0Z4S5HH8SJOosWHd4LxCvi0XsKE=
github.com/charmbracelet/huh v0.3.0/go.mod h1:fujUdKX8tC45CCSaRQdw789O6uaCRwx8l2NDyKfC4jA=
github.com/charmbracelet/huh/spinner v0.0.0-20240209193029-45947515c4cf h1:hzfl5rHblaVR/8zfAoCBuqsTcEp/Zvy1IVZBIebZelM=
github.com/charmbracelet/huh/spinner v0.0.0-20240209193029-45947515c4cf/go.mod h1:2l0nupcBRhdSZQqIiaV2hKwctrYbBbOr9Dn6Smox3f4=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro=
Expand Down
108 changes: 0 additions & 108 deletions pkg/api/api.go

This file was deleted.

7 changes: 0 additions & 7 deletions pkg/api/model.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/api/prompt.go

This file was deleted.

43 changes: 22 additions & 21 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package app

import (
"github.com/yusufcanb/tlama/pkg/api"
_ "embed"
ollama "github.com/jmorganca/ollama/api"
"github.com/yusufcanb/tlama/pkg/config"
"github.com/yusufcanb/tlama/pkg/explain"
"github.com/yusufcanb/tlama/pkg/install"
Expand All @@ -10,30 +11,36 @@ import (
"github.com/urfave/cli/v2"
)

type TlamaApp struct {
App *cli.App
Config *config.TlamaConfig
type TlmApp struct {
App *cli.App
}

func New(version string) *TlamaApp {
func New(version string, suggestModelfile string, explainModelfile string) *TlmApp {
con := config.New()
con.LoadOrCreateConfig()

o, _ := ollama.ClientFromEnvironment()
sug := suggest.New(o, suggestModelfile)
exp := explain.New(o, explainModelfile)
ins := install.New(o)

cliApp := &cli.App{
Name: "tlm",
Usage: "terminal intelligence with local language model.",
Description: "tlm is a command line tool to provide terminal intelligence using CodeLLaMa.",
Version: version,
Name: "tlm",
Usage: "local terminal companion powered by CodeLLaMa.",
Version: version,
HideHelpCommand: true,
Action: func(c *cli.Context) error {
return cli.ShowAppHelp(c)
},
Commands: []*cli.Command{
suggest.GetCommand(),
explain.GetCommand(),
install.GetCommand(),
config.GetCommand(),
sug.Command(),
exp.Command(),
ins.Command(),
con.Command(),
&cli.Command{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version.",
Usage: "print version.",
Action: func(c *cli.Context) error {
cli.ShowVersion(c)
return nil
Expand All @@ -42,13 +49,7 @@ func New(version string) *TlamaApp {
},
}

cliApp.HideHelpCommand = true
cliApp.Metadata = make(map[string]interface{})

cliApp.Metadata["config"] = config.New()
cliApp.Metadata["api"] = api.New(cliApp.Metadata["config"].(*config.TlamaConfig))

return &TlamaApp{
return &TlmApp{
App: cliApp,
}
}
58 changes: 58 additions & 0 deletions pkg/config/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package config

import (
"fmt"
"github.com/spf13/viper"
"github.com/yusufcanb/tlama/pkg/shell"
"log"
"os"
"path"
)

var defaultLLMHost = "http://localhost:11434"

func isExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}

func (c *Config) LoadOrCreateConfig() {
viper.SetConfigName(".tlm")
viper.SetConfigType("yaml")
viper.AddConfigPath("$HOME")

homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
}

configPath := path.Join(homeDir, ".tlm.yaml")
if !isExists(configPath) {
viper.Set("shell", shell.GetShell())

viper.Set("llm.host", defaultLLMHost)
viper.Set("llm.suggestion", "balanced")
viper.Set("llm.explain", "balanced")

err := os.Setenv("OLLAMA_HOST", defaultLLMHost)
if err != nil {
fmt.Printf(shell.Err()+" error writing config file, %s", err)
}

if err := viper.WriteConfigAs(path.Join(homeDir, ".tlm.yaml")); err != nil {
fmt.Printf(shell.Err()+" error writing config file, %s", err)
}
}

err = viper.ReadInConfig()
if err != nil {
log.Fatalf("Error reading config file, %s", err)
}

err = os.Setenv("OLLAMA_HOST", viper.GetString("llm.host"))
if err != nil {
fmt.Printf(shell.Err()+" %s", err)
}
}
Loading

0 comments on commit 3521e23

Please sign in to comment.