vanna.remote

class VannaDefault(vanna.base.base.VannaBase)

提供使用继承创建标准 ABC 的辅助类。

VannaDefault(model: str, api_key: str, config=None)
def get_training_data(self, **kwargs) -> pandas.core.frame.DataFrame:

获取当前模型的训练数据

示例

training_data = vn.get_training_data()
返回

pd.DataFrame 或 None:训练数据,如果发生错误则为 None。

def remove_training_data(self, id: str, **kwargs) -> bool:

从模型中移除训练数据

示例

vn.remove_training_data(id="1-ddl")
参数
  • id (str): 要移除的训练数据的 ID。
def generate_questions(self) -> list[str]:

示例

vn.generate_questions()
# ['What is the average salary of employees?', 'What is the total salary of employees?', ...]

使用 Vanna.AI API 生成问题。

返回

List[str] 或 None:生成的问题列表,如果发生错误则为 None。

def add_ddl(self, ddl: str, **kwargs) -> str:

向模型的训练数据中添加 DDL 语句

示例

vn.add_ddl(
    ddl="CREATE TABLE employees (id INT, name VARCHAR(255), salary INT)"
)
参数
  • ddl (str): 要存储的 DDL 语句。
返回

str:DDL 语句的 ID。

def add_documentation(self, doc: str, **kwargs) -> str:

向模型的训练数据中添加文档

示例

vn.add_documentation(
    documentation="Our organization's definition of sales is the discount price of an item multiplied by the quantity sold."
)
参数
  • documentation (str): 要存储的文档字符串。
返回

str:文档字符串的 ID。

def add_question_sql(self, question: str, sql: str, **kwargs) -> str:

向模型的训练数据中添加问题及其对应的 SQL 查询。建议通过调用 [vn.train(sql=...)][vanna.train] 来实现。

示例

vn.add_sql(
    question="What is the average salary of employees?",
    sql="SELECT AVG(salary) FROM employees"
)
参数
  • question (str): 要存储的问题。
  • sql (str): 要存储的 SQL 查询。
  • tag (Union[str, None]): 与问题和 SQL 查询相关联的标签。
返回

str:问题和 SQL 查询的 ID。

def generate_embedding(self, data: str, **kwargs) -> list[float]:

对于远程模型来说非必需,因为嵌入是在服务器端生成的。

def generate_plotly_code( self, question: str = None, sql: str = None, df_metadata: str = None, **kwargs) -> str:

示例

vn.generate_plotly_code(
    question="What is the average salary of employees?",
    sql="SELECT AVG(salary) FROM employees",
    df_metadata=df.dtypes
)
# fig = px.bar(df, x="name", y="salary")

使用 Vanna.AI API 生成 Plotly 代码。

参数
  • question (str): 要为其生成 Plotly 代码的问题。
  • sql (str): 要为其生成 Plotly 代码的 SQL 查询。
  • df (pd.DataFrame): 要为其生成 Plotly 代码的 dataframe。
  • chart_instructions (str): 可选的图表绘制说明。
返回

str 或 None:Plotly 代码,如果发生错误则为 None。

def generate_question(self, sql: str, **kwargs) -> str:

示例

vn.generate_question(sql="SELECT * FROM students WHERE name = 'John Doe'")
# 'What is the name of the student?'

使用 Vanna.AI API 从 SQL 查询生成问题。

参数
  • sql (str): 要为其生成问题 SQL 查询。
返回

str 或 None:生成的问题,如果发生错误则为 None。

def get_sql_prompt( self, question: str, question_sql_list: list, ddl_list: list, doc_list: list, **kwargs):

对于远程模型来说非必需,因为提示是在服务器端生成的。

def get_followup_questions_prompt( self, question: str, df: pandas.core.frame.DataFrame, question_sql_list: list, ddl_list: list, doc_list: list, **kwargs):

对于远程模型来说非必需,因为提示是在服务器端生成的。

def submit_prompt(self, prompt, **kwargs) -> str:

对于远程模型来说非必需,因为提示是在服务器端处理的。

def get_similar_question_sql(self, question: str, **kwargs) -> list:

对于远程模型来说非必需,因为相似问题是在服务器端生成的。

def generate_sql(self, question: str, **kwargs) -> str:

示例

vn.generate_sql_from_question(question="What is the average salary of employees?")
# SELECT AVG(salary) FROM employees

使用 Vanna.AI API 生成 SQL 查询。

参数
  • question (str): 要为其生成 SQL 查询的问题。
返回

str 或 None:SQL 查询,如果发生错误则为 None。

def generate_followup_questions( self, question: str, df: pandas.core.frame.DataFrame, **kwargs) -> list[str]:

示例

vn.generate_followup_questions(question="What is the average salary of employees?", df=df)
# ['What is the average salary of employees in the Sales department?', 'What is the average salary of employees in the Engineering department?', ...]

使用 Vanna.AI API 生成后续问题。

参数
  • question (str): 要为其生成后续问题的问题。
  • df (pd.DataFrame): 要为其生成后续问题的 DataFrame。
返回

List[str] 或 None:后续问题列表,如果发生错误则为 None。