fix unexpected end of response
errors when cancelling in ollama run
This commit is contained in:
parent
7eda3d0c55
commit
5687f1a0cf
1 changed files with 2 additions and 7 deletions
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue