refactor: remove unused return value

This commit is contained in:
Yiyang Kang 2023-03-20 21:19:53 +08:00
parent 7e9d4e5052
commit 9e7432a1a1
1 changed files with 8 additions and 7 deletions

View File

@ -87,7 +87,7 @@ func matchAssistantConversation(botUsr *tele.User, msg *tele.Message) []*tele.Me
return nil
}
type assistantStreamedResponseCb func(text string, finished bool) (*tele.Message, error)
type assistantStreamedResponseCb func(text string, finished bool) error
func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedResponseCb) error {
logger.Debugw("Openai chat request", "req", request)
@ -111,7 +111,7 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
nErrs := 0
go func() {
respBuilder := strings.Builder{}
minWait := time.After(1 * time.Second)
minWait := time.After(time.Second)
for {
var (
nNewChunk int
@ -149,9 +149,9 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
}
respoText := respBuilder.String() + assistantWritingSign
minWait = time.After(691 * time.Millisecond) // renew the timer
minWait = time.After(time.Second) // renew the timer
if _, err := cb(respoText, false); err != nil {
if err := cb(respoText, false); err != nil {
logger.Warnw("failed to send partial update", "error", err)
nErrs += 1
if nErrs > 3 {
@ -165,7 +165,7 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
}
respText := respBuilder.String()
if _, err = cb(respText, true); err != nil {
if err = cb(respText, true); err != nil {
logger.Warnw("assistant: failed to send message", "error", err)
}
}()
@ -213,6 +213,7 @@ func handleAssistantConversation(c tele.Context, thread []*tele.Message) error {
})
}
if len(convMsgs) == 0 {
// It turns out that this will never happen because Telegram splits messages when they exceed a certain length.
return c.Reply("Your message is too long (Sorry!)")
}
for l := len(convMsgs) - 1; l >= 0; l-- {
@ -233,7 +234,7 @@ func handleAssistantConversation(c tele.Context, thread []*tele.Message) error {
}()
var replyMsg *tele.Message
reqErr := assistantStreamedResponse(req, func(text string, finished bool) (*tele.Message, error) {
reqErr := assistantStreamedResponse(req, func(text string, finished bool) error {
var err error
if replyMsg == nil {
<-typingNotifyCh
@ -247,7 +248,7 @@ func handleAssistantConversation(c tele.Context, thread []*tele.Message) error {
logger.Warnw("failed to cache message", "error", err)
}
}
return replyMsg, err
return err
})
if reqErr != nil {