Skip to content

Commit

Permalink
fix word cut in streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
fegloff committed Mar 27, 2024
1 parent 4588b41 commit cbe63e8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/modules/llms/api/athropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ export const anthropicStreamCompletion = async (
if (msg) {
if (msg.startsWith('Input Token')) {
inputTokens = msg.split('Input Token: ')[1]
} else if (msg.startsWith('Text')) {
} else if (msg.startsWith('Output Tokens')) {
outputTokens = msg.split('Output Tokens: ')[1]
} else {
wordCount++
completion += msg.split('Text: ')[1]
completion += msg // .split('Text: ')[1]
if (msg.includes('Output Tokens:')) {
const tokenMsg = msg.split('Output Tokens: ')[1]
outputTokens = tokenMsg.split('Output Tokens: ')[1]
completion = completion.split('Output Tokens: ')[0]
}
if (wordCount > wordCountMinimum) { // if (chunck === '.' && wordCount > wordCountMinimum) {
if (wordCountMinimum < 64) {
wordCountMinimum *= 2
Expand All @@ -114,8 +121,6 @@ export const anthropicStreamCompletion = async (
})
}
}
} else if (msg.startsWith('Output Tokens')) {
outputTokens = msg.split('Output Tokens: ')[1]
}
}
}
Expand Down

0 comments on commit cbe63e8

Please sign in to comment.