Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
bf3f3c58
"vscode:/vscode.git/clone" did not exist on "ccb2211e4068785ff361b55cf2f8d8a7d4f3b807"
Commit
bf3f3c58
authored
Mar 02, 2024
by
Timothy J. Baek
Browse files
fix: text completion
parent
901e7a33
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
28 deletions
+27
-28
src/routes/(app)/playground/+page.svelte
src/routes/(app)/playground/+page.svelte
+27
-28
No files found.
src/routes/(app)/playground/+page.svelte
View file @
bf3f3c58
...
...
@@ -61,15 +61,26 @@
};
const textCompletionHandler = async () => {
const [res, controller] = await generateChatCompletion(localStorage.token, {
model: selectedModelId,
messages: [
{
role: 'assistant',
content: text
}
]
});
const model = $models.find((model) => model.id === selectedModelId);
const res = await generateOpenAIChatCompletion(
localStorage.token,
{
model: model.id,
stream: true,
messages: [
{
role: 'assistant',
content: text
}
]
},
model.external
? model.source === 'litellm'
? `${LITELLM_API_BASE_URL}/v1`
: `${OPENAI_API_BASE_URL}`
: `${OLLAMA_API_BASE_URL}/v1`
);
if (res && res.ok) {
const reader = res.body
...
...
@@ -80,10 +91,6 @@
while (true) {
const { value, done } = await reader.read();
if (done || stopResponseFlag) {
if (stopResponseFlag) {
await cancelChatCompletion(localStorage.token, currentRequestId);
}
currentRequestId = null;
break;
}
...
...
@@ -93,22 +100,14 @@
for (const line of lines) {
if (line !== '') {
console.log(line);
let data = JSON.parse(line);
if ('detail' in data) {
throw data;
}
if ('id' in data) {
console.log(data);
currentRequestId = data.id;
if (line === 'data: [DONE]') {
// responseMessage.done = true;
console.log('done');
} else {
if (data.done == false) {
text += data.message.content;
} else {
console.log('done');
}
let data = JSON.parse(line.replace(/^data: /, ''));
console.log(data);
text += data.choices[0].delta.content ?? '';
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment