Merge pull request #936 from trheyi/main
feat: Improve error handling and result processing in Assistant API
This commit is contained in:
commit
6b84dc7128
2 changed files with 28 additions and 10 deletions
|
|
@ -687,9 +687,18 @@ func (ast *Assistant) streamChat(
|
|||
return nil, retry
|
||||
}
|
||||
|
||||
var prompt string = ""
|
||||
// Default prompt
|
||||
var prompt string = fmt.Sprintf("Try to fix the error following the error message. error:\n %s", exception.Trim(retry))
|
||||
switch v := promptAny.(type) {
|
||||
case NextAction:
|
||||
case bool: // Ignore the error, and return the specific result
|
||||
if v == false {
|
||||
return nil, retry
|
||||
}
|
||||
|
||||
case map[string]interface{}: // Ignore the error, and return the specific result
|
||||
return v, nil
|
||||
|
||||
case NextAction: // Execute the next action
|
||||
result, err := v.Execute(c, ctx, contents, cb)
|
||||
if err != nil {
|
||||
// chatMessage.New().Error(err.Error()).Done().Callback(cb).Write(c.Writer)
|
||||
|
|
@ -697,7 +706,7 @@ func (ast *Assistant) streamChat(
|
|||
}
|
||||
return result, nil
|
||||
|
||||
case string:
|
||||
case string: // Add the prompt to the messages
|
||||
prompt = v
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -164,16 +164,25 @@ func (ast *Assistant) HookRetry(c *gin.Context, context chatctx.Context, input [
|
|||
}
|
||||
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
case string, bool:
|
||||
return v, nil
|
||||
|
||||
case map[string]interface{}:
|
||||
var next NextAction
|
||||
raw, _ := jsoniter.MarshalToString(v)
|
||||
err := jsoniter.UnmarshalFromString(raw, &next)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
// Has Action
|
||||
if _, has := v["action"]; has {
|
||||
var next NextAction
|
||||
raw, _ := jsoniter.MarshalToString(v)
|
||||
err := jsoniter.UnmarshalFromString(raw, &next)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &next, nil
|
||||
}
|
||||
return &next, nil
|
||||
|
||||
// Ignore the error, and return the specific result
|
||||
return v, nil
|
||||
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue