diff --git a/.gitignore b/.gitignore index a6cab14..b1a60d4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__/ **/__pycache__/ .DS_Store .gitignore +agent/models/ \ No newline at end of file diff --git a/agent/application/pages/conversation.py b/agent/application/pages/conversation.py index ef8d58f..9d073f0 100644 --- a/agent/application/pages/conversation.py +++ b/agent/application/pages/conversation.py @@ -142,7 +142,7 @@ def conversation_history_item_showing( min_width="14px", cursor="pointer", 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"), ), display="flex", @@ -221,7 +221,7 @@ def conversation_history_items_showing( min_width=rx.cond(is_conversation_history_shown, "240px", "0px"), max_width=rx.cond(is_conversation_history_shown, "380px", "0px"), height="100%", - transition="all 0.3s ease-in-out", + transition="all 0.18s ease-in-out", overflow="hidden", ) @@ -346,8 +346,8 @@ def thought_showing(item: Tuple[int, Thought]): "thinking", rx.text( thought.content, - line_height="22px", - font_size="var(--prismui-font-size-2)", + line_height="1.6", + font_size="var(--prismui-font-size-1)", color="var(--prismui-color-3)", ), ), @@ -416,35 +416,32 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: ), # 思考折叠面板 rx.vstack( - # 标题栏 + # 标题 rx.box( rx.hstack( rx.text( rx.cond(is_thinking, "思考中", "思考完成"), + font_size="var(--prismui-font-size-1)", color="var(--prismui-color-3)", - font_size="var(--prismui-font-size-2)", ), rx.icon( "chevron-right", width="14px", height="14px", color="var(--prismui-color-3)", - style={ - "transform": rx.cond( - is_expanded, "rotate(90deg)", "rotate(0deg)" - ), - "transition": "transform 0.2s ease-out", - }, + transform=rx.cond(is_expanded, "rotate(90deg)", "rotate(0deg)"), + transition="transform 0.18s ease-in-out", ), align_items="center", gap="4px", margin_bottom="8px", line_height="22px", ), - cursor="pointer", # 点击事件,展开/折叠思考折叠面板 on_click=lambda: ConversationState.toggle_collapse(dialog.id), + cursor="pointer", ), + # 思考 rx.box( rx.box( rx.auto_scroll( @@ -458,15 +455,13 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: ), style={"overflow": "hidden", "min-height": "0"}, ), + display="grid", + grid_template_rows=rx.cond(is_expanded, "1fr", "0fr"), width="100%", - style={ - "display": "grid", - "overflow": "hidden", - "grid_template_rows": rx.cond(is_expanded, "1fr", "0fr"), - "opacity": rx.cond(is_expanded, "1", "0"), - # 双属性同步过渡,和千问一致 - "transition": "grid-template-rows 0.3s ease-out, opacity 0.3s ease-out", - }, + margin_bottom="8px", + opacity=rx.cond(is_expanded, "1", "0"), + overflow="hidden", + transition="grid-template-rows 0.18s ease-in-out, opacity 0.18s ease-in-out", ), ), # 结果输出 @@ -481,11 +476,23 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: word_break="break-all", 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( text, margin="8px 0 4px", line_height="1.75", - font_size="18px", + font_size="var(--prismui-font-size-4)", font_weight="var(--prismui-font-weight-3)", word_wrap="break-word", word_break="break-all", @@ -495,7 +502,7 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: text, margin="6px 0 4px", line_height="1.75", - font_size="16px", + font_size="var(--prismui-font-size-3)", font_weight="var(--prismui-font-weight-3)", word_wrap="break-word", word_break="break-all", @@ -510,11 +517,6 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: word_break="break-all", white_space="pre-line", ), - "strong": lambda text: rx.text( - text, - display="inline", - font_weight="var(--prismui-font-weight-3)", - ), "ul": lambda children: rx.vstack( children, align_items="flex-start", @@ -532,8 +534,8 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: width="4.5px", height="4.5px", margin_right="8px", - background_color="var(--prismui-color-5)", - border_radius="50%", + background_color="var(--prismui-background-color-7)", + border_radius="100%", ), rx.text( text, @@ -553,31 +555,25 @@ def dialog_showing(item: Tuple[str, Dialog]) -> rx.Component: ), "table": lambda children: rx.el.table( children, - style={ - "margin": "12px 0", - "width": "100%", - "border-collapse": "collapse", - }, + width="100%", + margin="8px 0", + border_collapse="collapse", ), "thead": lambda children: rx.el.thead(children), "tbody": lambda children: rx.el.tbody(children), "tr": lambda children: rx.el.tr(children), - "th": lambda text: rx.el.th( - text, - style={ - "padding": "10px 12px", - "background": "var(--prismui-background-color-3)", - "border": "1px solid var(--prismui-background-color-6)", - "text-align": "left", - }, + "th": lambda children: rx.el.th( + children, + padding="8px 12px", + background_color="var(--prismui-background-color-6)", + border="1px solid var(--prismui-background-color-2)", + text_align="left", ), - "td": lambda text: rx.el.td( - text, - style={ - "padding": "10px 12px", - "border": "1px solid var(--prismui-background-color-6)", - "vertical-align": "top", - }, + "td": lambda children: rx.el.td( + children, + padding="8px 12px", + border="1px solid var(--prismui-background-color-2)", + text_align="left", ), }, width="100%", @@ -860,7 +856,7 @@ def conversation_history_collapse_button( "0 var(--prismui-border-radius-2)", ), box_shadow="var(--prismui-box-shadow-4)", - transition="all 0.3s ease-in-out", + transition="all 0.18s ease-in-out", cursor="pointer", ) @@ -901,7 +897,7 @@ def conversation() -> rx.Component: height="100%", min_height="0", overflow="hidden", - transition="all 0.3s ease-in-out", + transition="all 0.18s ease-in-out", ), # 会话历史折叠面板按钮 conversation_history_collapse_button(is_conversation_history_shown), diff --git a/agent/application/pages/index.py b/agent/application/pages/index.py index 9703301..633f191 100644 --- a/agent/application/pages/index.py +++ b/agent/application/pages/index.py @@ -224,7 +224,7 @@ def login_popup() -> rx.Component: "登录解锁更多功能", margin_bottom="24px", line_height="32px", - font_size="var(--prismui-font-size-4)", + font_size="var(--prismui-font-size-5)", font_weight="var(--prismui-font-weight-3)", ), # 邮箱输入框 diff --git a/agent/application/states/conversation.py b/agent/application/states/conversation.py index ae40dc3..fe6c8ed 100644 --- a/agent/application/states/conversation.py +++ b/agent/application/states/conversation.py @@ -286,10 +286,9 @@ class ConversationState(rx.State): match part: # 思考分片开始事件 case ThinkingPart(content=content): - # 若上一分片种类为空则将正在思考设置为 True、思考折叠面板展开状态设置为展开 + # 若上一分片种类为空则将正在思考设置为正在思考 if not previous_part_kind: dialog.is_thinking = True - dialog.is_expanded = True dialog.thoughts[index] = Thought( type="thinking", content=content ) @@ -350,10 +349,9 @@ class ConversationState(rx.State): match part: # 思考分片结束事件 case ThinkingPart(content=content): - # 若下一分片种类为文本则将思考状态设置为思考完成、思考面板展开状态设置为折叠 + # 若下一分片种类为文本则将思考状态设置为思考完成 if next_part_kind == "text": dialog.is_thinking = False - dialog.is_expanded = False # ========== 函数工具调用事件 ========== case FunctionToolCallEvent(tool_call_id=tool_call_id, part=part): diff --git a/agent/assets/styles.css b/agent/assets/styles.css index ca7d6e8..2d45ce1 100644 --- a/agent/assets/styles.css +++ b/agent/assets/styles.css @@ -5,6 +5,7 @@ --prismui-background-color-4: #babbc0; --prismui-background-color-5: #ffffff33; --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-2: linear-gradient(180deg, #fffffff2, #f8fafff2 99%); --prismui-background-3: linear-gradient(to right, #f3efff, #f3efff33, #e2f1fd33, #e2f1fd); @@ -12,7 +13,8 @@ --prismui-font-size-1: 12px; --prismui-font-size-2: 14px; --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-2: 500; --prismui-font-weight-3: 700; @@ -46,4 +48,15 @@ --prismui-box-shadow-8:0 1px 8px #1919190f; --prismui-box-shadow-9: 0 1px 8px 0 #1919190f; 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; } \ No newline at end of file diff --git a/agent/database.db b/agent/database.db index aeb3431..b4433d4 100644 Binary files a/agent/database.db and b/agent/database.db differ diff --git a/agent/test.py b/agent/test.py new file mode 100644 index 0000000..0a275fa --- /dev/null +++ b/agent/test.py @@ -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()) \ No newline at end of file