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
04e2b6e2
Commit
04e2b6e2
authored
Aug 14, 2024
by
Timothy J. Baek
Browse files
chore: format
parent
9f0c9d97
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
100 deletions
+107
-100
src/lib/components/chat/Messages/ResponseMessage.svelte
src/lib/components/chat/Messages/ResponseMessage.svelte
+2
-2
src/lib/utils/katex-extension.ts
src/lib/utils/katex-extension.ts
+105
-98
No files found.
src/lib/components/chat/Messages/ResponseMessage.svelte
View file @
04e2b6e2
...
@@ -159,7 +159,7 @@
...
@@ -159,7 +159,7 @@
const res = await synthesizeOpenAISpeech(
const res = await synthesizeOpenAISpeech(
localStorage.token,
localStorage.token,
$settings?.audio?.tts?.defaultVoice === $config.audio.tts.voice
$settings?.audio?.tts?.defaultVoice === $config.audio.tts.voice
? $settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice
?
(
$settings?.audio?.tts?.voice ?? $config?.audio?.tts?.voice
)
: $config?.audio?.tts?.voice,
: $config?.audio?.tts?.voice,
sentence
sentence
).catch((error) => {
).catch((error) => {
...
...
src/lib/utils/katex-extension.ts
View file @
04e2b6e2
...
@@ -9,7 +9,7 @@ const DELIMITER_LIST = [
...
@@ -9,7 +9,7 @@ const DELIMITER_LIST = [
{
left
:
'
(
'
,
right
:
'
)
'
,
display
:
false
},
{
left
:
'
(
'
,
right
:
'
)
'
,
display
:
false
},
{
left
:
'
\\
[
'
,
right
:
'
\\
]
'
,
display
:
true
},
{
left
:
'
\\
[
'
,
right
:
'
\\
]
'
,
display
:
true
},
{
left
:
'
[
'
,
right
:
'
]
'
,
display
:
true
}
{
left
:
'
[
'
,
right
:
'
]
'
,
display
:
true
}
]
]
;
// const DELIMITER_LIST = [
// const DELIMITER_LIST = [
// { left: '$$', right: '$$', display: false },
// { left: '$$', right: '$$', display: false },
...
@@ -27,7 +27,7 @@ function escapeRegex(string) {
...
@@ -27,7 +27,7 @@ function escapeRegex(string) {
}
}
function
generateRegexRules
(
delimiters
)
{
function
generateRegexRules
(
delimiters
)
{
delimiters
.
forEach
(
delimiter
=>
{
delimiters
.
forEach
(
(
delimiter
)
=>
{
const
{
left
,
right
}
=
delimiter
;
const
{
left
,
right
}
=
delimiter
;
// Ensure regex-safe delimiters
// Ensure regex-safe delimiters
const
escapedLeft
=
escapeRegex
(
left
);
const
escapedLeft
=
escapeRegex
(
left
);
...
@@ -35,7 +35,9 @@ function generateRegexRules(delimiters) {
...
@@ -35,7 +35,9 @@ function generateRegexRules(delimiters) {
// Inline pattern - Capture group $1, token content, followed by end delimiter and normal punctuation marks.
// Inline pattern - Capture group $1, token content, followed by end delimiter and normal punctuation marks.
// Example: $text$
// Example: $text$
inlinePatterns
.
push
(
`
${
escapedLeft
}
((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n
${
escapedRight
}
]))
${
escapedRight
}
`
);
inlinePatterns
.
push
(
`
${
escapedLeft
}
((?:\\\\.|[^\\\\\\n])*?(?:\\\\.|[^\\\\\\n
${
escapedRight
}
]))
${
escapedRight
}
`
);
// Block pattern - Starts and ends with the delimiter on new lines. Example:
// Block pattern - Starts and ends with the delimiter on new lines. Example:
// $$\ncontent here\n$$
// $$\ncontent here\n$$
...
@@ -50,19 +52,19 @@ function generateRegexRules(delimiters) {
...
@@ -50,19 +52,19 @@ function generateRegexRules(delimiters) {
const
{
inlineRule
,
blockRule
}
=
generateRegexRules
(
DELIMITER_LIST
);
const
{
inlineRule
,
blockRule
}
=
generateRegexRules
(
DELIMITER_LIST
);
export
default
function
(
options
=
{})
{
export
default
function
(
options
=
{})
{
return
{
return
{
extensions
:
[
extensions
:
[
inlineKatex
(
options
,
createRenderer
(
options
,
false
)),
inlineKatex
(
options
,
createRenderer
(
options
,
false
)),
blockKatex
(
options
,
createRenderer
(
options
,
true
))
,
blockKatex
(
options
,
createRenderer
(
options
,
true
))
],
]
};
};
}
}
function
createRenderer
(
options
,
newlineAfter
)
{
function
createRenderer
(
options
,
newlineAfter
)
{
return
(
token
)
=>
katex
.
renderToString
(
token
.
text
,
{
...
options
,
displayMode
:
token
.
displayMode
})
+
(
newlineAfter
?
'
\n
'
:
''
);
return
(
token
)
=>
katex
.
renderToString
(
token
.
text
,
{
...
options
,
displayMode
:
token
.
displayMode
})
+
(
newlineAfter
?
'
\n
'
:
''
);
}
}
function
inlineKatex
(
options
,
renderer
)
{
function
inlineKatex
(
options
,
renderer
)
{
...
@@ -95,16 +97,19 @@ function inlineKatex(options, renderer) {
...
@@ -95,16 +97,19 @@ function inlineKatex(options, renderer) {
const
match
=
src
.
match
(
ruleReg
);
const
match
=
src
.
match
(
ruleReg
);
if
(
match
)
{
if
(
match
)
{
const
text
=
match
.
slice
(
2
).
filter
((
item
)
=>
item
).
find
((
item
)
=>
item
.
trim
());
const
text
=
match
.
slice
(
2
)
.
filter
((
item
)
=>
item
)
.
find
((
item
)
=>
item
.
trim
());
return
{
return
{
type
:
'
inlineKatex
'
,
type
:
'
inlineKatex
'
,
raw
:
match
[
0
],
raw
:
match
[
0
],
text
:
text
,
text
:
text
};
};
}
}
},
},
renderer
,
renderer
};
};
}
}
...
@@ -116,16 +121,18 @@ function blockKatex(options, renderer) {
...
@@ -116,16 +121,18 @@ function blockKatex(options, renderer) {
const
match
=
src
.
match
(
blockRule
);
const
match
=
src
.
match
(
blockRule
);
if
(
match
)
{
if
(
match
)
{
const
text
=
match
.
slice
(
2
).
filter
((
item
)
=>
item
).
find
((
item
)
=>
item
.
trim
());
const
text
=
match
.
slice
(
2
)
.
filter
((
item
)
=>
item
)
.
find
((
item
)
=>
item
.
trim
());
return
{
return
{
type
:
'
blockKatex
'
,
type
:
'
blockKatex
'
,
raw
:
match
[
0
],
raw
:
match
[
0
],
text
:
text
,
text
:
text
};
};
}
}
},
},
renderer
,
renderer
};
};
}
}
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