mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-09 21:08:59 +00:00
Native data AI application framework based on AWEL+AGENT (#1152)
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: lcx01800250 <lcx01800250@alibaba-inc.com> Co-authored-by: licunxing <864255598@qq.com> Co-authored-by: Aralhi <xiaoping0501@gmail.com> Co-authored-by: xuyuan23 <643854343@qq.com> Co-authored-by: aries_ckt <916701291@qq.com> Co-authored-by: hzh97 <2976151305@qq.com>
This commit is contained in:
@@ -20,41 +20,59 @@ import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.agents.llm.llm import LLMConfig
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.agent.resource.resource_api import AgentResource, ResourceType
|
||||
from dbgpt.agent.resource.resource_loader import ResourceLoader
|
||||
from dbgpt.agent.resource.resource_plugin_api import PluginFileLoadClient
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
from dbgpt.serve.agent.team.plan.team_auto_plan import AutoPlanChatManager
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
# context.llm_models = [ModelMetadata(model="gpt-4-vision-preview")]
|
||||
context.gpts_name = "代码分析助手"
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(
|
||||
conv_id="test456", team_mode=Team, gpts_app_name="代码分析助手"
|
||||
)
|
||||
|
||||
default_memory = GptsMemory()
|
||||
coder = CodeAssistantAgent(memory=default_memory, agent_context=context)
|
||||
## TODO add other agent
|
||||
|
||||
manager = AutoPlanChatManager(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
resource_loader = ResourceLoader()
|
||||
|
||||
coder = (
|
||||
await CodeAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(resource_loader)
|
||||
.build()
|
||||
)
|
||||
|
||||
manager = (
|
||||
await AutoPlanChatManager()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
manager.hire([coder])
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="Obtain simple information about issues in the repository 'eosphoros-ai/DB-GPT' in the past three days and analyze the data. Create a Markdown table grouped by day and status.",
|
||||
# message="Find papers on gpt-4 in the past three weeks on arxiv, and organize their titles, authors, and links into a markdown table",
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="Obtain simple information about issues in the repository 'eosphoros-ai/DB-GPT' in the past three days and analyze the data. Create a Markdown table grouped by day and status.",
|
||||
# message="Find papers on gpt-4 in the past three weeks on arxiv, and organize their titles, authors, and links into a markdown table",
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
|
||||
print(await default_memory.one_chat_competions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
||||
asyncio.run(main())
|
||||
|
@@ -20,54 +20,78 @@ import os
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.agents.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
from dbgpt.agent.agents.llm.llm import LLMConfig
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.agent.resource.resource_api import AgentResource, ResourceType
|
||||
from dbgpt.agent.resource.resource_loader import ResourceLoader
|
||||
from dbgpt.agent.resource.resource_plugin_api import PluginFileLoadClient
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
from dbgpt.serve.agent.team.layout.team_awel_layout import AwelLayoutChatManger
|
||||
from dbgpt.serve.agent.team.layout.team_awel_layout import AwelLayoutChatManager
|
||||
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
test_plugin_dir = os.path.join(parent_dir, "test_files")
|
||||
test_plugin_dir = os.path.join(parent_dir, "test_files/plugins")
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
context.gpts_name = "信息析助手"
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456", gpts_app_name="信息析助手")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
manager = AwelLayoutChatManger(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
|
||||
resource_loader = ResourceLoader()
|
||||
plugin_file_loader = PluginFileLoadClient()
|
||||
resource_loader.register_resesource_api(plugin_file_loader)
|
||||
|
||||
plugin_resource = AgentResource(
|
||||
type=ResourceType.Plugin,
|
||||
name="test",
|
||||
value=test_plugin_dir,
|
||||
)
|
||||
|
||||
### agents
|
||||
tool_enginer = PluginAssistantAgent(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
plugin_path=test_plugin_dir,
|
||||
tool_enginer = (
|
||||
await PluginAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind([plugin_resource])
|
||||
.bind(resource_loader)
|
||||
.build()
|
||||
)
|
||||
summarizer = SummaryAssistantAgent(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
summarizer = (
|
||||
await SummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
|
||||
manager = (
|
||||
await AwelLayoutChatManager()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
manager.hire([tool_enginer, summarizer])
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="查询成都今天天气",
|
||||
# message="查询今天的最新热点财经新闻",
|
||||
# message="Find papers on gpt-4 in the past three weeks on arxiv, and organize their titles, authors, and links into a markdown table",
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="查询成都今天天气",
|
||||
# message="查询今天的最新热点财经新闻",
|
||||
# message="Find papers on gpt-4 in the past three weeks on arxiv, and organize their titles, authors, and links into a markdown table",
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
|
||||
print(await default_memory.one_chat_competions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
||||
asyncio.run(main())
|
||||
|
@@ -17,35 +17,61 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from dbgpt.agent.actions.plugin_action import PluginAction
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.agents.llm.llm import LLMConfig
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.agent.resource.resource_api import AgentResource, ResourceType
|
||||
from dbgpt.agent.resource.resource_loader import ResourceLoader
|
||||
from dbgpt.agent.resource.resource_plugin_api import PluginFileLoadClient
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
test_plugin_dir = os.path.join(parent_dir, "test_files/plugins")
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
|
||||
default_memory = GptsMemory()
|
||||
tool_enginer = PluginAssistantAgent(
|
||||
memory=default_memory,
|
||||
agent_context=context,
|
||||
plugin_path="/Users/tuyang.yhj/Code/python/DB-GPT/plugins",
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456")
|
||||
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
plugin_resource = AgentResource(
|
||||
type=ResourceType.Plugin,
|
||||
name="test",
|
||||
value=test_plugin_dir,
|
||||
)
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
resource_loader = ResourceLoader()
|
||||
plugin_file_loader = PluginFileLoadClient()
|
||||
resource_loader.register_resesource_api(plugin_file_loader)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=tool_enginer,
|
||||
reviewer=user_proxy,
|
||||
message="查询今天成都的天气",
|
||||
)
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
tool_enginer = (
|
||||
await PluginAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind([plugin_resource])
|
||||
.bind(resource_loader)
|
||||
.build()
|
||||
)
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=tool_enginer,
|
||||
reviewer=user_proxy,
|
||||
message="查询今天成都的天气",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
||||
print(await default_memory.one_chat_competions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
@@ -19,30 +19,37 @@ import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.agents.llm.llm import LLMConfig
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
default_memory = GptsMemory()
|
||||
coder = CodeAssistantAgent(memory=default_memory, agent_context=context)
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test123")
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=coder,
|
||||
reviewer=user_proxy,
|
||||
message="式计算下321 * 123等于多少", # 用python代码的方式计算下321 * 123等于多少
|
||||
# message="download data from https://raw.githubusercontent.com/uwdata/draco/master/data/cars.csv and plot a visualization that tells us about the relationship between weight and horsepower. Save the plot to a file. Print the fields in a dataset before visualizing it.",
|
||||
)
|
||||
coder = (
|
||||
await CodeAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=coder,
|
||||
reviewer=user_proxy,
|
||||
message="式计算下321 * 123等于多少", # 用python代码的方式计算下321 * 123等于多少
|
||||
# message="download data from https://raw.githubusercontent.com/uwdata/draco/master/data/cars.csv and plot a visualization that tells us about the relationship between weight and horsepower. Save the plot to a file. Print the fields in a dataset before visualizing it.",
|
||||
)
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
||||
print(await default_memory.one_chat_competions("test123"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
@@ -19,28 +19,33 @@ import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
from dbgpt.agent.agents.llm.llm import LLMConfig
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
|
||||
|
||||
def summary_example_with_success():
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
async def summary_example_with_success():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="summarize", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="summarize")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
summarizer = SummaryAssistantAgent(memory=default_memory, agent_context=context)
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
summarizer = (
|
||||
await SummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power according to the following content.
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power according to the following content.
|
||||
|
||||
Nuclear power in space is the use of nuclear power in outer space, typically either small fission systems or radioactive decay for electricity or heat. Another use is for scientific observation, as in a Mössbauer spectrometer. The most common type is a radioisotope thermoelectric generator, which has been used on many space probes and on crewed lunar missions. Small fission reactors for Earth observation satellites, such as the TOPAZ nuclear reactor, have also been flown.[1] A radioisotope heater unit is powered by radioactive decay and can keep components from becoming too cold to function, potentially over a span of decades.[2]
|
||||
|
||||
@@ -68,31 +73,36 @@ def summary_example_with_success():
|
||||
Nuclear pulse propulsion
|
||||
Nuclear electric rocket
|
||||
""",
|
||||
)
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("summarize")))
|
||||
print(await default_memory.one_chat_competions("summarize"))
|
||||
|
||||
|
||||
def summary_example_with_faliure():
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
async def summary_example_with_faliure():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="summarize", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="summarize")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
summarizer = SummaryAssistantAgent(memory=default_memory, agent_context=context)
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
summarizer = (
|
||||
await SummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
# Test the failure example
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power according to the following content.
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power according to the following content.
|
||||
|
||||
Taylor Swift is an American singer-songwriter and actress who is one of the most prominent and successful figures in the music industry. She was born on December 13, 1989, in Reading, Pennsylvania, USA. Taylor Swift gained widespread recognition for her narrative songwriting style, which often draws from her personal experiences and relationships.
|
||||
|
||||
@@ -104,17 +114,16 @@ def summary_example_with_faliure():
|
||||
|
||||
Taylor Swift is not only a successful artist but also an influential cultural icon known for her evolving musical style, storytelling abilities, and her impact on the entertainment industry.
|
||||
""",
|
||||
)
|
||||
)
|
||||
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("summarize")))
|
||||
print(await default_memory.one_chat_competions("summarize"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(
|
||||
"\033[92m=======================Start The Summary Assistant with Successful Results==================\033[0m"
|
||||
)
|
||||
summary_example_with_success()
|
||||
asyncio.run(summary_example_with_success())
|
||||
print(
|
||||
"\033[92m=======================The Summary Assistant with Successful Results Ended==================\n\n\033[91m"
|
||||
)
|
||||
@@ -122,7 +131,7 @@ if __name__ == "__main__":
|
||||
print(
|
||||
"\033[91m=======================Start The Summary Assistant with Fail Results==================\033[91m"
|
||||
)
|
||||
summary_example_with_faliure()
|
||||
asyncio.run(summary_example_with_faliure())
|
||||
print(
|
||||
"\033[91m=======================The Summary Assistant with Fail Results Ended==================\033[91m"
|
||||
)
|
||||
|
75
examples/agents/sql_agent_dialogue_example.py
Normal file
75
examples/agents/sql_agent_dialogue_example.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Agents: single agents about CodeAssistantAgent?
|
||||
|
||||
Examples:
|
||||
|
||||
Execute the following command in the terminal:
|
||||
Set env params.
|
||||
.. code-block:: shell
|
||||
|
||||
export OPENAI_API_KEY=sk-xx
|
||||
export OPENAI_API_BASE=https://xx:80/v1
|
||||
|
||||
run example.
|
||||
..code-block:: shell
|
||||
python examples/agents/single_agent_dialogue_example.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.data_scientist_agent import DataScientistAgent
|
||||
from dbgpt.agent.agents.llm.llm import LLMConfig
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.agent.resource.resource_api import AgentResource, ResourceType
|
||||
from dbgpt.agent.resource.resource_db_api import SqliteLoadClient
|
||||
from dbgpt.agent.resource.resource_loader import ResourceLoader
|
||||
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
test_plugin_dir = os.path.join(parent_dir, "test_files")
|
||||
|
||||
|
||||
async def main():
|
||||
from dbgpt.model.proxy.llms.chatgpt import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456")
|
||||
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
db_resource = AgentResource(
|
||||
type=ResourceType.DB,
|
||||
name="TestData",
|
||||
value=f"{test_plugin_dir}/dbgpt.db",
|
||||
)
|
||||
|
||||
resource_loader = ResourceLoader()
|
||||
sqlite_file_loader = SqliteLoadClient()
|
||||
resource_loader.register_resesource_api(sqlite_file_loader)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
sql_boy = (
|
||||
await DataScientistAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind([db_resource])
|
||||
.bind(resource_loader)
|
||||
.build()
|
||||
)
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=sql_boy,
|
||||
reviewer=user_proxy,
|
||||
message="当前库有那些表",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_competions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
@@ -354,6 +354,8 @@ with DAG("dbgpt_awel_data_analyst_assistant") as dag:
|
||||
lambda req: ModelRequestContext(
|
||||
conv_uid=req.context.conv_uid,
|
||||
stream=req.stream,
|
||||
user_name=req.context.user_name,
|
||||
sys_code=req.context.sys_code,
|
||||
chat_mode=req.context.chat_mode,
|
||||
)
|
||||
)
|
||||
|
BIN
examples/test_files/dbgpt.db
Normal file
BIN
examples/test_files/dbgpt.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user