fix line end with new-line in some backend (#474)

* fix line end with new-line in some backend

In backend with golang (like https://github.com/sashabaranov/go-openai), the responseText always has '\n'.

* feat: 补全遗漏

---------

Co-authored-by: ChenZhaoYu <790348264@qq.com>
main
Liut 2 years ago committed by GitHub
parent 1edf591721
commit e30217542d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -115,7 +115,7 @@ async function onConversation() {
const xhr = event.target const xhr = event.target
const { responseText } = xhr const { responseText } = xhr
// Always process the final line // Always process the final line
const lastIndex = responseText.lastIndexOf('\n') const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
let chunk = responseText let chunk = responseText
if (lastIndex !== -1) if (lastIndex !== -1)
chunk = responseText.substring(lastIndex) chunk = responseText.substring(lastIndex)
@ -245,7 +245,7 @@ async function onRegenerate(index: number) {
const xhr = event.target const xhr = event.target
const { responseText } = xhr const { responseText } = xhr
// Always process the final line // Always process the final line
const lastIndex = responseText.lastIndexOf('\n') const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
let chunk = responseText let chunk = responseText
if (lastIndex !== -1) if (lastIndex !== -1)
chunk = responseText.substring(lastIndex) chunk = responseText.substring(lastIndex)

Loading…
Cancel
Save