mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
refac
This commit is contained in:
parent
2e36540023
commit
3a1bbcb12e
3 changed files with 20 additions and 15 deletions
|
|
@ -1463,14 +1463,17 @@ async def process_chat_response(
|
||||||
|
|
||||||
reasoning_duration = block.get("duration", None)
|
reasoning_duration = block.get("duration", None)
|
||||||
|
|
||||||
|
start_tag = block.get("start_tag", "")
|
||||||
|
end_tag = block.get("end_tag", "")
|
||||||
|
|
||||||
if reasoning_duration is not None:
|
if reasoning_duration is not None:
|
||||||
if raw:
|
if raw:
|
||||||
content = f'{content}\n{block["start_tag"]}{block["content"]}{block["end_tag"]}\n'
|
content = f'{content}\n{start_tag}{block["content"]}{end_tag}\n'
|
||||||
else:
|
else:
|
||||||
content = f'{content}\n<details type="reasoning" done="true" duration="{reasoning_duration}">\n<summary>Thought for {reasoning_duration} seconds</summary>\n{reasoning_display_content}\n</details>\n'
|
content = f'{content}\n<details type="reasoning" done="true" duration="{reasoning_duration}">\n<summary>Thought for {reasoning_duration} seconds</summary>\n{reasoning_display_content}\n</details>\n'
|
||||||
else:
|
else:
|
||||||
if raw:
|
if raw:
|
||||||
content = f'{content}\n{block["start_tag"]}{block["content"]}{block["end_tag"]}\n'
|
content = f'{content}\n{start_tag}{block["content"]}{end_tag}\n'
|
||||||
else:
|
else:
|
||||||
content = f'{content}\n<details type="reasoning" done="false">\n<summary>Thinking…</summary>\n{reasoning_display_content}\n</details>\n'
|
content = f'{content}\n<details type="reasoning" done="false">\n<summary>Thinking…</summary>\n{reasoning_display_content}\n</details>\n'
|
||||||
|
|
||||||
|
|
@ -1511,7 +1514,7 @@ async def process_chat_response(
|
||||||
|
|
||||||
return content.strip()
|
return content.strip()
|
||||||
|
|
||||||
def convert_content_blocks_to_messages(content_blocks):
|
def convert_content_blocks_to_messages(content_blocks, raw=False):
|
||||||
messages = []
|
messages = []
|
||||||
|
|
||||||
temp_blocks = []
|
temp_blocks = []
|
||||||
|
|
@ -1520,7 +1523,7 @@ async def process_chat_response(
|
||||||
messages.append(
|
messages.append(
|
||||||
{
|
{
|
||||||
"role": "assistant",
|
"role": "assistant",
|
||||||
"content": serialize_content_blocks(temp_blocks),
|
"content": serialize_content_blocks(temp_blocks, raw),
|
||||||
"tool_calls": block.get("content"),
|
"tool_calls": block.get("content"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -1540,7 +1543,7 @@ async def process_chat_response(
|
||||||
temp_blocks.append(block)
|
temp_blocks.append(block)
|
||||||
|
|
||||||
if temp_blocks:
|
if temp_blocks:
|
||||||
content = serialize_content_blocks(temp_blocks)
|
content = serialize_content_blocks(temp_blocks, raw)
|
||||||
if content:
|
if content:
|
||||||
messages.append(
|
messages.append(
|
||||||
{
|
{
|
||||||
|
|
@ -1936,8 +1939,8 @@ async def process_chat_response(
|
||||||
):
|
):
|
||||||
reasoning_block = {
|
reasoning_block = {
|
||||||
"type": "reasoning",
|
"type": "reasoning",
|
||||||
"start_tag": "think",
|
"start_tag": "<think>",
|
||||||
"end_tag": "/think",
|
"end_tag": "</think>",
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"type": "reasoning_content"
|
"type": "reasoning_content"
|
||||||
},
|
},
|
||||||
|
|
@ -2253,7 +2256,9 @@ async def process_chat_response(
|
||||||
"tools": form_data["tools"],
|
"tools": form_data["tools"],
|
||||||
"messages": [
|
"messages": [
|
||||||
*form_data["messages"],
|
*form_data["messages"],
|
||||||
*convert_content_blocks_to_messages(content_blocks),
|
*convert_content_blocks_to_messages(
|
||||||
|
content_blocks, True
|
||||||
|
),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
import XMark from '$lib/components/icons/XMark.svelte';
|
import XMark from '$lib/components/icons/XMark.svelte';
|
||||||
|
import Textarea from '$lib/components/common/Textarea.svelte';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
|
@ -111,15 +112,12 @@
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{#if document.metadata?.parameters}
|
{#if document.metadata?.parameters}
|
||||||
<div class="text-sm font-medium dark:text-gray-300 mt-2">
|
<div class="text-sm font-medium dark:text-gray-300 mt-2 mb-0.5">
|
||||||
{$i18n.t('Parameters')}
|
{$i18n.t('Parameters')}
|
||||||
</div>
|
</div>
|
||||||
<pre
|
|
||||||
class="text-sm dark:text-gray-400 bg-gray-50 dark:bg-gray-800 p-2 rounded-md overflow-auto max-h-40">{JSON.stringify(
|
<Textarea readonly value={JSON.stringify(document.metadata.parameters, null, 2)}
|
||||||
document.metadata.parameters,
|
></Textarea>
|
||||||
null,
|
|
||||||
2
|
|
||||||
)}</pre>
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if showRelevance}
|
{#if showRelevance}
|
||||||
<div class="text-sm font-medium dark:text-gray-300 mt-2">
|
<div class="text-sm font-medium dark:text-gray-300 mt-2">
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
export let minSize = null;
|
export let minSize = null;
|
||||||
export let maxSize = null;
|
export let maxSize = null;
|
||||||
export let required = false;
|
export let required = false;
|
||||||
|
export let readonly = false;
|
||||||
export let className =
|
export let className =
|
||||||
'w-full rounded-lg px-3.5 py-2 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden h-full';
|
'w-full rounded-lg px-3.5 py-2 text-sm bg-gray-50 dark:text-gray-300 dark:bg-gray-850 outline-hidden h-full';
|
||||||
|
|
||||||
|
|
@ -54,6 +55,7 @@
|
||||||
style="field-sizing: content;"
|
style="field-sizing: content;"
|
||||||
{rows}
|
{rows}
|
||||||
{required}
|
{required}
|
||||||
|
{readonly}
|
||||||
on:input={(e) => {
|
on:input={(e) => {
|
||||||
resize();
|
resize();
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue