Compare commits
No commits in common. "5e65a2ce32a6883d1d966d5feb543c9e7fcf6d9b" and "89286b7e734223275c15b020bed389e42ffc8200" have entirely different histories.
5e65a2ce32
...
89286b7e73
16
assistant.go
16
assistant.go
|
@ -108,13 +108,11 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
|
||||||
logger.Warnw("assistant: failed to get response", "error", err)
|
logger.Warnw("assistant: failed to get response", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var nErrs, nUpdates int
|
nErrs := 0
|
||||||
go func() {
|
go func() {
|
||||||
respBuilder := strings.Builder{}
|
respBuilder := strings.Builder{}
|
||||||
minWait := time.After(time.Second)
|
minWait := time.After(time.Second)
|
||||||
for {
|
for {
|
||||||
nUpdates += 1
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nNewChunk int
|
nNewChunk int
|
||||||
finished bool
|
finished bool
|
||||||
|
@ -150,17 +148,13 @@ func assistantStreamedResponse(request openai.ChatRequest, cb assistantStreamedR
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renew the timer.
|
respoText := respBuilder.String() + assistantWritingSign
|
||||||
// The Telegram API rate limit for group messages is 20 per minute. So we cannot update messages too frequently.
|
minWait = time.After(time.Second) // renew the timer
|
||||||
minWaitDurSecs := lo.Min([]int{nUpdates, 4}) + nErrs*3
|
|
||||||
minWait = time.After(time.Duration(minWaitDurSecs) * time.Second)
|
|
||||||
|
|
||||||
// send the partial message
|
if err := cb(respoText, false); err != nil {
|
||||||
respText := respBuilder.String() + assistantWritingSign
|
|
||||||
if err := cb(respText, 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 > 5 {
|
if nErrs > 3 {
|
||||||
logger.Warnw("too many errors, aborting")
|
logger.Warnw("too many errors, aborting")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
func Assistant() string {
|
func Assistant() string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
"Misaka is a playful, energetic individual. She is annoyingly talkative.",
|
"Misaka is a playful, energetic individual. She is annoyingly talkative.",
|
||||||
"Misaka must answer questions as truthfully as possible. If the user's intention is unclear, Misaka may ask for more context.",
|
"Misaka must answer questions as truthfully as possible. In case Misaka does not know the answer, she must begin her reply with \"Sorry, I don't know\" (in the same language as the user is speaking).",
|
||||||
"Misaka must use a lot of different emojis in chat 😝🥹.",
|
"Misaka must use a lot of different emojis in chat 😝🥹.",
|
||||||
"Most importantly, Misaka is a helpful assistant.",
|
"Most importantly, Misaka is a helpful assistant.",
|
||||||
"",
|
"",
|
||||||
|
|
Loading…
Reference in New Issue