mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-16 14:40:56 +00:00
WEB API independent
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
from pilot.configs.config import Config
|
||||
import pandas as pd
|
||||
from sqlalchemy import create_engine, pool
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from matplotlib.font_manager import FontProperties
|
||||
from pyecharts.charts import Bar
|
||||
from pyecharts import options as opts
|
||||
from test_cls_1 import TestBase, Test1
|
||||
from test_cls_2 import Test2
|
||||
|
||||
CFG = Config()
|
||||
|
||||
#
|
||||
# if __name__ == "__main__":
|
||||
# # 创建连接池
|
||||
# engine = create_engine('mysql+pymysql://root:aa123456@localhost:3306/gpt-user')
|
||||
#
|
||||
# # 从连接池中获取连接
|
||||
#
|
||||
#
|
||||
# # 归还连接到连接池中
|
||||
#
|
||||
# # 执行SQL语句并将结果转化为DataFrame
|
||||
# query = "SELECT * FROM users"
|
||||
# df = pd.read_sql(query, engine.connect())
|
||||
# df.style.set_properties(subset=['name'], **{'font-weight': 'bold'})
|
||||
# # 导出为HTML文件
|
||||
# with open('report.html', 'w') as f:
|
||||
# f.write(df.style.render())
|
||||
#
|
||||
# # # 设置中文字体
|
||||
# # font = FontProperties(fname='SimHei.ttf', size=14)
|
||||
# #
|
||||
# # colors = np.random.rand(df.shape[0])
|
||||
# # df.plot.scatter(x='city', y='user_name', c=colors)
|
||||
# # plt.show()
|
||||
#
|
||||
# # 查看DataFrame
|
||||
# print(df.head())
|
||||
#
|
||||
#
|
||||
# # 创建数据
|
||||
# x_data = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
|
||||
# y_data = [820, 932, 901, 934, 1290, 1330, 1320]
|
||||
#
|
||||
# # 生成图表
|
||||
# bar = (
|
||||
# Bar()
|
||||
# .add_xaxis(x_data)
|
||||
# .add_yaxis("销售额", y_data)
|
||||
# .set_global_opts(title_opts=opts.TitleOpts(title="销售额统计"))
|
||||
# )
|
||||
#
|
||||
# # 生成HTML文件
|
||||
# bar.render('report.html')
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
|
||||
# def __extract_json(s):
|
||||
# i = s.index("{")
|
||||
# count = 1 # 当前所在嵌套深度,即还没闭合的'{'个数
|
||||
# for j, c in enumerate(s[i + 1 :], start=i + 1):
|
||||
# if c == "}":
|
||||
# count -= 1
|
||||
# elif c == "{":
|
||||
# count += 1
|
||||
# if count == 0:
|
||||
# break
|
||||
# assert count == 0 # 检查是否找到最后一个'}'
|
||||
# return s[i : j + 1]
|
||||
#
|
||||
# ss = """here's a sql statement that can be used to generate a histogram to analyze the distribution of user orders in different cities:select u.city, count(*) as order_countfrom tran_order oleft join user u on o.user_id = u.idgroup by u.city;this will return the number of orders for each city that has at least one order. we can use this data to generate a histogram that shows the distribution of orders across different cities.here's the response in the required format:{ "thoughts": "here's a sql statement that can be used to generate a histogram to analyze the distribution of user orders in different cities:\n\nselect u.city, count(*) as order_count\nfrom tran_order o\nleft join user u on o.user_id = u.id\ngroup by u.city;", "speak": "here's a sql statement that can be used to generate a histogram to analyze the distribution of user orders in different cities.", "command": { "name": "histogram-executor", "args": { "title": "distribution of user orders in different cities", "sql": "select u.city, count(*) as order_count\nfrom tran_order o\nleft join user u on o.user_id = u.id\ngroup by u.city;" } }}"""
|
||||
# print(__extract_json(ss))
|
||||
|
||||
if __name__ == "__main__":
|
||||
# test1 = Test1()
|
||||
# test2 = Test2()
|
||||
# test1.write()
|
||||
# test1.test()
|
||||
# test2.write()
|
||||
# test1.test()
|
||||
# test2.test()
|
||||
|
||||
# 定义包含元组的列表
|
||||
data = [('key1', 'value1'), ('key2', 'value2'), ('key3', 'value3')]
|
||||
|
||||
# 使用字典解析将列表转换为字典
|
||||
result = {k: v for k, v in data}
|
||||
|
||||
print(result)
|
@@ -1,20 +0,0 @@
|
||||
import json
|
||||
from pilot.common.sql_database import Database
|
||||
from pilot.configs.config import Config
|
||||
|
||||
CFG = Config()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# connect = CFG.local_db.get_session("gpt-user")
|
||||
# datas = CFG.local_db.run(connect, "SELECT * FROM users; ")
|
||||
|
||||
# print(datas)
|
||||
|
||||
# str = """{ "thoughts": "thought text", "sql": "SELECT COUNT(DISTINCT user_id) FROM transactions_order WHERE user_id IN (SELECT DISTINCT user_id FROM users WHERE country='China') AND create_time BETWEEN 20230101 AND 20230131" ,}"""
|
||||
#
|
||||
# print(str.find("["))
|
||||
|
||||
test =["t1", "t2", "t3", "tx"]
|
||||
print(str(test[1:]))
|
||||
|
||||
|
@@ -1,16 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
import duckdb
|
||||
|
||||
default_db_path = os.path.join(os.getcwd(), "message")
|
||||
duckdb_path = os.getenv("DB_DUCKDB_PATH", default_db_path + "/chat_history.db")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if os.path.isfile("../../../message/chat_history.db"):
|
||||
cursor = duckdb.connect("../../../message/chat_history.db").cursor()
|
||||
# cursor.execute("SELECT * FROM chat_history limit 20")
|
||||
cursor.execute(
|
||||
"SELECT * FROM chat_history where conv_uid ='b54ae5fe-1624-11ee-a271-b26789cc3e58'"
|
||||
)
|
||||
data = cursor.fetchall()
|
||||
print(data)
|
@@ -1,44 +0,0 @@
|
||||
from enum import Enum
|
||||
from typing import List
|
||||
|
||||
class Test(Enum):
|
||||
XXX = ("x", "1", True)
|
||||
YYY =("Y", "2", False)
|
||||
ZZZ = ("Z", "3")
|
||||
def __init__(self, code, v, flag= False):
|
||||
self.code = code
|
||||
self.v = v
|
||||
self.flag = flag
|
||||
|
||||
class Scene:
|
||||
def __init__(self, code, name, describe, param_types:List=[], is_inner: bool = False):
|
||||
self.code = code
|
||||
self.name = name
|
||||
self.describe = describe
|
||||
self.param_types = param_types
|
||||
self.is_inner = is_inner
|
||||
|
||||
|
||||
class ChatScene(Enum):
|
||||
|
||||
ChatWithDbExecute = Scene("chat_with_db_execute", "Chat Data", "Dialogue with your private data through natural language.", ["DB Select"])
|
||||
ChatWithDbQA = Scene("chat_with_db_qa", "Chat Meta Data", "Have a Professional Conversation with Metadata.", ["DB Select"])
|
||||
ChatExecution = Scene("chat_execution", "Chat Plugin", "Use tools through dialogue to accomplish your goals.", ["Plugin Select"])
|
||||
ChatDefaultKnowledge = Scene("chat_default_knowledge", "Chat Default Knowledge", "Dialogue through natural language and private documents and knowledge bases.")
|
||||
ChatNewKnowledge = Scene("chat_new_knowledge", "Chat New Knowledge", "Dialogue through natural language and private documents and knowledge bases.", ["Knowledge Select"])
|
||||
ChatUrlKnowledge = Scene("chat_url_knowledge", "Chat URL", "Dialogue through natural language and private documents and knowledge bases.", ["Url Input"])
|
||||
InnerChatDBSummary = Scene("inner_chat_db_summary", "DB Summary", "Db Summary.", True)
|
||||
|
||||
ChatNormal = Scene("chat_normal", "Chat Normal", "Native LLM large model AI dialogue.")
|
||||
ChatDashboard = Scene("chat_dashboard", "Chat Dashboard", "Provide you with professional analysis reports through natural language.", ["DB Select"])
|
||||
ChatKnowledge = Scene("chat_knowledge", "Chat Knowledge", "Dialogue through natural language and private documents and knowledge bases.", ["Knowledge Space Select"])
|
||||
|
||||
def scene_value(self):
|
||||
return self.value.code;
|
||||
|
||||
def scene_name(self):
|
||||
return self._value_.name;
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(ChatScene.ChatWithDbExecute.scene_value())
|
||||
# print(ChatScene.ChatWithDbExecute.value.describe)
|
@@ -1,12 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from pydantic import BaseModel
|
||||
from test_cls_base import TestBase
|
||||
|
||||
|
||||
class Test1(TestBase):
|
||||
mode: str = "456"
|
||||
|
||||
def write(self):
|
||||
self.test_values.append("x")
|
||||
self.test_values.append("y")
|
||||
self.test_values.append("g")
|
@@ -1,17 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from pydantic import BaseModel
|
||||
from test_cls_base import TestBase
|
||||
from typing import Any, Callable, Dict, List, Mapping, Optional, Set, Union
|
||||
|
||||
|
||||
class Test2(TestBase):
|
||||
test_2_values: List = []
|
||||
mode: str = "789"
|
||||
|
||||
def write(self):
|
||||
self.test_values.append(1)
|
||||
self.test_values.append(2)
|
||||
self.test_values.append(3)
|
||||
self.test_2_values.append("x")
|
||||
self.test_2_values.append("y")
|
||||
self.test_2_values.append("z")
|
@@ -1,13 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from pydantic import BaseModel
|
||||
from typing import Any, Callable, Dict, List, Mapping, Optional, Set, Union
|
||||
|
||||
|
||||
class TestBase(BaseModel, ABC):
|
||||
test_values: List = []
|
||||
mode: str = "123"
|
||||
|
||||
def test(self):
|
||||
print(self.__class__.__name__ + ":")
|
||||
print(self.test_values)
|
||||
print(self.mode)
|
Reference in New Issue
Block a user