refactor: remove unused return value
This commit is contained in:
parent
7e9d4e5052
commit
9e7432a1a1
15
assistant.go
15
assistant.go
|
@ -87,7 +87,7 @@ func matchAssistantConversation(botUsr *tele.User, msg *tele.Message) []*tele.Me
|
||||||
return nil
|
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 {
|
func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedResponseCb) error {
|
||||||
logger.Debugw("Openai chat request", "req", request)
|
logger.Debugw("Openai chat request", "req", request)
|
||||||
|
@ -111,7 +111,7 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
|
||||||
nErrs := 0
|
nErrs := 0
|
||||||
go func() {
|
go func() {
|
||||||
respBuilder := strings.Builder{}
|
respBuilder := strings.Builder{}
|
||||||
minWait := time.After(1 * time.Second)
|
minWait := time.After(time.Second)
|
||||||
for {
|
for {
|
||||||
var (
|
var (
|
||||||
nNewChunk int
|
nNewChunk int
|
||||||
|
@ -149,9 +149,9 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
|
||||||
}
|
}
|
||||||
|
|
||||||
respoText := respBuilder.String() + assistantWritingSign
|
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)
|
logger.Warnw("failed to send partial update", "error", err)
|
||||||
nErrs += 1
|
nErrs += 1
|
||||||
if nErrs > 3 {
|
if nErrs > 3 {
|
||||||
|
@ -165,7 +165,7 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
|
||||||
}
|
}
|
||||||
|
|
||||||
respText := respBuilder.String()
|
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)
|
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 {
|
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!)")
|
return c.Reply("Your message is too long (Sorry!)")
|
||||||
}
|
}
|
||||||
for l := len(convMsgs) - 1; l >= 0; l-- {
|
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
|
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
|
var err error
|
||||||
if replyMsg == nil {
|
if replyMsg == nil {
|
||||||
<-typingNotifyCh
|
<-typingNotifyCh
|
||||||
|
@ -247,7 +248,7 @@ func handleAssistantConversation(c tele.Context, thread []*tele.Message) error {
|
||||||
logger.Warnw("failed to cache message", "error", err)
|
logger.Warnw("failed to cache message", "error", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return replyMsg, err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
if reqErr != nil {
|
if reqErr != nil {
|
||||||
|
|
Loading…
Reference in New Issue