Skip to content

Commit

Permalink
refactor(core): enhance thinking message handling with sleep function…
Browse files Browse the repository at this point in the history
…ality

- Added a sleep function to introduce a delay before sending thinking messages, improving user experience by preventing immediate responses.
- Adjusted the timeout handling logic to ensure proper management of thinking message timeouts, enhancing the overall flow of message processing.
- These changes aim to refine the interaction timing within the chat service, making it more responsive and user-friendly.
  • Loading branch information
dingyi222666 committed Dec 13, 2024
1 parent 8c04ff8 commit 7f56787
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/middlewares/thinking_message_send.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Logger } from 'koishi'
import { Context, Logger, sleep } from 'koishi'
import { Config } from '../config'
import {
ChainMiddlewareContextOptions,
Expand Down Expand Up @@ -26,6 +26,9 @@ export function apply(ctx: Context, config: Config, chain: ChatChain) {
context.options
)

// sleep to wait think
await sleep(config.sendThinkingMessageTimeout)

if (thinkingTimeoutObject.timeout == null || queueCount < 1) {
return
}
Expand Down Expand Up @@ -56,7 +59,7 @@ export function apply(ctx: Context, config: Config, chain: ChatChain) {
},
1000 * 60 * 2 - 1000 * 3
)
}, config.sendThinkingMessageTimeout)
}, 0)

return ChainMiddlewareRunStatus.CONTINUE
})
Expand Down

0 comments on commit 7f56787

Please sign in to comment.