{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2024-09-05T11:18:05.926025Z", "start_time": "2024-09-05T11:18:00.554798Z" } }, "outputs": [], "source": [ "import os\n", "from pprint import pprint\n", "from typing import Optional\n", "\n", "from qwen_agent.agents import ReActChat\n", "from qwen_agent.gui import WebUI\n", "\n", "# ROOT_RESOURCE = os.path.join(os.path.dirname(__file__), 'resource')\n", "ROOT_RESOURCE=\"resource\"" ] }, { "cell_type": "code", "outputs": [], "source": [ "def init_agent_service():\n", " llm_cfg = {\n", " 'model': 'qwen2-instruct',\n", " 'model_server': 'http://lq.lianqiai.cn:20335/v1',\n", " 'api_key': \"\",\n", " # 'model': 'qwen-max',\n", " # 'model_server': 'dashscope',\n", " # 'api_key': os.getenv('DASHSCOPE_API_KEY'),\n", " }\n", " tools = ['code_interpreter']\n", " bot = ReActChat(llm=llm_cfg,\n", " name='code interpreter',\n", " description='This agent can run code to solve the problem',\n", " function_list=tools)\n", " return bot" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-09-05T11:18:05.934621Z", "start_time": "2024-09-05T11:18:05.927991Z" } }, "id": "a32402553c8cda24", "execution_count": 2 }, { "cell_type": "code", "outputs": [], "source": [ "def app_gui():\n", " bot = init_agent_service()\n", " chatbot_config = {\n", " 'prompt.suggestions': [{\n", " 'text': 'pd.head the file first and then help me draw a line chart to show the changes in stock prices',\n", " 'files': [os.path.join(ROOT_RESOURCE, 'stock_prices.csv')]\n", " }, 'Draw a line graph y=x^2']\n", " }\n", " WebUI(bot, chatbot_config=chatbot_config).run()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-09-05T11:18:14.068675Z", "start_time": "2024-09-05T11:18:14.063472Z" } }, "id": "cab30016b457d1e1", "execution_count": 4 }, { "cell_type": "code", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/plain": "", "text/html": "
" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "app_gui()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-09-05T11:18:16.773442Z", "start_time": "2024-09-05T11:18:14.664160Z" } }, "id": "c465f06cef966638", "execution_count": 5 }, { "cell_type": "code", "outputs": [], "source": [], "metadata": { "collapsed": false }, "id": "19e8d4153229f5a9" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 5 }