添加智能体页面
This commit is contained in:
parent
dbf5000ac7
commit
6b0ccf8d17
@ -1,6 +1,6 @@
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from langchain_core.tools import Tool
|
||||
from langchain_core.tools import tool
|
||||
from langchain_openai import ChatOpenAI
|
||||
|
||||
from src import config
|
||||
@ -10,12 +10,17 @@ from src.agents.registry import Configuration
|
||||
def get_default_requirements():
|
||||
return ["TAVILY_API_KEY"]
|
||||
|
||||
@tool
|
||||
def multiply(first_int: int, second_int: int) -> int:
|
||||
"""Multiply two integers together."""
|
||||
return first_int * second_int
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class ChatbotConfiguration(Configuration):
|
||||
requirements: list[str] = field(default_factory=get_default_requirements)
|
||||
llm: ChatOpenAI | None = None
|
||||
model_provider: str = "siliconflow"
|
||||
model_name: str = "Qwen/Qwen2.5-72B-Instruct"
|
||||
model_provider: str = "zhipu"
|
||||
model_name: str = "glm-4-plus"
|
||||
|
||||
def __post_init__(self):
|
||||
# TODO 需要确保这里的模型是支持 tools 的
|
||||
|
||||
@ -9,7 +9,7 @@ from langgraph.prebuilt import ToolNode, tools_condition
|
||||
from langgraph.checkpoint.memory import MemorySaver
|
||||
|
||||
from src.agents.registry import State, BaseAgent
|
||||
from src.agents.chatbot.configuration import ChatbotConfiguration
|
||||
from src.agents.chatbot.configuration import ChatbotConfiguration, multiply
|
||||
|
||||
class ChatbotAgent(BaseAgent):
|
||||
name = "chatbot"
|
||||
@ -23,7 +23,7 @@ class ChatbotAgent(BaseAgent):
|
||||
|
||||
def _get_tools(self, config: RunnableConfig):
|
||||
"""根据配置获取工具"""
|
||||
tools = []
|
||||
tools = [multiply]
|
||||
if not config:
|
||||
return tools
|
||||
|
||||
|
||||
@ -84,8 +84,7 @@ def chat_post(
|
||||
|
||||
logger.debug(f"Final response: {content}")
|
||||
logger.debug(f"Final reasoning response: {reasoning_content}")
|
||||
yield make_chunk(content=content,
|
||||
status="finished",
|
||||
yield make_chunk(status="finished",
|
||||
history=history_manager.update_ai(content),
|
||||
refs=refs)
|
||||
except Exception as e:
|
||||
@ -164,7 +163,7 @@ def chat_agent(agent_name: str,
|
||||
content = ""
|
||||
yield make_chunk(status="waiting")
|
||||
for msg, metadata in agent.stream_messages(messages, runnable_config):
|
||||
# logger.debug(f"msg: {msg.model_dump()}, {metadata=}")
|
||||
logger.debug(f">>>>> msg: {msg.model_dump()}, >>>>>>> {metadata=}")
|
||||
if isinstance(msg, AIMessageChunk) and msg.content != "<tool_call>":
|
||||
content += msg.content
|
||||
yield make_chunk(content=msg.content,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
@import './base.css';
|
||||
@import './markdown.css';
|
||||
|
||||
:root {
|
||||
--header-height: 60px;
|
||||
|
||||
53
web/src/assets/markdown.css
Normal file
53
web/src/assets/markdown.css
Normal file
@ -0,0 +1,53 @@
|
||||
.message-md {
|
||||
color: var(--gray-900);
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.message-md pre {
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
border: 1px solid var(--main-light-3);
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.message-md pre:has(code.hljs) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.message-md pre code.hljs {
|
||||
font-size: 0.8rem;
|
||||
background-color: var(--gray-100);
|
||||
}
|
||||
|
||||
.message-md strong {
|
||||
color: var(--gray-800);
|
||||
}
|
||||
|
||||
.message-md h1,
|
||||
.message-md h2,
|
||||
.message-md h3,
|
||||
.message-md h4,
|
||||
.message-md h5,
|
||||
.message-md h6 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.message-md li > p,
|
||||
.message-md ol > p,
|
||||
.message-md ul > p {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
|
||||
.message-md ol,
|
||||
.message-md ul {
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.message-md hr {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.message-md a {
|
||||
color: var(--main-800);
|
||||
margin: auto 2px;
|
||||
}
|
||||
@ -1137,55 +1137,3 @@ watch(
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
.message-md {
|
||||
color: var(--gray-900);
|
||||
max-width: 100%;
|
||||
|
||||
pre {
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
border: 1px solid var(--main-light-3);
|
||||
padding: 1rem;
|
||||
|
||||
&:has(code.hljs) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
font-size: 0.8rem;
|
||||
background-color: var(--gray-100);
|
||||
}
|
||||
}
|
||||
|
||||
strong {
|
||||
color: var(--gray-800);
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
li, ol, ul {
|
||||
& > p {
|
||||
margin: 0.25rem 0;
|
||||
}
|
||||
}
|
||||
|
||||
ol, ul {
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
hr {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--main-800);
|
||||
margin: auto 2px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user