fix unexpected end of response errors when cancelling in ollama run

This commit is contained in:
Jeffrey Morgan 2023-11-30 00:30:16 -05:00
parent 7eda3d0c55
commit 5687f1a0cf

View file

@ -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")