|
@@ -15,13 +15,11 @@ import (
|
|
|
"net"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
- "os/signal"
|
|
|
"path/filepath"
|
|
|
"runtime"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync/atomic"
|
|
|
- "syscall"
|
|
|
"time"
|
|
|
|
|
|
"github.com/containerd/console"
|
|
@@ -330,6 +328,7 @@ func RunHandler(cmd *cobra.Command, args []string) error {
|
|
|
if err := PullHandler(cmd, []string{name}); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
+
|
|
|
return client.Show(cmd.Context(), &api.ShowRequest{Name: name})
|
|
|
}
|
|
|
return info, err
|
|
@@ -858,17 +857,6 @@ func chat(cmd *cobra.Command, opts runOptions) (*api.Message, error) {
|
|
|
spinner := progress.NewSpinner("")
|
|
|
p.Add("", spinner)
|
|
|
|
|
|
- cancelCtx, cancel := context.WithCancel(cmd.Context())
|
|
|
- defer cancel()
|
|
|
-
|
|
|
- sigChan := make(chan os.Signal, 1)
|
|
|
- signal.Notify(sigChan, syscall.SIGINT)
|
|
|
-
|
|
|
- go func() {
|
|
|
- <-sigChan
|
|
|
- cancel()
|
|
|
- }()
|
|
|
-
|
|
|
var state *displayResponseState = &displayResponseState{}
|
|
|
var latest api.ChatResponse
|
|
|
var fullResponse strings.Builder
|
|
@@ -903,10 +891,7 @@ func chat(cmd *cobra.Command, opts runOptions) (*api.Message, error) {
|
|
|
req.KeepAlive = opts.KeepAlive
|
|
|
}
|
|
|
|
|
|
- if err := client.Chat(cancelCtx, req, fn); err != nil {
|
|
|
- if errors.Is(err, context.Canceled) {
|
|
|
- return nil, nil
|
|
|
- }
|
|
|
+ if err := client.Chat(cmd.Context(), req, fn); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
@@ -946,17 +931,6 @@ func generate(cmd *cobra.Command, opts runOptions) error {
|
|
|
generateContext = []int{}
|
|
|
}
|
|
|
|
|
|
- ctx, cancel := context.WithCancel(cmd.Context())
|
|
|
- defer cancel()
|
|
|
-
|
|
|
- sigChan := make(chan os.Signal, 1)
|
|
|
- signal.Notify(sigChan, syscall.SIGINT)
|
|
|
-
|
|
|
- go func() {
|
|
|
- <-sigChan
|
|
|
- cancel()
|
|
|
- }()
|
|
|
-
|
|
|
var state *displayResponseState = &displayResponseState{}
|
|
|
|
|
|
fn := func(response api.GenerateResponse) error {
|
|
@@ -992,10 +966,7 @@ func generate(cmd *cobra.Command, opts runOptions) error {
|
|
|
KeepAlive: opts.KeepAlive,
|
|
|
}
|
|
|
|
|
|
- if err := client.Generate(ctx, &request, fn); err != nil {
|
|
|
- if errors.Is(err, context.Canceled) {
|
|
|
- return nil
|
|
|
- }
|
|
|
+ if err := client.Generate(cmd.Context(), &request, fn); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
|
|
@@ -1017,8 +988,7 @@ func generate(cmd *cobra.Command, opts runOptions) error {
|
|
|
latest.Summary()
|
|
|
}
|
|
|
|
|
|
- ctx = context.WithValue(cmd.Context(), generateContextKey("context"), latest.Context)
|
|
|
- cmd.SetContext(ctx)
|
|
|
+ cmd.SetContext(context.WithValue(cmd.Context(), generateContextKey("context"), latest.Context))
|
|
|
|
|
|
return nil
|
|
|
}
|