microsoft / TaskWeaver

A code-first agent framework for seamlessly planning and executing data analytics tasks.
https://microsoft.github.io/TaskWeaver/
MIT License
5.37k stars 690 forks source link

taskweaver #306

Closed fywang2 closed 7 months ago

fywang2 commented 7 months ago

1、Docker host operating system:ubuntun 22.04 desktop

2、Run TaskWeaver using the All-in-One Docker Image: sudo docker run -it \ --name taskweaver \ --privileged \ --net=host \ -e "LLM_API_KEY=sk-0f67XXXX" \ -e "LLM_API_TYPE=qwen" \ -e "LLM_MODEL=qwen-max" \ -e "TASKWEAVER_UID=0" \ -e "TASKWEAVER_GID=0" \ -p 8000:8000 \ -v /data/workspace/vscode/vscodeProjects/taskWeaverFromContaner/project:/app/project \ --entrypoint /app/entrypoint_chainlit.sh \ taskweavercontainers/taskweaver-all-in-one:latest

3、plugin file: sql_pull_mysql_data.py import pandas as pd

from taskweaver.plugin import Plugin, register_plugin

import pymysql

@register_plugin class SqlPullMysqlData(Plugin):

class SqlPullMysqlData():

def __call__(self, query: str):
    query = "查询产业工人项目列表"
    #sql = "select * from opi_project"
    sql = "select id as 编码,project_name as 项目名称,area as 项目所在地区, eng_status as 项目状态 from opi_project"
    result = query_data(sql)
    print(result)

    df = pd.DataFrame(result)
    print(df)

    if len(df) == 0:
        return df, (
            f"我在 `{query}` 基础上生成SQL.\n所生成SQL语句为 {sql}.\n" f"返回结果为空的."
        )
    else:
        return df, (
            f"我在 `{query}`基础上生成SQL.\n所生成SQL语句为 {sql}.\n"
            f"返回结果有 {len(df)} 行.\n"
            f"返回结果的前 {min(5, len(df))} 行记录:\n{df.head(min(5, len(df))).to_markdown()}"
        )

""" 常用模块:读写MySQL """ def get_conn(): omit some codes

def query_data(sql): omit some codes

4、plugin file: sql_pull_mysql_data.yaml name: sql_pull_mysql_data code: sql_pull_mysql_data enabled: true required: true description: >- 获取产业工人项目数据。 当向用户的答复涉及本插件时,请以中文答复。 不需要把用户输入的自然语言转换为数据库SQL。 以Markdown表格形式展示给用户。 (omit some descriptions)

examples: |- df, description = sql_pull_mysql_data("从数据库查询产业工人项目列表")

parameters:

returns:

5、Installing pymysql in the Docker container docker exec -it taskweaver /bin/bash pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip config list pip install pymysql

6、When asking “显示产业工人项目”,Taskweaver execute the plugin sql_pull_mysql_data, then the backend execption logs: 2024-04-16 15:08:06 - LLM output: {"response": [{"type": "init_plan", "content": "1. 使用sql_pull_mysql_data插件获取产业工人项目数据"}, {"type": "plan", "content": "1. 使用sql_pull_mysql_data插件获取产业工人项目数据"}, {"type": "current_plan_step", "content": "1. 使用sql_pull_mysql_data插件获取产业工人项目数据"}, {"type": "send_to", "content": "sql_pull_mysql_data"}, {"type": "message", "content": "请使用插件功能获取产业工人项目数据"}], "execute_code": true} 2024-04-16 15:08:06 - Planner talk to sql_pull_mysql_data: 请使用插件功能获取产业工人项目数据 2024-04-16 15:08:06 - Traceback (most recent call last): File "/app/playground/UI/../../taskweaver/session/session.py", line 194, in _send_text_message post = _send_message(post.send_to, post) File "/app/playground/UI/../../taskweaver/module/tracing.py", line 174, in wrapper return func(*args, **kwargs) File "/app/playground/UI/../../taskweaver/session/session.py", line 182, in _send_message raise Exception(f"Unknown recipient {recipient}") Exception: Unknown recipient sql_pull_mysql_data

image

liqul commented 7 months ago

close due to duplicate

marcindulak commented 7 months ago

@liqul - which issue is the duplicate? When closing as duplicate please provide the other issue.

liqul commented 7 months ago

@liqul - which issue is the duplicate? When closing as duplicate please provide the other issue.

https://github.com/microsoft/TaskWeaver/issues/307