feat(assistant): add retry when requesting completion
This commit is contained in:
parent
08985f6936
commit
7e9d4e5052
17
assistant.go
17
assistant.go
|
@ -93,10 +93,20 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
|
|||
logger.Debugw("Openai chat request", "req", request)
|
||||
ai := openai.NewClient(config.OpenAIApiKey)
|
||||
|
||||
resp, err := ai.ChatCompletionStream(request)
|
||||
if err != nil {
|
||||
var (
|
||||
resp *openai.ChatResponseStream
|
||||
err error
|
||||
)
|
||||
tries := 2
|
||||
for {
|
||||
if tries--; tries < 0 {
|
||||
return err
|
||||
}
|
||||
if resp, err = ai.ChatCompletionStream(request); err == nil {
|
||||
break
|
||||
}
|
||||
logger.Warnw("assistant: failed to get response", "error", err)
|
||||
}
|
||||
|
||||
nErrs := 0
|
||||
go func() {
|
||||
|
@ -242,8 +252,9 @@ func handleAssistantConversation(c tele.Context, thread []*tele.Message) error {
|
|||
|
||||
if reqErr != nil {
|
||||
logger.Errorw("assistant: failed to complete conversation", "error", reqErr)
|
||||
return c.Reply("Sorry, there's a technical issue. 😵💫 Please try again later.", tele.Silent)
|
||||
}
|
||||
return reqErr
|
||||
return nil
|
||||
}
|
||||
|
||||
func assistantRemoveMention(msg, name string) string {
|
||||
|
|
Loading…
Reference in New Issue