Commit 5687f1a0 authored by Jeffrey Morgan's avatar Jeffrey Morgan
Browse files

fix `unexpected end of response` errors when cancelling in `ollama run`

parent 7eda3d0c
...@@ -496,12 +496,10 @@ func generate(cmd *cobra.Command, opts generateOptions) error { ...@@ -496,12 +496,10 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
sigChan := make(chan os.Signal, 1) sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT) signal.Notify(sigChan, syscall.SIGINT)
var abort bool
go func() { go func() {
<-sigChan <-sigChan
cancel() cancel()
abort = true
}() }()
var currentLineLength int var currentLineLength int
...@@ -548,7 +546,7 @@ func generate(cmd *cobra.Command, opts generateOptions) error { ...@@ -548,7 +546,7 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
} }
if err := client.Generate(cancelCtx, &request, fn); err != nil { 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 nil
} }
return err return err
...@@ -559,10 +557,7 @@ func generate(cmd *cobra.Command, opts generateOptions) error { ...@@ -559,10 +557,7 @@ func generate(cmd *cobra.Command, opts generateOptions) error {
} }
if !latest.Done { if !latest.Done {
if abort { return nil
return nil
}
return errors.New("unexpected end of response")
} }
verbose, err := cmd.Flags().GetBool("verbose") verbose, err := cmd.Flags().GetBool("verbose")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment