mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-09 04:49:26 +00:00
feat(agent): Release agent SDK (#1396)
This commit is contained in:
@@ -16,27 +16,23 @@
|
||||
|
||||
|
||||
import asyncio
|
||||
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
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
UserProxyAgent,
|
||||
)
|
||||
from dbgpt.agent.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.plan import AutoPlanChatManager
|
||||
|
||||
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(
|
||||
conv_id="test456", team_mode=Team, gpts_app_name="代码分析助手"
|
||||
)
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-4")
|
||||
context: AgentContext = AgentContext(conv_id="test456", gpts_app_name="代码分析助手")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
|
||||
@@ -62,7 +58,7 @@ async def main():
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
await user_proxy.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.",
|
||||
@@ -70,7 +66,7 @@ async def main():
|
||||
# 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"))
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -11,31 +11,32 @@
|
||||
|
||||
run example.
|
||||
..code-block:: shell
|
||||
python examples/agents/auto_plan_agent_dialogue_example.py
|
||||
python examples/agents/awel_layout_agents_chat_examples.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
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 AwelLayoutChatManager
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentResource,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
ResourceType,
|
||||
UserProxyAgent,
|
||||
)
|
||||
from dbgpt.agent.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
from dbgpt.agent.plan import WrappedAWELLayoutManager
|
||||
from dbgpt.agent.resource import PluginFileLoadClient
|
||||
from dbgpt.configs.model_config import ROOT_PATH
|
||||
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
test_plugin_dir = os.path.join(parent_dir, "test_files/plugins")
|
||||
test_plugin_dir = os.path.join(ROOT_PATH, "examples/test_files/plugins")
|
||||
|
||||
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456", gpts_app_name="信息析助手")
|
||||
@@ -44,7 +45,7 @@ async def main():
|
||||
|
||||
resource_loader = ResourceLoader()
|
||||
plugin_file_loader = PluginFileLoadClient()
|
||||
resource_loader.register_resesource_api(plugin_file_loader)
|
||||
resource_loader.register_resource_api(plugin_file_loader)
|
||||
|
||||
plugin_resource = AgentResource(
|
||||
type=ResourceType.Plugin,
|
||||
@@ -52,7 +53,7 @@ async def main():
|
||||
value=test_plugin_dir,
|
||||
)
|
||||
|
||||
tool_enginer = (
|
||||
tool_engineer = (
|
||||
await PluginAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
@@ -70,17 +71,17 @@ async def main():
|
||||
)
|
||||
|
||||
manager = (
|
||||
await AwelLayoutChatManager()
|
||||
await WrappedAWELLayoutManager()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
manager.hire([tool_enginer, summarizer])
|
||||
manager.hire([tool_engineer, summarizer])
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="查询成都今天天气",
|
||||
@@ -89,7 +90,7 @@ async def main():
|
||||
# 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"))
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -11,22 +11,23 @@
|
||||
|
||||
run example.
|
||||
..code-block:: shell
|
||||
python examples/agents/single_agent_dialogue_example.py
|
||||
python examples/agents/plugin_agent_dialogue_example.py
|
||||
"""
|
||||
|
||||
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
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentResource,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
ResourceType,
|
||||
UserProxyAgent,
|
||||
)
|
||||
from dbgpt.agent.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.resource import PluginFileLoadClient
|
||||
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
@@ -34,7 +35,7 @@ test_plugin_dir = os.path.join(parent_dir, "test_files/plugins")
|
||||
|
||||
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456")
|
||||
@@ -49,11 +50,11 @@ async def main():
|
||||
|
||||
resource_loader = ResourceLoader()
|
||||
plugin_file_loader = PluginFileLoadClient()
|
||||
resource_loader.register_resesource_api(plugin_file_loader)
|
||||
resource_loader.register_resource_api(plugin_file_loader)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
tool_enginer = (
|
||||
tool_engineer = (
|
||||
await PluginAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
@@ -63,14 +64,14 @@ async def main():
|
||||
.build()
|
||||
)
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
recipient=tool_enginer,
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=tool_engineer,
|
||||
reviewer=user_proxy,
|
||||
message="查询今天成都的天气",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_competions("test456"))
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -17,50 +17,50 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.retrieve_summary_assistant_agent import (
|
||||
from dbgpt.agent import AgentContext, GptsMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent.expand.retrieve_summary_assistant_agent import (
|
||||
RetrieveSummaryAssistantAgent,
|
||||
)
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
from dbgpt.configs.model_config import ROOT_PATH
|
||||
|
||||
|
||||
def summary_example_with_success():
|
||||
async def summary_example_with_success():
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(
|
||||
conv_id="retrieve_summarize", llm_provider=llm_client
|
||||
)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo-16k")]
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo-16k")
|
||||
context: AgentContext = AgentContext(conv_id="retrieve_summarize")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
summarizer = RetrieveSummaryAssistantAgent(
|
||||
memory=default_memory, agent_context=context
|
||||
summarizer = (
|
||||
await RetrieveSummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power.
|
||||
You can refer the following file pathes and URLs: ['/home/ubuntu/DB-GPT/examples/Nuclear_power.pdf', 'https://en.wikipedia.org/wiki/Modern_Family', '/home/ubuntu/DB-GPT/examples/Taylor_Swift.pdf', 'https://en.wikipedia.org/wiki/Chernobyl_disaster']
|
||||
""",
|
||||
)
|
||||
paths_urls = [
|
||||
os.path.join(ROOT_PATH, "examples/agents/example_files/Nuclear_power.pdf"),
|
||||
os.path.join(ROOT_PATH, "examples/agents/example_files/Taylor_Swift.pdf"),
|
||||
"https://en.wikipedia.org/wiki/Modern_Family",
|
||||
"https://en.wikipedia.org/wiki/Chernobyl_disaster",
|
||||
]
|
||||
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message=f"I want to summarize advantages of Nuclear Power. You can refer the "
|
||||
f"following file paths and URLs: {paths_urls}",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("retrieve_summarize")))
|
||||
# dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_completions("retrieve_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"
|
||||
)
|
||||
|
@@ -15,17 +15,13 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
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 import AgentContext, GptsMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent.expand.code_assistant_agent import CodeAssistantAgent
|
||||
|
||||
|
||||
async def main():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test123")
|
||||
@@ -41,14 +37,14 @@ async def main():
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
await user_proxy.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(await default_memory.one_chat_competions("test123"))
|
||||
print(await default_memory.one_chat_completions("test123"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -15,17 +15,13 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
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.agent import AgentContext, GptsMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
|
||||
|
||||
async def summary_example_with_success():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="summarize")
|
||||
@@ -42,7 +38,7 @@ async def summary_example_with_success():
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power according to the following content.
|
||||
@@ -76,11 +72,11 @@ async def summary_example_with_success():
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_competions("summarize"))
|
||||
print(await default_memory.one_chat_completions("summarize"))
|
||||
|
||||
|
||||
async def summary_example_with_faliure():
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="summarize")
|
||||
@@ -99,7 +95,7 @@ async def summary_example_with_faliure():
|
||||
|
||||
# Test the failure example
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=summarizer,
|
||||
reviewer=user_proxy,
|
||||
message="""I want to summarize advantages of Nuclear Power according to the following content.
|
||||
@@ -116,7 +112,7 @@ async def summary_example_with_faliure():
|
||||
""",
|
||||
)
|
||||
|
||||
print(await default_memory.one_chat_competions("summarize"))
|
||||
print(await default_memory.one_chat_completions("summarize"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -17,14 +17,17 @@
|
||||
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
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentResource,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
ResourceType,
|
||||
UserProxyAgent,
|
||||
)
|
||||
from dbgpt.agent.expand.data_scientist_agent import DataScientistAgent
|
||||
from dbgpt.agent.resource import SqliteLoadClient
|
||||
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
@@ -47,7 +50,7 @@ async def main():
|
||||
|
||||
resource_loader = ResourceLoader()
|
||||
sqlite_file_loader = SqliteLoadClient()
|
||||
resource_loader.register_resesource_api(sqlite_file_loader)
|
||||
resource_loader.register_resource_api(sqlite_file_loader)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
|
||||
@@ -61,14 +64,14 @@ async def main():
|
||||
.build()
|
||||
)
|
||||
|
||||
await user_proxy.a_initiate_chat(
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=sql_boy,
|
||||
reviewer=user_proxy,
|
||||
message="当前库有那些表",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_competions("test456"))
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user