mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-05 11:07:55 -05:00
refac
This commit is contained in:
1 parent
924e9885fc
commit
0481ad7c2e
77 files changed
+816
-1067
No files matched your search
@@ -417,12 +417,12 @@ async def _generate_summary(
|
||||
models = await add_tether_model(request, user, model_id, models)
|
||||
|
||||
task_config = await Config.get_many(
|
||||
'task.model.params',
|
||||
'system_model.params',
|
||||
'chat.context_compaction.model',
|
||||
)
|
||||
context_compaction_model = task_config.get('chat.context_compaction.model')
|
||||
task_model_id = context_compaction_model if context_compaction_model in models else model_id
|
||||
if task_model_id not in models:
|
||||
compaction_model_id = context_compaction_model if context_compaction_model in models else model_id
|
||||
if compaction_model_id not in models:
|
||||
raise ValueError('No available model for context compaction')
|
||||
|
||||
summary_prompt_template = summary_prompt_template.strip() or DEFAULT_CONTEXT_COMPACTION_PROMPT
|
||||
@@ -453,10 +453,12 @@ async def _generate_summary(
|
||||
prompt = prompt_variables_template(prompt, {'{{PREVIOUS_SUMMARY}}': summary or ''})
|
||||
return await prompt_template(prompt, user)
|
||||
|
||||
task_model_params = task_config.get('task.model.params') or {}
|
||||
if not isinstance(task_model_params, dict):
|
||||
task_model_params = {}
|
||||
task_model_params = {key: value for key, value in task_model_params.items() if value is not None and value != ''}
|
||||
system_model_params = task_config.get('system_model.params') or {}
|
||||
if not isinstance(system_model_params, dict):
|
||||
system_model_params = {}
|
||||
system_model_params = {
|
||||
key: value for key, value in system_model_params.items() if value is not None and value != ''
|
||||
}
|
||||
|
||||
metadata = {
|
||||
**(request.state.metadata if hasattr(request.state, 'metadata') else {}),
|
||||
@@ -467,7 +469,7 @@ async def _generate_summary(
|
||||
# A repeated or transformed boundary cannot safely identify the history to discard.
|
||||
if (
|
||||
form_data
|
||||
and task_model_id == model_id
|
||||
and compaction_model_id == model_id
|
||||
and has_unique_prefix
|
||||
and sum(_message_prefix(message) == boundary_prefix for message in form_data['messages']) == 1
|
||||
):
|
||||
@@ -486,7 +488,7 @@ async def _generate_summary(
|
||||
)
|
||||
)
|
||||
payload = {
|
||||
'model': task_model_id,
|
||||
'model': compaction_model_id,
|
||||
'messages': [*copy.deepcopy(form_data['messages']), {'role': 'user', 'content': prompt}],
|
||||
'stream': False,
|
||||
'metadata': metadata,
|
||||
@@ -496,7 +498,7 @@ async def _generate_summary(
|
||||
try:
|
||||
response = await generate_chat_completion(
|
||||
request,
|
||||
form_data=apply_params_to_form_data(payload, models[task_model_id], task_model_params),
|
||||
form_data=apply_params_to_form_data(payload, models[compaction_model_id], system_model_params),
|
||||
user=user,
|
||||
bypass_system_prompt=bypass_system_prompt,
|
||||
)
|
||||
@@ -508,13 +510,13 @@ async def _generate_summary(
|
||||
|
||||
prompt = await render_prompt(summary_prompt_template)
|
||||
payload = {
|
||||
'model': task_model_id,
|
||||
'model': compaction_model_id,
|
||||
'messages': [{'role': 'user', 'content': prompt}],
|
||||
'stream': False,
|
||||
'metadata': metadata,
|
||||
}
|
||||
|
||||
payload = apply_params_to_form_data(payload, models[task_model_id], task_model_params)
|
||||
payload = apply_params_to_form_data(payload, models[compaction_model_id], system_model_params)
|
||||
response = await generate_chat_completion(request, form_data=payload, user=user)
|
||||
text = _response_text(response).strip()
|
||||
if text:
|
||||
|
||||
Reference in new issue
Block a user