Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taskweaver #306

Closed
fywang2 opened this issue Apr 16, 2024 · 3 comments
Closed

taskweaver #306

fywang2 opened this issue Apr 16, 2024 · 3 comments

Comments

@fywang2
Copy link

fywang2 commented Apr 16, 2024

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:

  • name: query
    type: str
    required: true
    description: >-
    直接把query传入数据库处理,不需要数据库名称、查询条件。

returns:

  • name: df
    type: pandas.DataFrame
    description: This is the dataframe containing the data from the database.从数据库返回的产业工人项目结果数据。
  • name: description
    type: str
    description: This is a string describing the data pulled from the database.对从数据库返回的产业工人项目数据的描述。

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
Copy link
Contributor

liqul commented Apr 17, 2024

close due to duplicate

@liqul liqul closed this as completed Apr 17, 2024
@marcindulak
Copy link

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

@liqul
Copy link
Contributor

liqul commented Apr 17, 2024

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

#307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants