mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-27 22:07:48 +00:00
136 lines
3.8 KiB
Plaintext
136 lines
3.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"id": "6de2e0bb",
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2024-04-10T04:37:21.832993Z",
|
|
"start_time": "2024-04-10T04:37:21.828221Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"import os\n",
|
|
"import nest_asyncio\n",
|
|
"from dbgpt.agent import (\n",
|
|
" AgentContext,\n",
|
|
" AgentResource,\n",
|
|
" GptsMemory,\n",
|
|
" LLMConfig,\n",
|
|
" ResourceLoader,\n",
|
|
" ResourceType,\n",
|
|
" UserProxyAgent,\n",
|
|
")\n",
|
|
"from dbgpt.agent.expand.plugin_assistant_agent import PluginAssistantAgent\n",
|
|
"from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent\n",
|
|
"from dbgpt.agent.plan import WrappedAWELLayoutManager\n",
|
|
"from dbgpt.agent.resource import PluginFileLoadClient\n",
|
|
"from dbgpt.configs.model_config import ROOT_PATH\n",
|
|
"from dbgpt.model.proxy import OpenAILLMClient\n",
|
|
"\n",
|
|
"nest_asyncio.apply()\n",
|
|
"test_plugin_dir = os.path.join(ROOT_PATH, \"examples/test_files/plugins\")"
|
|
],
|
|
"execution_count": 11,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"id": "437b9c40",
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2024-04-10T04:37:27.592117Z",
|
|
"start_time": "2024-04-10T04:37:23.569538Z"
|
|
}
|
|
},
|
|
"source": [
|
|
"# os.environ['OPENAI_API_KEY']=\"sk-x\"\n",
|
|
"# os.environ['OPENAI_API_BASE']=\"https://proxy_url/v1\"\n",
|
|
"# os.environ['SEARCH_ENGINE']=\"baidu\"\n",
|
|
"# os.environ['BAIDU_COOKIE']=\"\"\"your baidu cookie\"\"\"\n",
|
|
"\n",
|
|
"llm_client = OpenAILLMClient(model_alias=\"gpt-3.5-turbo\")\n",
|
|
"context: AgentContext = AgentContext(conv_id=\"test456\", gpts_app_name=\"信息析助手\")\n",
|
|
"\n",
|
|
"default_memory = GptsMemory()\n",
|
|
"\n",
|
|
"resource_loader = ResourceLoader()\n",
|
|
"plugin_file_loader = PluginFileLoadClient()\n",
|
|
"resource_loader.register_resource_api(plugin_file_loader)\n",
|
|
"\n",
|
|
"plugin_resource = AgentResource(\n",
|
|
" type=ResourceType.Plugin,\n",
|
|
" name=\"test\",\n",
|
|
" value=test_plugin_dir,\n",
|
|
")\n",
|
|
"\n",
|
|
"tool_engineer = (\n",
|
|
" await PluginAssistantAgent()\n",
|
|
" .bind(context)\n",
|
|
" .bind(LLMConfig(llm_client=llm_client))\n",
|
|
" .bind(default_memory)\n",
|
|
" .bind([plugin_resource])\n",
|
|
" .bind(resource_loader)\n",
|
|
" .build()\n",
|
|
")\n",
|
|
"summarizer = (\n",
|
|
" await SummaryAssistantAgent()\n",
|
|
" .bind(context)\n",
|
|
" .bind(default_memory)\n",
|
|
" .bind(LLMConfig(llm_client=llm_client))\n",
|
|
" .build()\n",
|
|
")\n",
|
|
"\n",
|
|
"manager = (\n",
|
|
" await WrappedAWELLayoutManager()\n",
|
|
" .bind(context)\n",
|
|
" .bind(default_memory)\n",
|
|
" .bind(LLMConfig(llm_client=llm_client))\n",
|
|
" .build()\n",
|
|
")\n",
|
|
"manager.hire([tool_engineer, summarizer])\n",
|
|
"\n",
|
|
"user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()\n",
|
|
"\n",
|
|
"await user_proxy.initiate_chat(\n",
|
|
" recipient=manager,\n",
|
|
" reviewer=user_proxy,\n",
|
|
" message=\"查询成都今天天气\",\n",
|
|
" # message=\"查询今天的最新热点财经新闻\",\n",
|
|
")"
|
|
],
|
|
"execution_count": 12,
|
|
"outputs": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7ded4107",
|
|
"metadata": {},
|
|
"source": [],
|
|
"outputs": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.13"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|