-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(":"), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(":"), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/carapace-sh/carapace-bin/completers/ollama_completer/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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...) | ||
}) | ||
} |