mirror of
https://github.com/dogkeeper886/ollama37.git
synced 2025-12-10 07:46:59 +00:00
simplify api client
This commit is contained in:
16
cmd/cmd.go
16
cmd/cmd.go
@@ -36,10 +36,7 @@ func RunRun(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func pull(model string) error {
|
||||
client, err := NewAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client := api.NewClient()
|
||||
|
||||
var bar *progressbar.ProgressBar
|
||||
return client.Pull(
|
||||
@@ -68,10 +65,7 @@ func RunGenerate(_ *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func generate(model string, prompts ...string) error {
|
||||
client, err := NewAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client := api.NewClient()
|
||||
|
||||
for _, prompt := range prompts {
|
||||
client.Generate(context.Background(), &api.GenerateRequest{Model: model, Prompt: prompt}, func(resp api.GenerateResponse) error {
|
||||
@@ -121,12 +115,6 @@ func RunServer(_ *cobra.Command, _ []string) error {
|
||||
return server.Serve(ln)
|
||||
}
|
||||
|
||||
func NewAPIClient() (*api.Client, error) {
|
||||
return &api.Client{
|
||||
URL: "http://localhost:11434",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewCLI() *cobra.Command {
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user