mirror of
https://github.com/rsteube/carapace-bin.git
synced 2025-05-05 15:32:53 +00:00
added ollama
This commit is contained in:
parent
791b846a53
commit
1bd9061929
24
completers/ollama_completer/cmd/cp.go
Normal file
24
completers/ollama_completer/cmd/cp.go
Normal file
@ -0,0 +1,24 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ollama"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var cpCmd = &cobra.Command{
|
||||
Use: "cp SOURCE TARGET",
|
||||
Short: "Copy a model",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(cpCmd).Standalone()
|
||||
|
||||
rootCmd.AddCommand(cpCmd)
|
||||
|
||||
carapace.Gen(cpCmd).PositionalCompletion(
|
||||
ollama.ActionModels().MultiParts(":"),
|
||||
ollama.ActionModels().MultiParts(":").FilterArgs(),
|
||||
)
|
||||
}
|
28
completers/ollama_completer/cmd/create.go
Normal file
28
completers/ollama_completer/cmd/create.go
Normal file
@ -0,0 +1,28 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ollama"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var createCmd = &cobra.Command{
|
||||
Use: "create MODEL",
|
||||
Short: "Create a model from a Modelfile",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(createCmd).Standalone()
|
||||
|
||||
createCmd.Flags().StringP("file", "f", "", "Name of the Modelfile (default \"Modelfile\")")
|
||||
rootCmd.AddCommand(createCmd)
|
||||
|
||||
carapace.Gen(createCmd).FlagCompletion(carapace.ActionMap{
|
||||
"file": carapace.ActionFiles(),
|
||||
})
|
||||
|
||||
carapace.Gen(createCmd).PositionalCompletion(
|
||||
ollama.ActionModels().MultiParts(":"),
|
||||
)
|
||||
}
|
22
completers/ollama_completer/cmd/help.go
Normal file
22
completers/ollama_completer/cmd/help.go
Normal file
@ -0,0 +1,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var helpCmd = &cobra.Command{
|
||||
Use: "help [command]",
|
||||
Short: "Help about any command",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(helpCmd).Standalone()
|
||||
|
||||
rootCmd.AddCommand(helpCmd)
|
||||
|
||||
carapace.Gen(helpCmd).PositionalAnyCompletion(
|
||||
carapace.ActionCommands(rootCmd),
|
||||
)
|
||||
}
|
19
completers/ollama_completer/cmd/list.go
Normal file
19
completers/ollama_completer/cmd/list.go
Normal file
@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List models",
|
||||
Aliases: []string{"ls"},
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(listCmd).Standalone()
|
||||
|
||||
rootCmd.AddCommand(listCmd)
|
||||
}
|
21
completers/ollama_completer/cmd/pull.go
Normal file
21
completers/ollama_completer/cmd/pull.go
Normal file
@ -0,0 +1,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var pullCmd = &cobra.Command{
|
||||
Use: "pull MODEL",
|
||||
Short: "Pull a model from a registry",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(pullCmd).Standalone()
|
||||
|
||||
pullCmd.Flags().Bool("insecure", false, "Use an insecure registry")
|
||||
rootCmd.AddCommand(pullCmd)
|
||||
|
||||
// TODO complete remote models
|
||||
}
|
24
completers/ollama_completer/cmd/push.go
Normal file
24
completers/ollama_completer/cmd/push.go
Normal file
@ -0,0 +1,24 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ollama"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var pushCmd = &cobra.Command{
|
||||
Use: "push MODEL",
|
||||
Short: "Push a model to a registry",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(pushCmd).Standalone()
|
||||
|
||||
pushCmd.Flags().Bool("insecure", false, "Use an insecure registry")
|
||||
rootCmd.AddCommand(pushCmd)
|
||||
|
||||
carapace.Gen(pushCmd).PositionalCompletion(
|
||||
ollama.ActionModels().MultiParts(":"),
|
||||
)
|
||||
}
|
23
completers/ollama_completer/cmd/rm.go
Normal file
23
completers/ollama_completer/cmd/rm.go
Normal file
@ -0,0 +1,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ollama"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rmCmd = &cobra.Command{
|
||||
Use: "rm MODEL [MODEL...]",
|
||||
Short: "Remove a model",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(rmCmd).Standalone()
|
||||
|
||||
rootCmd.AddCommand(rmCmd)
|
||||
|
||||
carapace.Gen(rmCmd).PositionalAnyCompletion(
|
||||
ollama.ActionModels().MultiParts(":").FilterArgs(),
|
||||
)
|
||||
}
|
23
completers/ollama_completer/cmd/root.go
Normal file
23
completers/ollama_completer/cmd/root.go
Normal file
@ -0,0 +1,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "ollama",
|
||||
Short: "Large language model runner",
|
||||
Long: "https://ollama.com/",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(rootCmd).Standalone()
|
||||
|
||||
rootCmd.Flags().BoolP("version", "v", false, "Show version information")
|
||||
}
|
31
completers/ollama_completer/cmd/run.go
Normal file
31
completers/ollama_completer/cmd/run.go
Normal file
@ -0,0 +1,31 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ollama"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var runCmd = &cobra.Command{
|
||||
Use: "run MODEL [PROMPT]",
|
||||
Short: "Run a model",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(runCmd).Standalone()
|
||||
|
||||
runCmd.Flags().String("format", "", "Response format (e.g. json)")
|
||||
runCmd.Flags().Bool("insecure", false, "Use an insecure registry")
|
||||
runCmd.Flags().Bool("nowordwrap", false, "Don't wrap words to the next line automatically")
|
||||
runCmd.Flags().Bool("verbose", false, "Show timings for response")
|
||||
rootCmd.AddCommand(runCmd)
|
||||
|
||||
carapace.Gen(runCmd).FlagCompletion(carapace.ActionMap{
|
||||
"format": carapace.ActionValues("json"),
|
||||
})
|
||||
|
||||
carapace.Gen(runCmd).PositionalCompletion(
|
||||
ollama.ActionModels(),
|
||||
)
|
||||
}
|
19
completers/ollama_completer/cmd/serve.go
Normal file
19
completers/ollama_completer/cmd/serve.go
Normal file
@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var serveCmd = &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Start ollama",
|
||||
Aliases: []string{"start"},
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(serveCmd).Standalone()
|
||||
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
}
|
28
completers/ollama_completer/cmd/show.go
Normal file
28
completers/ollama_completer/cmd/show.go
Normal file
@ -0,0 +1,28 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/carapace-sh/carapace"
|
||||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/ollama"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var showCmd = &cobra.Command{
|
||||
Use: "show MODEL",
|
||||
Short: "Show information for a model",
|
||||
Run: func(cmd *cobra.Command, args []string) {},
|
||||
}
|
||||
|
||||
func init() {
|
||||
carapace.Gen(showCmd).Standalone()
|
||||
|
||||
showCmd.Flags().Bool("license", false, "Show license of a model")
|
||||
showCmd.Flags().Bool("modelfile", false, "Show Modelfile of a model")
|
||||
showCmd.Flags().Bool("parameters", false, "Show parameters of a model")
|
||||
showCmd.Flags().Bool("system", false, "Show system message of a model")
|
||||
showCmd.Flags().Bool("template", false, "Show template of a model")
|
||||
rootCmd.AddCommand(showCmd)
|
||||
|
||||
carapace.Gen(showCmd).PositionalCompletion(
|
||||
ollama.ActionModels(),
|
||||
)
|
||||
}
|
7
completers/ollama_completer/main.go
Normal file
7
completers/ollama_completer/main.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "github.com/carapace-sh/carapace-bin/completers/ollama_completer/cmd"
|
||||
|
||||
func main() {
|
||||
cmd.Execute()
|
||||
}
|
22
pkg/actions/tools/ollama/model.go
Normal file
22
pkg/actions/tools/ollama/model.go
Normal file
@ -0,0 +1,22 @@
|
||||
package ollama
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/carapace-sh/carapace"
|
||||
)
|
||||
|
||||
// ActionModels completes models
|
||||
func ActionModels() carapace.Action {
|
||||
return carapace.ActionExecCommand("ollama", "list")(func(output []byte) carapace.Action {
|
||||
lines := strings.Split(string(output), "\n")
|
||||
vals := make([]string, 0)
|
||||
for _, line := range lines[1:] {
|
||||
if splitted := strings.Split(line, "\t"); len(splitted) >= 4 {
|
||||
vals = append(vals, splitted[0], fmt.Sprintf("%v - %v", splitted[2], splitted[3]))
|
||||
}
|
||||
}
|
||||
return carapace.ActionValuesDescribed(vals...)
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user