From 5687f1a0cfa3d2408bfcb04f4342f657f6dada58 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Thu, 30 Nov 2023 00:30:16 -0500 Subject: [PATCH] fix `unexpected end of response` errors when cancelling in `ollama run` --- cmd/cmd.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 0d5ffb69..2912a51f 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -496,12 +496,10 @@ func generate(cmd *cobra.Command, opts generateOptions) error { sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, syscall.SIGINT) - var abort bool go func() { <-sigChan cancel() - abort = true }() var currentLineLength int @@ -548,7 +546,7 @@ func generate(cmd *cobra.Command, opts generateOptions) error { } if err := client.Generate(cancelCtx, &request, fn); err != nil { - if strings.Contains(err.Error(), "context canceled") && abort { + if errors.Is(err, context.Canceled) { return nil } return err @@ -559,10 +557,7 @@ func generate(cmd *cobra.Command, opts generateOptions) error { } if !latest.Done { - if abort { - return nil - } - return errors.New("unexpected end of response") + return nil } verbose, err := cmd.Flags().GetBool("verbose")