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
67df928c
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "4fdb26fdc4e9360f28cdba9d44b4b8deaab79e1c"
Commit
67df928c
authored
Apr 21, 2024
by
Jun Siang Cheah
Browse files
feat: make chunk splitting a configurable option
parent
efa258c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
7 deletions
+41
-7
src/lib/apis/streaming/index.ts
src/lib/apis/streaming/index.ts
+7
-2
src/lib/components/chat/Settings/Interface.svelte
src/lib/components/chat/Settings/Interface.svelte
+28
-0
src/lib/i18n/locales/en-US/translation.json
src/lib/i18n/locales/en-US/translation.json
+1
-0
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+1
-1
src/routes/(app)/c/[id]/+page.svelte
src/routes/(app)/c/[id]/+page.svelte
+4
-4
No files found.
src/lib/apis/streaming/index.ts
View file @
67df928c
...
@@ -6,9 +6,14 @@ type TextStreamUpdate = {
...
@@ -6,9 +6,14 @@ type TextStreamUpdate = {
// createOpenAITextStream takes a ReadableStreamDefaultReader from an SSE response,
// createOpenAITextStream takes a ReadableStreamDefaultReader from an SSE response,
// and returns an async generator that emits delta updates with large deltas chunked into random sized chunks
// and returns an async generator that emits delta updates with large deltas chunked into random sized chunks
export
async
function
createOpenAITextStream
(
export
async
function
createOpenAITextStream
(
messageStream
:
ReadableStreamDefaultReader
messageStream
:
ReadableStreamDefaultReader
,
splitLargeDeltas
:
boolean
):
Promise
<
AsyncGenerator
<
TextStreamUpdate
>>
{
):
Promise
<
AsyncGenerator
<
TextStreamUpdate
>>
{
return
streamLargeDeltasAsRandomChunks
(
openAIStreamToIterator
(
messageStream
));
let
iterator
=
openAIStreamToIterator
(
messageStream
);
if
(
splitLargeDeltas
)
{
iterator
=
streamLargeDeltasAsRandomChunks
(
iterator
);
}
return
iterator
;
}
}
async
function
*
openAIStreamToIterator
(
async
function
*
openAIStreamToIterator
(
...
...
src/lib/components/chat/Settings/Interface.svelte
View file @
67df928c
...
@@ -17,11 +17,17 @@
...
@@ -17,11 +17,17 @@
let titleAutoGenerateModelExternal = '';
let titleAutoGenerateModelExternal = '';
let fullScreenMode = false;
let fullScreenMode = false;
let titleGenerationPrompt = '';
let titleGenerationPrompt = '';
let splitLargeChunks = false;
// Interface
// Interface
let promptSuggestions = [];
let promptSuggestions = [];
let showUsername = false;
let showUsername = false;
const toggleSplitLargeChunks = async () => {
splitLargeChunks = !splitLargeChunks;
saveSettings({ splitLargeChunks: splitLargeChunks });
};
const toggleFullScreenMode = async () => {
const toggleFullScreenMode = async () => {
fullScreenMode = !fullScreenMode;
fullScreenMode = !fullScreenMode;
saveSettings({ fullScreenMode: fullScreenMode });
saveSettings({ fullScreenMode: fullScreenMode });
...
@@ -197,6 +203,28 @@
...
@@ -197,6 +203,28 @@
</button>
</button>
</div>
</div>
</div>
</div>
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">
{$i18n.t('Fluidly stream large external response chunks')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleSplitLargeChunks();
}}
type="button"
>
{#if splitLargeChunks === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
</div>
</div>
<hr class=" dark:border-gray-700" />
<hr class=" dark:border-gray-700" />
...
...
src/lib/i18n/locales/en-US/translation.json
View file @
67df928c
...
@@ -152,6 +152,7 @@
...
@@ -152,6 +152,7 @@
"File Mode"
:
""
,
"File Mode"
:
""
,
"File not found."
:
""
,
"File not found."
:
""
,
"Fingerprint spoofing detected: Unable to use initials as avatar. Defaulting to default profile image."
:
""
,
"Fingerprint spoofing detected: Unable to use initials as avatar. Defaulting to default profile image."
:
""
,
"Fluidly stream large external response chunks"
:
""
,
"Focus chat input"
:
""
,
"Focus chat input"
:
""
,
"Format your variables using square brackets like this:"
:
""
,
"Format your variables using square brackets like this:"
:
""
,
"From (Base Model)"
:
""
,
"From (Base Model)"
:
""
,
...
...
src/routes/(app)/+page.svelte
View file @
67df928c
...
@@ -600,7 +600,7 @@
...
@@ -600,7 +600,7 @@
.
pipeThrough
(
splitStream
(
'\n'
))
.
pipeThrough
(
splitStream
(
'\n'
))
.
getReader
();
.
getReader
();
const
textStream
=
await
createOpenAITextStream
(
reader
);
const
textStream
=
await
createOpenAITextStream
(
reader
,
$
settings
.
splitLargeChunks
);
console
.
log
(
textStream
);
console
.
log
(
textStream
);
for
await
(
const
update
of
textStream
)
{
for
await
(
const
update
of
textStream
)
{
...
...
src/routes/(app)/c/[id]/+page.svelte
View file @
67df928c
...
@@ -552,9 +552,9 @@
...
@@ -552,9 +552,9 @@
messages
:
[
messages
:
[
$
settings
.
system
$
settings
.
system
?
{
?
{
role
:
'system'
,
role
:
'system'
,
content
:
$
settings
.
system
content
:
$
settings
.
system
}
}
:
undefined
,
:
undefined
,
...
messages
...
messages
]
]
...
@@ -612,7 +612,7 @@
...
@@ -612,7 +612,7 @@
.
pipeThrough
(
splitStream
(
'\n'
))
.
pipeThrough
(
splitStream
(
'\n'
))
.
getReader
();
.
getReader
();
const
textStream
=
await
createOpenAITextStream
(
reader
);
const
textStream
=
await
createOpenAITextStream
(
reader
,
$
settings
.
splitLargeChunks
);
console
.
log
(
textStream
);
console
.
log
(
textStream
);
for
await
(
const
update
of
textStream
)
{
for
await
(
const
update
of
textStream
)
{
...
...
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