Skip to content

Commit

Permalink
[Web] fix abort in structured mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Cerlancism committed Sep 28, 2024
1 parent 8149cee commit 209cc67
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 82 deletions.
151 changes: 73 additions & 78 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@nextui-org/react": "2.2.10",
"chatgpt-subtitle-translator": "github:Cerlancism/chatgpt-subtitle-translator#137e1cc02b70a85e694f45713078402b8bccc15c",
"chatgpt-subtitle-translator": "github:Cerlancism/chatgpt-subtitle-translator#8149ceebb24d216b21c52ce44927b80287528692",
"next": "14.2.13",
"react": "^18",
"react-dom": "^18"
Expand Down
8 changes: 5 additions & 3 deletions web/src/components/TranslatorApplication.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export function TranslatorApplication() {
setBaseUrlWithModerator(value)
}

function setBaseUrlWithModerator(value)
{
function setBaseUrlWithModerator(value) {
if (!baseUrlValue && value && useModerator) {
setUseModerator(false)
}
Expand Down Expand Up @@ -116,6 +115,9 @@ export function TranslatorApplication() {
},
onStreamEnd: () => {
currentStream = ""
if (translatorRef.current?.aborted) {
return
}
setStreamOutput("")
},
moderationService: {
Expand All @@ -137,10 +139,10 @@ export function TranslatorApplication() {
}

try {
setStreamOutput("")
for await (const output of translatorRef.current.translateLines(inputs)) {
if (!translatorRunningRef.current) {
console.error("[User Interface]", "Aborted")
setStreamOutput("")
break
}
currentOutputs.push(output.finalTransform)
Expand Down

0 comments on commit 209cc67

Please sign in to comment.