feat: 更新依赖项,添加新的配置字段,优化智能体管理和视图组件
This commit is contained in:
parent
24e3937aa2
commit
44b6dfdbc0
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
### python gitignore
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.venv
|
||||
.ruff_cache
|
||||
|
||||
### Vue gitignore
|
||||
dist
|
||||
|
||||
@ -5,6 +5,7 @@ description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
"arxiv>=2.2.0",
|
||||
"asyncpg>=0.30.0",
|
||||
"chromadb>=1.0.15",
|
||||
"colorlog>=6.9.0",
|
||||
@ -14,6 +15,7 @@ dependencies = [
|
||||
"langchain-community>=0.3.22",
|
||||
"langchain-deepseek>=0.1.3",
|
||||
"langchain-huggingface>=0.2.0",
|
||||
"langchain-mcp-adapters>=0.1.9",
|
||||
"langchain-openai>=0.3.14",
|
||||
"langchain-tavily>=0.2.3",
|
||||
"langchain-together>=0.3.0",
|
||||
@ -24,6 +26,7 @@ dependencies = [
|
||||
"lightrag-hku>=1.3.9",
|
||||
"llama-index>=0.12.33",
|
||||
"llama-index-readers-file>=0.4.7",
|
||||
"mcp>=1.12.0",
|
||||
"mineru>=2.0.6",
|
||||
"neo4j>=5.28.1",
|
||||
"networkx>=3.5",
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
from src.agents.chatbot import ChatbotAgent
|
||||
from src.agents.react import ReActAgent
|
||||
|
||||
from .chatbot import ChatbotAgent
|
||||
from .react import ReActAgent
|
||||
|
||||
class AgentManager:
|
||||
def __init__(self):
|
||||
@ -32,7 +33,7 @@ class AgentManager:
|
||||
|
||||
agent_manager = AgentManager()
|
||||
agent_manager.register_agent(ChatbotAgent)
|
||||
agent_manager.register_agent(ReActAgent) # 暂时屏蔽 ReActAgent
|
||||
agent_manager.register_agent(ReActAgent)
|
||||
agent_manager.init_all_agents()
|
||||
|
||||
__all__ = ["agent_manager"]
|
||||
|
||||
@ -13,13 +13,13 @@ class ChatbotConfiguration(Configuration):
|
||||
|
||||
metadata 中 configurable 为 True 的配置项可以被用户配置,
|
||||
configurable 为 False 的配置项不能被用户配置,只能由开发者预设。
|
||||
除非显示配置为 False,否则所有配置项都默认可配置。
|
||||
"""
|
||||
|
||||
system_prompt: str = field(
|
||||
default="You are a helpful assistant.",
|
||||
metadata={
|
||||
"name": "系统提示词",
|
||||
"configurable": True,
|
||||
"description": "用来描述智能体的角色和行为"
|
||||
},
|
||||
)
|
||||
@ -28,7 +28,6 @@ class ChatbotConfiguration(Configuration):
|
||||
default="zhipu/glm-4-plus",
|
||||
metadata={
|
||||
"name": "智能体模型",
|
||||
"configurable": True,
|
||||
"options": [],
|
||||
"description": "智能体的驱动模型"
|
||||
},
|
||||
@ -38,7 +37,6 @@ class ChatbotConfiguration(Configuration):
|
||||
default_factory=list,
|
||||
metadata={
|
||||
"name": "工具",
|
||||
"configurable": True,
|
||||
"options": list(get_all_tools().keys()), # 这里的选择是所有的工具
|
||||
"description": "工具列表"
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@ import os
|
||||
import yaml
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from typing import Annotated, TypedDict
|
||||
from typing import Annotated, TypedDict, Optional, Any
|
||||
from abc import abstractmethod
|
||||
from dataclasses import dataclass, fields, field
|
||||
|
||||
@ -30,6 +30,24 @@ class Configuration(dict):
|
||||
3. 类默认配置:最低优先级,类中定义的默认值
|
||||
"""
|
||||
|
||||
thread_id: str = field(
|
||||
default_factory=lambda: str(uuid.uuid4()),
|
||||
metadata={
|
||||
"name": "线程ID",
|
||||
"configurable": False,
|
||||
"description": "用来描述智能体的角色和行为"
|
||||
},
|
||||
)
|
||||
|
||||
user_id: str = field(
|
||||
default_factory=lambda: str(uuid.uuid4()),
|
||||
metadata={
|
||||
"name": "用户ID",
|
||||
"configurable": False,
|
||||
"description": "用来描述智能体的角色和行为"
|
||||
},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_runnable_config(
|
||||
cls, config: RunnableConfig | None = None, agent_name: str | None = None
|
||||
@ -127,7 +145,7 @@ class Configuration(dict):
|
||||
else:
|
||||
confs[f.name] = value
|
||||
|
||||
if f.metadata.get("configurable"):
|
||||
if f.metadata.get("configurable", True):
|
||||
configurable_items[f.name] = {
|
||||
"type": f.type.__name__,
|
||||
"name": f.metadata.get("name", f.name),
|
||||
@ -139,23 +157,6 @@ class Configuration(dict):
|
||||
return confs
|
||||
|
||||
|
||||
thread_id: str = field(
|
||||
default_factory=lambda: str(uuid.uuid4()),
|
||||
metadata={
|
||||
"name": "线程ID",
|
||||
"configurable": False,
|
||||
"description": "用来描述智能体的角色和行为"
|
||||
},
|
||||
)
|
||||
|
||||
user_id: str = field(
|
||||
default_factory=lambda: str(uuid.uuid4()),
|
||||
metadata={
|
||||
"name": "用户ID",
|
||||
"configurable": False,
|
||||
"description": "用来描述智能体的角色和行为"
|
||||
},
|
||||
)
|
||||
|
||||
class BaseAgent:
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
<a-select
|
||||
v-model:value="selectedAgentId"
|
||||
class="agent-list"
|
||||
style="width: 200px"
|
||||
style="width: 300px"
|
||||
@change="selectAgent"
|
||||
>
|
||||
<a-select-option
|
||||
@ -20,8 +20,11 @@
|
||||
:value="name"
|
||||
>
|
||||
<div class="agent-option">
|
||||
智能体:{{ agent.name }}
|
||||
<StarFilled v-if="name === defaultAgentId" class="default-icon" />
|
||||
<div class="agent-option-content">
|
||||
<p class="agent-option-name">{{ agent.name }} <StarFilled v-if="name === defaultAgentId" class="default-icon" /></p>
|
||||
<p class="agent-option-description">{{ agent.description }}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
@ -59,7 +62,7 @@
|
||||
<a-modal
|
||||
v-model:open="state.agentConfOpen"
|
||||
title="智能体详细配置"
|
||||
:width="600"
|
||||
:width="800"
|
||||
:footer="null"
|
||||
:maskClosable="false"
|
||||
class="conf-modal"
|
||||
@ -117,13 +120,16 @@
|
||||
v-else-if="typeof agentConfig[key] === 'boolean'"
|
||||
v-model:checked="agentConfig[key]"
|
||||
/>
|
||||
<!-- 单选 -->
|
||||
<a-select
|
||||
v-else-if="value?.options && value?.type === 'str'"
|
||||
v-else-if="value?.options && (value?.type === 'str' || value?.type === 'select')"
|
||||
v-model:value="agentConfig[key]"
|
||||
>
|
||||
<a-select-option v-for="option in value.options" :key="option" :value="option"></a-select-option>
|
||||
<a-select-option v-for="option in value.options" :key="option" :value="option">
|
||||
{{ option.label || option }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
<!-- 多选标签卡片 -->
|
||||
<!-- 多选 -->
|
||||
<div v-else-if="value?.options && value?.type === 'list'" class="multi-select-cards">
|
||||
<div class="multi-select-label">
|
||||
<span>已选择 {{ getSelectedCount(key) }} 项</span>
|
||||
@ -152,6 +158,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 数字 -->
|
||||
<a-input-number
|
||||
v-else-if="value?.type === 'number'"
|
||||
v-model:value="agentConfig[key]"
|
||||
:placeholder="getPlaceholder(key, value)"
|
||||
/>
|
||||
<!-- 滑块 -->
|
||||
<a-slider
|
||||
v-else-if="value?.type === 'slider'"
|
||||
v-model:value="agentConfig[key]"
|
||||
:min="value.min"
|
||||
:max="value.max"
|
||||
:step="value.step"
|
||||
style="max-width: 300px;"
|
||||
/>
|
||||
<!-- 其他类型 -->
|
||||
<a-input
|
||||
v-else
|
||||
v-model:value="agentConfig[key]"
|
||||
@ -228,7 +250,18 @@ const state = reactive({
|
||||
|
||||
const selectedAgent = computed(() => agents.value[selectedAgentId.value] || {});
|
||||
const configSchema = computed(() => selectedAgent.value.config_schema || {});
|
||||
const configurableItems = computed(() => configSchema.value.configurable_items || {});
|
||||
const configurableItems = computed(() => {
|
||||
const items = configSchema.value.configurable_items || {};
|
||||
// 遍历所有的配置项,将所有的 x_oap_ui_config 的层级提升到上一层
|
||||
Object.keys(items).forEach(key => {
|
||||
const item = items[key];
|
||||
if (item.x_oap_ui_config) {
|
||||
items[key] = { ...item, ...item.x_oap_ui_config };
|
||||
delete items[key].x_oap_ui_config;
|
||||
}
|
||||
});
|
||||
return items;
|
||||
});
|
||||
|
||||
// 配置状态
|
||||
const agentConfig = ref({});
|
||||
@ -467,7 +500,7 @@ onMounted(async () => {
|
||||
// 获取配置标签
|
||||
const getConfigLabel = (key, value) => {
|
||||
// 根据配置项属性选择合适的显示文本
|
||||
if (value.description) {
|
||||
if (value.description && value.name !== key) {
|
||||
return `${value.name}(${key})`;
|
||||
}
|
||||
return key;
|
||||
@ -655,11 +688,28 @@ const toggleConf = () => {
|
||||
.agent-option {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
.agent-option-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.agent-option-description {
|
||||
font-size: 12px;
|
||||
color: var(--gray-700);
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.default-icon {
|
||||
color: #faad14;
|
||||
font-size: 14px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,6 +802,7 @@ const toggleConf = () => {
|
||||
max-height: 60vh;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
@ -787,4 +838,14 @@ const toggleConf = () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 针对 Ant Design Select 组件的深度样式修复
|
||||
:deep(.ant-select-item-option-content) {
|
||||
.agent-option-name {
|
||||
color: var(--main-color);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user