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
941bb7c6
Commit
941bb7c6
authored
Mar 26, 2024
by
Timothy J. Baek
Browse files
refac: chat[id] page
parent
3edc5473
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
39 deletions
+51
-39
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+11
-11
src/routes/(app)/c/[id]/+page.svelte
src/routes/(app)/c/[id]/+page.svelte
+40
-28
No files found.
src/routes/(app)/+page.svelte
View file @
941bb7c6
...
...
@@ -784,6 +784,17 @@
}
};
const
setChatTitle
=
async
(
_chatId
,
_title
)
=>
{
if
(
_chatId
===
$
chatId
)
{
title
=
_title
;
}
if
($
settings
.
saveChatHistory
??
true
)
{
chat
=
await
updateChatById
(
localStorage
.
token
,
_chatId
,
{
title
:
_title
});
await
chats
.
set
(
await
getChatList
(
localStorage
.
token
));
}
};
const
getTags
=
async
()
=>
{
return
await
getTagsById
(
localStorage
.
token
,
$
chatId
).
catch
(
async
(
error
)
=>
{
return
[];
...
...
@@ -811,17 +822,6 @@
_tags
.
set
(
await
getAllChatTags
(
localStorage
.
token
));
};
const
setChatTitle
=
async
(
_chatId
,
_title
)
=>
{
if
(
_chatId
===
$
chatId
)
{
title
=
_title
;
}
if
($
settings
.
saveChatHistory
??
true
)
{
chat
=
await
updateChatById
(
localStorage
.
token
,
_chatId
,
{
title
:
_title
});
await
chats
.
set
(
await
getChatList
(
localStorage
.
token
));
}
};
</
script
>
<
svelte
:
head
>
...
...
src/routes/(app)/c/[id]/+page.svelte
View file @
941bb7c6
...
...
@@ -521,7 +521,8 @@
if
(
messages
.
length
==
2
&&
messages
.
at
(
1
).
content
!== '') {
window
.
history
.
replaceState
(
history
.
state
,
''
,
`/
c
/${
_chatId
}`);
await
generateChatTitle
(
_chatId
,
userPrompt
);
const
_title
=
await
generateChatTitle
(
userPrompt
);
await
setChatTitle
(
_chatId
,
_title
);
}
};
...
...
@@ -706,11 +707,8 @@
if
(
messages
.
length
==
2
)
{
window
.
history
.
replaceState
(
history
.
state
,
''
,
`/
c
/${
_chatId
}`);
if
($
settings
?.
titleAutoGenerateModel
)
{
await
generateChatTitle
(
_chatId
,
userPrompt
);
}
else
{
await
setChatTitle
(
_chatId
,
userPrompt
);
}
const
_title
=
await
generateChatTitle
(
userPrompt
);
await
setChatTitle
(
_chatId
,
_title
);
}
};
...
...
@@ -719,6 +717,19 @@
console
.
log
(
'stopResponse'
);
};
const
regenerateResponse
=
async
()
=>
{
console
.
log
(
'regenerateResponse'
);
if
(
messages
.
length
!= 0 && messages.at(-1).done == true) {
messages
.
splice
(
messages
.
length
-
1
,
1
);
messages
=
messages
;
let
userMessage
=
messages
.
at
(-
1
);
let
userPrompt
=
userMessage
.
content
;
await
sendPrompt
(
userPrompt
,
userMessage
.
id
);
}
};
const
continueGeneration
=
async
()
=>
{
console
.
log
(
'continueGeneration'
);
const
_chatId
=
JSON
.
parse
(
JSON
.
stringify
($
chatId
));
...
...
@@ -751,36 +762,35 @@
}
};
const
regenerateResponse
=
async
()
=>
{
console
.
log
(
'regenerateResponse'
);
if
(
messages
.
length
!= 0 && messages.at(-1).done == true) {
messages
.
splice
(
messages
.
length
-
1
,
1
);
messages
=
messages
;
let
userMessage
=
messages
.
at
(-
1
);
let
userPrompt
=
userMessage
.
content
;
const
generateChatTitle
=
async
(
userPrompt
)
=>
{
if
($
settings
?.
title
?.
auto
??
true
)
{
const
model
=
$
models
.
find
((
model
)
=>
model
.
id
===
selectedModels
[
0
]);
await
sendPrompt
(
userPrompt
,
userMessage
.
id
);
}
};
const
titleModelId
=
model
?.
external
??
false
?
$
settings
?.
title
?.
modelExternal
??
selectedModels
[
0
]
:
$
settings
?.
title
?.
model
??
selectedModels
[
0
];
const
titleModel
=
$
models
.
find
((
model
)
=>
model
.
id
===
titleModelId
);
const
generateChatTitle
=
async
(
_chatId
,
userPrompt
)
=>
{
if
($
settings
.
titleAutoGenerate
??
true
)
{
console
.
log
(
titleModel
);
const
title
=
await
generateTitle
(
localStorage
.
token
,
$
settings
?.
title
GenerationP
rompt
??
$
settings
?.
title
?.
p
rompt
??
$
i18n
.
t
(
"Create a concise, 3-5 word phrase as a header for the following query, strictly adhering to the 3-5 word limit and avoiding the use of the word 'title':"
)
+
' {{prompt}}'
,
$
settings
?.
titleAutoGenerateModel
??
selectedModels
[
0
],
userPrompt
titleModelId
,
userPrompt
,
titleModel
?.
external
??
false
?
titleModel
.
source
===
'litellm'
?
`${
LITELLM_API_BASE_URL
}/
v1
`
:
`${
OPENAI_API_BASE_URL
}`
:
`${
OLLAMA_API_BASE_URL
}/
v1
`
);
if
(
title
)
{
await
setChatTitle
(
_chatId
,
title
);
}
return
title
;
}
else
{
await
setChatTitle
(
_chatId
,
`${
userPrompt
}`
)
;
return
`${
userPrompt
}`;
}
};
...
...
@@ -789,8 +799,10 @@
title
=
_title
;
}
chat
=
await
updateChatById
(
localStorage
.
token
,
_chatId
,
{
title
:
_title
});
await
chats
.
set
(
await
getChatList
(
localStorage
.
token
));
if
($
settings
.
saveChatHistory
??
true
)
{
chat
=
await
updateChatById
(
localStorage
.
token
,
_chatId
,
{
title
:
_title
});
await
chats
.
set
(
await
getChatList
(
localStorage
.
token
));
}
};
const
getTags
=
async
()
=>
{
...
...
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