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
db817fcf
"vscode:/vscode.git/clone" did not exist on "786f3a1c44fb3733f6f1b5e7a5d20d6d772a4e47"
Commit
db817fcf
authored
Apr 13, 2024
by
Jun Siang Cheah
Browse files
feat: add {{prompt:start:length}} and {{prompt:end:length}} to title gen
parent
8e30948d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
+29
-2
src/lib/apis/ollama/index.ts
src/lib/apis/ollama/index.ts
+2
-1
src/lib/apis/openai/index.ts
src/lib/apis/openai/index.ts
+2
-1
src/lib/utils/index.ts
src/lib/utils/index.ts
+25
-0
No files found.
src/lib/apis/ollama/index.ts
View file @
db817fcf
import
{
OLLAMA_API_BASE_URL
}
from
'
$lib/constants
'
;
import
{
templatePrompt
}
from
'
$lib/utils
'
;
export
const
getOllamaUrls
=
async
(
token
:
string
=
''
)
=>
{
let
error
=
null
;
...
...
@@ -144,7 +145,7 @@ export const generateTitle = async (
)
=>
{
let
error
=
null
;
template
=
template
.
replace
(
/{{prompt}}/g
,
prompt
);
template
=
template
Prompt
(
template
,
prompt
);
console
.
log
(
template
);
...
...
src/lib/apis/openai/index.ts
View file @
db817fcf
import
{
OPENAI_API_BASE_URL
}
from
'
$lib/constants
'
;
import
{
templatePrompt
}
from
'
$lib/utils
'
;
export
const
getOpenAIUrls
=
async
(
token
:
string
=
''
)
=>
{
let
error
=
null
;
...
...
@@ -273,7 +274,7 @@ export const generateTitle = async (
)
=>
{
let
error
=
null
;
template
=
template
.
replace
(
/{{prompt}}/g
,
prompt
);
template
=
template
Prompt
(
template
,
prompt
);
console
.
log
(
template
);
...
...
src/lib/utils/index.ts
View file @
db817fcf
...
...
@@ -467,3 +467,28 @@ export const blobToFile = (blob, fileName) => {
const
file
=
new
File
([
blob
],
fileName
,
{
type
:
blob
.
type
});
return
file
;
};
// templatePrompt replaces any occurrences of the following in the template with the prompt
// {{prompt}} will be replaced with the prompt
// {{prompt:start:<length>}} will be replaced with the first <length> characters of the prompt
// {{prompt:end:<length>}} will be replaced with the last <length> characters of the prompt
// Character length is used as we don't have the ability to tokenize the prompt
export
const
templatePrompt
=
(
template
,
prompt
)
=>
{
template
=
template
.
replace
(
/{{prompt}}/g
,
prompt
);
// Replace {{prompt:start:<length>}} with the first <length> characters of the prompt
const
startMatch
=
template
.
match
(
/{{prompt:start:
(\d
+
)
}}/
);
if
(
startMatch
)
{
const
length
=
parseInt
(
startMatch
[
1
]);
template
=
template
.
replace
(
startMatch
[
0
],
prompt
.
substring
(
0
,
length
));
}
// Replace {{prompt:end:<length>}} with the last <length> characters of the prompt
const
endMatch
=
template
.
match
(
/{{prompt:end:
(\d
+
)
}}/
);
if
(
endMatch
)
{
const
length
=
parseInt
(
endMatch
[
1
]);
template
=
template
.
replace
(
endMatch
[
0
],
prompt
.
substring
(
prompt
.
length
-
length
));
}
return
template
;
};
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