This commit is contained in:
liubiren 2026-07-30 11:20:39 +08:00
parent a6bf6dbac3
commit 5f438285a9
7 changed files with 97 additions and 58 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ __pycache__/
**/__pycache__/ **/__pycache__/
.DS_Store .DS_Store
.gitignore .gitignore
agent/models/

View File

@ -142,7 +142,7 @@ def conversation_history_item_showing(
min_width="14px", min_width="14px",
cursor="pointer", cursor="pointer",
opacity=rx.cond(highlight, "1", "0"), opacity=rx.cond(highlight, "1", "0"),
transition="opacity 0.18s ease", transition="opacity 0.18s ease-in-out",
pointer_events=rx.cond(highlight, "auto", "none"), pointer_events=rx.cond(highlight, "auto", "none"),
), ),
display="flex", display="flex",
@ -221,7 +221,7 @@ def conversation_history_items_showing(
min_width=rx.cond(is_conversation_history_shown, "240px", "0px"), min_width=rx.cond(is_conversation_history_shown, "240px", "0px"),
max_width=rx.cond(is_conversation_history_shown, "380px", "0px"), max_width=rx.cond(is_conversation_history_shown, "380px", "0px"),
height="100%", height="100%",
transition="all 0.3s ease-in-out", transition="all 0.18s ease-in-out",
overflow="hidden", overflow="hidden",
) )
@ -346,8 +346,8 @@ def thought_showing(item: Tuple[int, Thought]):
"thinking", "thinking",
rx.text( rx.text(
thought.content, thought.content,
line_height="22px", line_height="1.6",
font_size="var(--prismui-font-size-2)", font_size="var(--prismui-font-size-1)",
color="var(--prismui-color-3)", color="var(--prismui-color-3)",
), ),
), ),
@ -416,35 +416,32 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
), ),
# 思考折叠面板 # 思考折叠面板
rx.vstack( rx.vstack(
# 标题 # 标题
rx.box( rx.box(
rx.hstack( rx.hstack(
rx.text( rx.text(
rx.cond(is_thinking, "思考中", "思考完成"), rx.cond(is_thinking, "思考中", "思考完成"),
font_size="var(--prismui-font-size-1)",
color="var(--prismui-color-3)", color="var(--prismui-color-3)",
font_size="var(--prismui-font-size-2)",
), ),
rx.icon( rx.icon(
"chevron-right", "chevron-right",
width="14px", width="14px",
height="14px", height="14px",
color="var(--prismui-color-3)", color="var(--prismui-color-3)",
style={ transform=rx.cond(is_expanded, "rotate(90deg)", "rotate(0deg)"),
"transform": rx.cond( transition="transform 0.18s ease-in-out",
is_expanded, "rotate(90deg)", "rotate(0deg)"
),
"transition": "transform 0.2s ease-out",
},
), ),
align_items="center", align_items="center",
gap="4px", gap="4px",
margin_bottom="8px", margin_bottom="8px",
line_height="22px", line_height="22px",
), ),
cursor="pointer",
# 点击事件,展开/折叠思考折叠面板 # 点击事件,展开/折叠思考折叠面板
on_click=lambda: ConversationState.toggle_collapse(dialog.id), on_click=lambda: ConversationState.toggle_collapse(dialog.id),
cursor="pointer",
), ),
# 思考
rx.box( rx.box(
rx.box( rx.box(
rx.auto_scroll( rx.auto_scroll(
@ -458,15 +455,13 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
), ),
style={"overflow": "hidden", "min-height": "0"}, style={"overflow": "hidden", "min-height": "0"},
), ),
display="grid",
grid_template_rows=rx.cond(is_expanded, "1fr", "0fr"),
width="100%", width="100%",
style={ margin_bottom="8px",
"display": "grid", opacity=rx.cond(is_expanded, "1", "0"),
"overflow": "hidden", overflow="hidden",
"grid_template_rows": rx.cond(is_expanded, "1fr", "0fr"), transition="grid-template-rows 0.18s ease-in-out, opacity 0.18s ease-in-out",
"opacity": rx.cond(is_expanded, "1", "0"),
# 双属性同步过渡,和千问一致
"transition": "grid-template-rows 0.3s ease-out, opacity 0.3s ease-out",
},
), ),
), ),
# 结果输出 # 结果输出
@ -481,11 +476,23 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
word_break="break-all", word_break="break-all",
white_space="pre-line", white_space="pre-line",
), ),
"strong": lambda text: rx.text(
text,
display="inline",
font_weight="var(--prismui-font-weight-3)",
),
"code": lambda text: rx.text(
text,
display="inline",
background_color="var(--prismui-background-color-6)",
border_radius="var(--prismui-border-radius-1)",
color="var(--prismui-color-5)",
),
"h1": lambda text: rx.text( "h1": lambda text: rx.text(
text, text,
margin="8px 0 4px", margin="8px 0 4px",
line_height="1.75", line_height="1.75",
font_size="18px", font_size="var(--prismui-font-size-4)",
font_weight="var(--prismui-font-weight-3)", font_weight="var(--prismui-font-weight-3)",
word_wrap="break-word", word_wrap="break-word",
word_break="break-all", word_break="break-all",
@ -495,7 +502,7 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
text, text,
margin="6px 0 4px", margin="6px 0 4px",
line_height="1.75", line_height="1.75",
font_size="16px", font_size="var(--prismui-font-size-3)",
font_weight="var(--prismui-font-weight-3)", font_weight="var(--prismui-font-weight-3)",
word_wrap="break-word", word_wrap="break-word",
word_break="break-all", word_break="break-all",
@ -510,11 +517,6 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
word_break="break-all", word_break="break-all",
white_space="pre-line", white_space="pre-line",
), ),
"strong": lambda text: rx.text(
text,
display="inline",
font_weight="var(--prismui-font-weight-3)",
),
"ul": lambda children: rx.vstack( "ul": lambda children: rx.vstack(
children, children,
align_items="flex-start", align_items="flex-start",
@ -532,8 +534,8 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
width="4.5px", width="4.5px",
height="4.5px", height="4.5px",
margin_right="8px", margin_right="8px",
background_color="var(--prismui-color-5)", background_color="var(--prismui-background-color-7)",
border_radius="50%", border_radius="100%",
), ),
rx.text( rx.text(
text, text,
@ -553,31 +555,25 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component:
), ),
"table": lambda children: rx.el.table( "table": lambda children: rx.el.table(
children, children,
style={ width="100%",
"margin": "12px 0", margin="8px 0",
"width": "100%", border_collapse="collapse",
"border-collapse": "collapse",
},
), ),
"thead": lambda children: rx.el.thead(children), "thead": lambda children: rx.el.thead(children),
"tbody": lambda children: rx.el.tbody(children), "tbody": lambda children: rx.el.tbody(children),
"tr": lambda children: rx.el.tr(children), "tr": lambda children: rx.el.tr(children),
"th": lambda text: rx.el.th( "th": lambda children: rx.el.th(
text, children,
style={ padding="8px 12px",
"padding": "10px 12px", background_color="var(--prismui-background-color-6)",
"background": "var(--prismui-background-color-3)", border="1px solid var(--prismui-background-color-2)",
"border": "1px solid var(--prismui-background-color-6)", text_align="left",
"text-align": "left",
},
), ),
"td": lambda text: rx.el.td( "td": lambda children: rx.el.td(
text, children,
style={ padding="8px 12px",
"padding": "10px 12px", border="1px solid var(--prismui-background-color-2)",
"border": "1px solid var(--prismui-background-color-6)", text_align="left",
"vertical-align": "top",
},
), ),
}, },
width="100%", width="100%",
@ -860,7 +856,7 @@ def conversation_history_collapse_button(
"0 var(--prismui-border-radius-2)", "0 var(--prismui-border-radius-2)",
), ),
box_shadow="var(--prismui-box-shadow-4)", box_shadow="var(--prismui-box-shadow-4)",
transition="all 0.3s ease-in-out", transition="all 0.18s ease-in-out",
cursor="pointer", cursor="pointer",
) )
@ -901,7 +897,7 @@ def conversation() -> rx.Component:
height="100%", height="100%",
min_height="0", min_height="0",
overflow="hidden", overflow="hidden",
transition="all 0.3s ease-in-out", transition="all 0.18s ease-in-out",
), ),
# 会话历史折叠面板按钮 # 会话历史折叠面板按钮
conversation_history_collapse_button(is_conversation_history_shown), conversation_history_collapse_button(is_conversation_history_shown),

View File

@ -224,7 +224,7 @@ def login_popup() -> rx.Component:
"登录解锁更多功能", "登录解锁更多功能",
margin_bottom="24px", margin_bottom="24px",
line_height="32px", line_height="32px",
font_size="var(--prismui-font-size-4)", font_size="var(--prismui-font-size-5)",
font_weight="var(--prismui-font-weight-3)", font_weight="var(--prismui-font-weight-3)",
), ),
# 邮箱输入框 # 邮箱输入框

View File

@ -286,10 +286,9 @@ class ConversationState(rx.State):
match part: match part:
# 思考分片开始事件 # 思考分片开始事件
case ThinkingPart(content=content): case ThinkingPart(content=content):
# 若上一分片种类为空则将正在思考设置为 True、思考折叠面板展开状态设置为展开 # 若上一分片种类为空则将正在思考设置为正在思考
if not previous_part_kind: if not previous_part_kind:
dialog.is_thinking = True dialog.is_thinking = True
dialog.is_expanded = True
dialog.thoughts[index] = Thought( dialog.thoughts[index] = Thought(
type="thinking", content=content type="thinking", content=content
) )
@ -350,10 +349,9 @@ class ConversationState(rx.State):
match part: match part:
# 思考分片结束事件 # 思考分片结束事件
case ThinkingPart(content=content): case ThinkingPart(content=content):
# 若下一分片种类为文本则将思考状态设置为思考完成、思考面板展开状态设置为折叠 # 若下一分片种类为文本则将思考状态设置为思考完成
if next_part_kind == "text": if next_part_kind == "text":
dialog.is_thinking = False dialog.is_thinking = False
dialog.is_expanded = False
# ========== 函数工具调用事件 ========== # ========== 函数工具调用事件 ==========
case FunctionToolCallEvent(tool_call_id=tool_call_id, part=part): case FunctionToolCallEvent(tool_call_id=tool_call_id, part=part):

View File

@ -5,6 +5,7 @@
--prismui-background-color-4: #babbc0; --prismui-background-color-4: #babbc0;
--prismui-background-color-5: #ffffff33; --prismui-background-color-5: #ffffff33;
--prismui-background-color-6: #f2f2f3; --prismui-background-color-6: #f2f2f3;
--prismui-background-color-7: #5e7ce0;
--prismui-background-1: linear-gradient(to bottom, #D0C9FF 0%, #E6D6F0 8%, #F1DBEA 12%, #C8DCFB 40%, #ABC6F6 60%, #87AEFE 90%); --prismui-background-1: linear-gradient(to bottom, #D0C9FF 0%, #E6D6F0 8%, #F1DBEA 12%, #C8DCFB 40%, #ABC6F6 60%, #87AEFE 90%);
--prismui-background-2: linear-gradient(180deg, #fffffff2, #f8fafff2 99%); --prismui-background-2: linear-gradient(180deg, #fffffff2, #f8fafff2 99%);
--prismui-background-3: linear-gradient(to right, #f3efff, #f3efff33, #e2f1fd33, #e2f1fd); --prismui-background-3: linear-gradient(to right, #f3efff, #f3efff33, #e2f1fd33, #e2f1fd);
@ -12,7 +13,8 @@
--prismui-font-size-1: 12px; --prismui-font-size-1: 12px;
--prismui-font-size-2: 14px; --prismui-font-size-2: 14px;
--prismui-font-size-3: 16px; --prismui-font-size-3: 16px;
--prismui-font-size-4: 20px; --prismui-font-size-4: 18px;
--prismui-font-size-5: 20px;
--prismui-font-weight-1: normal; --prismui-font-weight-1: normal;
--prismui-font-weight-2: 500; --prismui-font-weight-2: 500;
--prismui-font-weight-3: 700; --prismui-font-weight-3: 700;
@ -47,3 +49,14 @@
--prismui-box-shadow-9: 0 1px 8px 0 #1919190f; --prismui-box-shadow-9: 0 1px 8px 0 #1919190f;
background-color: var(--prismui-background-color-1); background-color: var(--prismui-background-color-1);
} }
pre {
padding: 16px !important;
margin: 12px 0 !important;
background-color: var(--prismui-background-color-1) !important;
border-radius: var(--prismui-border-radius-1) !important;
}
pre, pre code {
font-family: Consolas, "Microsoft YaHei", sans-serif !important;
}

Binary file not shown.

31
agent/test.py Normal file
View File

@ -0,0 +1,31 @@
import asyncio
from pathlib import Path
from pydantic_ai import Embedder
from pydantic_ai.embeddings.sentence_transformers import (
SentenceTransformerEmbeddingModel,
SentenceTransformersEmbeddingSettings
)
async def main():
# 自动定位:脚本目录/models/模型文件夹
base_path = Path(__file__).parent
model_path = str(base_path / "models" / "paraphrase-multilingual-MiniLM-L12-v2")
model = SentenceTransformerEmbeddingModel(
model_path,
settings=SentenceTransformersEmbeddingSettings(
sentence_transformers_device="cpu",
sentence_transformers_normalize_embeddings=True,
)
)
embedder = Embedder(model)
query_text = "刘弼仁"
counts = await embedder.count_tokens(query_text)
print(counts)
max_tokens = await embedder.max_input_tokens()
print(f'Max tokens: {max_tokens}')
res = await embedder.embed_query(query_text)
print(f"向量维度:{len(res.embeddings[0])}")
asyncio.run(main())