From ff6747cb1f1750202abfb78deeac934284b55867 Mon Sep 17 00:00:00 2001 From: yhjun1026 <460342015@qq.com> Date: Wed, 23 Apr 2025 20:34:57 +0800 Subject: [PATCH] feat(agent):Thinking content External vis processing --- configs/dev.toml | 96 ------------------- .../src/dbgpt/agent/core/base_agent.py | 16 +--- .../src/dbgpt/agent/util/llm/llm_client.py | 2 +- .../dbgpt-core/src/dbgpt/vis/vis_converter.py | 6 +- .../dbgpt_serve/agent/agents/controller.py | 6 +- .../src/dbgpt_serve/agent/db/gpts_app.py | 17 ++-- 6 files changed, 19 insertions(+), 124 deletions(-) delete mode 100644 configs/dev.toml diff --git a/configs/dev.toml b/configs/dev.toml deleted file mode 100644 index 4e1cbd469..000000000 --- a/configs/dev.toml +++ /dev/null @@ -1,96 +0,0 @@ -[system] -# Load language from environment variable(It is set by the hook) -language = "${env:DBGPT_LANG:-zh}" -log_level = "INFO" -api_keys = [] -encrypt_key = "your_secret_key" - -# Server Configurations -[service.web] -host = "127.0.0.1" -port = 5670 - -[service.web.database] -type = "sqlite" -path = "pilot/meta_data/dbgpt.db" -#[service.web.database] -# type = "mysql" -# host = "127.0.0.1" -# port = 3306 -# user = "root" -# database = "dbgpt" -# password = "aa12345678" - -[service.model.worker] -host = "127.0.0.1" - -[rag] -chunk_size=1000 -chunk_overlap=0 -similarity_top_k=5 -similarity_score_threshold=0.0 -max_chunks_once_load=10 -max_threads=1 -rerank_top_k=3 -graph_community_summary_enabled="True" -enable_summary=true - - -[rag.storage] -[rag.storage.vector] -type = "Chroma" -persist_path = "pilot/data" - -#type = "ElasticSearch" -#uri = "127.0.0.1" -#port = "19530" -#username="dbgpt" -#password=19530 -[rag.storage.graph] -type = "TuGraph" -host="127.0.0.1" -port=7687 -username="admin" -password="73@TuGraph" -enable_summary=true -enable_similarity_search=false - -[rag.storage.full_text] -type = "ElasticSearch" -host="127.0.0.1" -port=9200 - - - - -#GRAPH_COMMUNITY_SUMMARY_ENABLED=True # enable the graph community summary -#TRIPLET_GRAPH_ENABLED=True # enable the graph search for the triplets -#DOCUMENT_GRAPH_ENABLED=True # enable the graph search for documents and chunks -#KNOWLEDGE_GRAPH_EXTRACTION_BATCH_SIZE=20 # the batch size of triplet extraction from the text -#COMMUNITY_SUMMARY_BATCH_SIZE=20 # the batch size of parallel community summary process - - - - -# Model Configurations -[models] -[[models.llms]] -#name = "deepseek-chat" -#provider = "proxy/deepseek" -#provider = "proxy/vol-deepseek" -#api_key = "${env:DEEPSEEK_API_KEY}" -#name = "${env:LLM_MODEL_NAME:-deepseek-chat}" -#provider = "${env:LLM_MODEL_PROVIDER:-proxy/deepseek}" -#api_url = "https://zdfmng.alipay.com/chat/completions" -#api_key = "sk-adf80a1b814cf1193422fabcd34ccc0a" -#api_key = "sk-04bec639baf54da7b743016e8536a459" - -name = "Qwen2.5-72B-Instruct" -provider = "proxy/gitee" -api_key = "W7LRHBLWM0XMW0AGLDRKEITZNZCSUUHAVFOYWO1C" - -[[models.embeddings]] -name = "bge-large-zh-v1.5" -provider = "proxy/openai" -api_url = "https://ai.gitee.com/v1/embeddings" -api_key = "W7LRHBLWM0XMW0AGLDRKEITZNZCSUUHAVFOYWO1C" \ No newline at end of file diff --git a/packages/dbgpt-core/src/dbgpt/agent/core/base_agent.py b/packages/dbgpt-core/src/dbgpt/agent/core/base_agent.py index 7a6665e3e..a7f862cdb 100644 --- a/packages/dbgpt-core/src/dbgpt/agent/core/base_agent.py +++ b/packages/dbgpt-core/src/dbgpt/agent/core/base_agent.py @@ -611,17 +611,11 @@ class ConversableAgent(Role, Agent): "content": res_content, "avatar": self.avatar, } - if not self.not_null_agent_context.output_process_message: - if self.is_final_role: - await self.memory.gpts_memory.push_message( - self.not_null_agent_context.conv_id, - stream_msg=temp_message, - ) - else: - await self.memory.gpts_memory.push_message( - self.not_null_agent_context.conv_id, - stream_msg=temp_message, - ) + + await self.memory.gpts_memory.push_message( + self.not_null_agent_context.conv_id, + stream_msg=temp_message, + ) return res_thinking, res_content, llm_model except LLMChatError as e: diff --git a/packages/dbgpt-core/src/dbgpt/agent/util/llm/llm_client.py b/packages/dbgpt-core/src/dbgpt/agent/util/llm/llm_client.py index 190129468..b2e02eddb 100644 --- a/packages/dbgpt-core/src/dbgpt/agent/util/llm/llm_client.py +++ b/packages/dbgpt-core/src/dbgpt/agent/util/llm/llm_client.py @@ -158,7 +158,7 @@ class AIWrapper: model_request.copy() ): # type: ignore model_output = output - parsed_output = model_output.text_and_thinking() + parsed_output = model_output.gen_text_and_thinking() think_blank = not parsed_output[0] or len(parsed_output[0]) <= 0 content_blank = not parsed_output[1] or len(parsed_output[1]) <= 0 diff --git a/packages/dbgpt-core/src/dbgpt/vis/vis_converter.py b/packages/dbgpt-core/src/dbgpt/vis/vis_converter.py index e6ec240a2..3ba4d102f 100644 --- a/packages/dbgpt-core/src/dbgpt/vis/vis_converter.py +++ b/packages/dbgpt-core/src/dbgpt/vis/vis_converter.py @@ -171,7 +171,7 @@ class DefaultVisConverter(VisProtocolConverter): } ) if stream_msg: - simple_message_list.append(self._view_stream_message(stream_msg)) + simple_message_list.append(await self._view_stream_message(stream_msg)) return simple_message_list @@ -181,7 +181,7 @@ class DefaultVisConverter(VisProtocolConverter): messages_view.append( { "sender": message["sender"], - "receiver": message["receiver"], + "receiver": message.get("receiver"), "model": message["model"], "markdown": message["markdown"], } @@ -193,4 +193,4 @@ class DefaultVisConverter(VisProtocolConverter): self, stream_msg: Optional[Union[Dict, str]] = None, ): - return self._view_stream_message(stream_msg) + return await self._view_stream_message(stream_msg) diff --git a/packages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py b/packages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py index 634d85a3f..050fbb634 100644 --- a/packages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py +++ b/packages/dbgpt-serve/src/dbgpt_serve/agent/agents/controller.py @@ -142,7 +142,7 @@ class MultiAgents(BaseComponent, ABC): ).create() storage_manager = StorageManager.get_instance(self.system_app) - index_name = "_agent_memory_" + index_name = "agent_memory" vector_store = storage_manager.create_vector_store(index_name=index_name) if not vector_store.vector_name_exists(): vector_store.create_collection(collection_name=index_name) @@ -312,7 +312,9 @@ class MultiAgents(BaseComponent, ABC): vis_protocal = None # if enable_verbose: ## Defaul use gpt_vis ui component‘s package - # vis_protocal = GptVisConverter() + from dbgpt_ext.vis.gpt_vis.gpt_vis_converter_v2 import GptVisConverterNew + + vis_protocal = GptVisConverterNew() self.memory.init( agent_conv_id, diff --git a/packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.py b/packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.py index 3a330247c..5afbd0182 100644 --- a/packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.py +++ b/packages/dbgpt-serve/src/dbgpt_serve/agent/db/gpts_app.py @@ -368,6 +368,7 @@ class GptsAppDetailEntity(Model): app_name = Column(String(255), nullable=False, comment="Current AI assistant name") type = Column( String(255), + default="agent", nullable=False, comment="bind detail agent type. 'app' or 'agent', default 'agent'", ) @@ -804,7 +805,7 @@ class GptsAppDao(BaseDao): else: return app_info - async def auto_team_bin_apps(self, team_app_code: str, bind_apps: List[str]): + async def app_bind_apps(self, team_app_code: str, bind_apps: List[str]): """Convert the gpts app to a sub-agent of the current application.""" logger.info(f"auto_team_bin_apps:{team_app_code},{bind_apps}") team_app: GptsApp = self.app_detail(team_app_code) @@ -827,19 +828,13 @@ class GptsAppDao(BaseDao): for gpt_app in gpt_apps: ## 暂时线只支持绑定单agent应用,多Agent应用绑定要把多Agent的子Agent资源提到绑定的TL Agent上,可能需要产品测来定义 #noqa if gpt_app.team_mode == TeamMode.SINGLE_AGENT.value: - new_detail: GptsAppDetail = gpt_app.details[0].copy() + new_detail: GptsAppDetail = GptsAppDetail() new_detail.app_name = team_app.app_name new_detail.app_code = team_app.app_code - strategy_values = json.loads(gpt_app.details[0].llm_strategy_value) - # 恢复模拟前端的数据 - new_detail.llm_strategy_value = ",".join(strategy_values) - new_detail.agent_describe = gpt_app.app_describe - new_detail.agent_role = ( - new_detail.agent_role - if new_detail.agent_role - else new_detail.agent_name - ) + new_detail.type = "app" new_detail.agent_name = gpt_app.app_name + new_detail.agent_role = gpt_app.app_code + new_detail.agent_describe = gpt_app.app_describe team_app.details.append(new_detail) self.edit(team_app)