LCA-LLM/DataAnalysis/debug.py

45 lines
1.6 KiB
Python
Raw Permalink Normal View History

2024-07-30 10:11:41 +08:00
import os
import re
import gradio as gr
from PIL import Image
from pprint import pprint
from qwen_agent.agents import Assistant
import sys
os.chdir(sys.path[0])
# os.environ['TMPDIR'] = "/home/zhangxj/WorkFile/LCA-GPT/LCARAG/DataAnalysis/tmp"
llm_cfg = {
'model': 'qwen1.5-72b-chat',
'model_server': 'dashscope',
'api_key': "sk-c5f441f863f44094b0ddb96c831b5002",
}
system_instruction = '''你是一位专注在生命周期领域做数据分析的助手,在数据分析之后,
如果有可视化要求请使用 `plt.show()` 显示图像,并将图像进行保存
最后请对数据分析结果结合生命周期评价领域知识进行解释'''
tools = ['code_interpreter'] # `code_interpreter` is a built-in tool for executing code.
messages = [] # This stores the chat history.
files = ["/home/zhangxj/WorkFile/LCA-GPT/DataAnalysis/tmp/2021beijing.csv"]
bot = Assistant(llm=llm_cfg,
system_message=system_instruction,
function_list=tools,
files=files
)
# print("user input>")
user_input = '''2021beijing.csv给出了2021年北京不同行业的碳排放量数据首先分析数据的每一行和每一列代表的含义
绘制不同排放行业的碳排放量占比的饼图要求美观字体清晰给出可视化结果和结果分析'''
messages.append({'role': 'user', 'content': user_input})
# Get response from bot
response = []
for response in bot.run(messages=messages):
continue
pprint(response)
messages.extend(response)