**
先看 notebook 代码
**
数据分析大模型
教程
架构图
from IPython.display import display, Image
path = r"Architecture.gif"
img = Image(path)
display(img)
效果
from IPython.display import display, HTML
html_str = ‘’’
<video controls width=“500” height=“500” src=“{}”>animation
‘’'.format(“./ai_db_demo.mp4”)
print(html_str)
display(HTML(html_str))
!pip install vanna ollama ChromaDB mysql-connector-python vanna[chromadb,ollama,mysql] -i https://pypi.tuna.tsinghua.edu.cn/simple
import pandas as pd
import mysql.connector
from vanna.ollama import Ollama
from vanna.vannadb import VannaDB_VectorStore
from vanna.chromadb.chromadb_vector import ChromaDB_VectorStore
class MyVanna(ChromaDB_VectorStore, Ollama):
def init(self, config=None):
ChromaDB_VectorStore.init(self, config=config)
Ollama.init(self, config=config)
vn = MyVanna(config={‘model’: ‘mistral:latest’,‘ollama_host’:‘http://172.10.36.28:11434’})
cnx = mysql.connector.connect(user=‘root’,password=‘q3fD50<VSlFE’, host=‘172.10.32.234’, database=‘nlsql_test’)
cursor = cnx.cursor()
def run_sql(sql: str) -> pd.DataFrame:
cursor.execute(sql)
result = cursor.fetchall()
columns = cursor.column_names
df = pd.DataFrame(columns=columns)
if len(result) > 0:
df = pd.DataFrame(result, columns=columns)
return df
将函数设置到vn.run_sql中
vn.run_sql = run_sql
vn.run_sql_is_set = True
vn.train(question=“”“图书表明细”“”,
sql=“”"
SELECT id, create_time, book_name, book_code, book_introduction, book_publisher, book_image FROM book
“”“,
ddl=”“”
CREATE TABLE IF NOT EXISTS book
(
id
int NOT NULL AUTO_INCREMENT COMMENT ‘表唯一ID’,
create_time
datetime DEFAULT NULL COMMENT ‘创建时间’,
book_name
varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT ‘书的名字’,
book_code
varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT ‘书的编号’,
book_introduction
varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT ‘书的简介’,
book_publisher
varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DE