vanna 0.6.4__tar.gz → 0.6.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {vanna-0.6.4 → vanna-0.6.5}/PKG-INFO +4 -1
- {vanna-0.6.4 → vanna-0.6.5}/pyproject.toml +3 -2
- vanna-0.6.5/src/vanna/qianfan/Qianfan_Chat.py +165 -0
- vanna-0.6.5/src/vanna/qianfan/Qianfan_embeddings.py +36 -0
- vanna-0.6.5/src/vanna/qianfan/__init__.py +2 -0
- {vanna-0.6.4 → vanna-0.6.5}/README.md +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/ZhipuAI/ZhipuAI_Chat.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/ZhipuAI/ZhipuAI_embeddings.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/ZhipuAI/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/advanced/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/anthropic/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/anthropic/anthropic_chat.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/base/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/base/base.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/bedrock/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/bedrock/bedrock_converse.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/chromadb/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/chromadb/chromadb_vector.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/exceptions/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/flask/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/flask/assets.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/flask/auth.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/google/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/google/gemini_chat.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/hf/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/hf/hf.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/local.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/marqo/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/marqo/marqo.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/milvus/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/milvus/milvus_vector.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/mistral/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/mistral/mistral.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/mock/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/mock/embedding.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/mock/llm.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/mock/vectordb.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/ollama/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/ollama/ollama.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/openai/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/openai/openai_chat.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/openai/openai_embeddings.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/opensearch/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/opensearch/opensearch_vector.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/pinecone/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/pinecone/pinecone_vector.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/qdrant/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/qdrant/qdrant.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/remote.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/types/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/utils.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/vannadb/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/vannadb/vannadb_vector.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/vllm/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/vllm/vllm.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/weaviate/__init__.py +0 -0
- {vanna-0.6.4 → vanna-0.6.5}/src/vanna/weaviate/weaviate_vector.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vanna
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.5
|
|
4
4
|
Summary: Generate SQL queries from natural language
|
|
5
5
|
Author-email: Zain Hoda <zain@vanna.ai>
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -25,6 +25,7 @@ Requires-Dist: google-cloud-bigquery ; extra == "all"
|
|
|
25
25
|
Requires-Dist: snowflake-connector-python ; extra == "all"
|
|
26
26
|
Requires-Dist: duckdb ; extra == "all"
|
|
27
27
|
Requires-Dist: openai ; extra == "all"
|
|
28
|
+
Requires-Dist: qianfan ; extra == "all"
|
|
28
29
|
Requires-Dist: mistralai ; extra == "all"
|
|
29
30
|
Requires-Dist: chromadb ; extra == "all"
|
|
30
31
|
Requires-Dist: anthropic ; extra == "all"
|
|
@@ -68,6 +69,7 @@ Requires-Dist: psycopg2-binary ; extra == "postgres"
|
|
|
68
69
|
Requires-Dist: db-dtypes ; extra == "postgres"
|
|
69
70
|
Requires-Dist: qdrant-client ; extra == "qdrant"
|
|
70
71
|
Requires-Dist: fastembed ; extra == "qdrant"
|
|
72
|
+
Requires-Dist: qianfan ; extra == "qianfan"
|
|
71
73
|
Requires-Dist: snowflake-connector-python ; extra == "snowflake"
|
|
72
74
|
Requires-Dist: tox ; extra == "test"
|
|
73
75
|
Requires-Dist: vllm ; extra == "vllm"
|
|
@@ -95,6 +97,7 @@ Provides-Extra: opensearch
|
|
|
95
97
|
Provides-Extra: pinecone
|
|
96
98
|
Provides-Extra: postgres
|
|
97
99
|
Provides-Extra: qdrant
|
|
100
|
+
Provides-Extra: qianfan
|
|
98
101
|
Provides-Extra: snowflake
|
|
99
102
|
Provides-Extra: test
|
|
100
103
|
Provides-Extra: vllm
|
|
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vanna"
|
|
7
|
-
version = "0.6.
|
|
7
|
+
version = "0.6.5"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Zain Hoda", email="zain@vanna.ai" },
|
|
10
10
|
]
|
|
@@ -33,10 +33,11 @@ bigquery = ["google-cloud-bigquery"]
|
|
|
33
33
|
snowflake = ["snowflake-connector-python"]
|
|
34
34
|
duckdb = ["duckdb"]
|
|
35
35
|
google = ["google-generativeai", "google-cloud-aiplatform"]
|
|
36
|
-
all = ["psycopg2-binary", "db-dtypes", "PyMySQL", "google-cloud-bigquery", "snowflake-connector-python", "duckdb", "openai", "mistralai", "chromadb", "anthropic", "zhipuai", "marqo", "google-generativeai", "google-cloud-aiplatform", "qdrant-client", "fastembed", "ollama", "httpx", "opensearch-py", "opensearch-dsl", "transformers", "pinecone-client", "pymilvus[model]","weaviate-client"]
|
|
36
|
+
all = ["psycopg2-binary", "db-dtypes", "PyMySQL", "google-cloud-bigquery", "snowflake-connector-python", "duckdb", "openai", "qianfan", "mistralai", "chromadb", "anthropic", "zhipuai", "marqo", "google-generativeai", "google-cloud-aiplatform", "qdrant-client", "fastembed", "ollama", "httpx", "opensearch-py", "opensearch-dsl", "transformers", "pinecone-client", "pymilvus[model]","weaviate-client"]
|
|
37
37
|
test = ["tox"]
|
|
38
38
|
chromadb = ["chromadb"]
|
|
39
39
|
openai = ["openai"]
|
|
40
|
+
qianfan = ["qianfan"]
|
|
40
41
|
mistralai = ["mistralai"]
|
|
41
42
|
anthropic = ["anthropic"]
|
|
42
43
|
gemini = ["google-generativeai"]
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import qianfan
|
|
2
|
+
|
|
3
|
+
from ..base import VannaBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Qianfan_Chat(VannaBase):
|
|
7
|
+
def __init__(self, client=None, config=None):
|
|
8
|
+
VannaBase.__init__(self, config=config)
|
|
9
|
+
|
|
10
|
+
if "api_key" not in config:
|
|
11
|
+
raise Exception("Missing api_key in config")
|
|
12
|
+
self.api_key = config["api_key"]
|
|
13
|
+
|
|
14
|
+
if "secret_key" not in config:
|
|
15
|
+
raise Exception("Missing secret_key in config")
|
|
16
|
+
self.secret_key = config["secret_key"]
|
|
17
|
+
|
|
18
|
+
# default parameters - can be overrided using config
|
|
19
|
+
self.temperature = 0.9
|
|
20
|
+
self.max_tokens = 1024
|
|
21
|
+
|
|
22
|
+
if "temperature" in config:
|
|
23
|
+
self.temperature = config["temperature"]
|
|
24
|
+
|
|
25
|
+
if "max_tokens" in config:
|
|
26
|
+
self.max_tokens = config["max_tokens"]
|
|
27
|
+
|
|
28
|
+
self.model = config["model"] if "model" in config else "ERNIE-Speed"
|
|
29
|
+
|
|
30
|
+
if client is not None:
|
|
31
|
+
self.client = client
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
self.client = qianfan.ChatCompletion(ak=self.api_key,
|
|
35
|
+
sk=self.secret_key)
|
|
36
|
+
|
|
37
|
+
def system_message(self, message: str) -> any:
|
|
38
|
+
return {"role": "system", "content": message}
|
|
39
|
+
|
|
40
|
+
def user_message(self, message: str) -> any:
|
|
41
|
+
return {"role": "user", "content": message}
|
|
42
|
+
|
|
43
|
+
def assistant_message(self, message: str) -> any:
|
|
44
|
+
return {"role": "assistant", "content": message}
|
|
45
|
+
|
|
46
|
+
def get_sql_prompt(
|
|
47
|
+
self,
|
|
48
|
+
initial_prompt: str,
|
|
49
|
+
question: str,
|
|
50
|
+
question_sql_list: list,
|
|
51
|
+
ddl_list: list,
|
|
52
|
+
doc_list: list,
|
|
53
|
+
**kwargs,
|
|
54
|
+
):
|
|
55
|
+
"""
|
|
56
|
+
Example:
|
|
57
|
+
```python
|
|
58
|
+
vn.get_sql_prompt(
|
|
59
|
+
question="What are the top 10 customers by sales?",
|
|
60
|
+
question_sql_list=[{"question": "What are the top 10 customers by sales?", "sql": "SELECT * FROM customers ORDER BY sales DESC LIMIT 10"}],
|
|
61
|
+
ddl_list=["CREATE TABLE customers (id INT, name TEXT, sales DECIMAL)"],
|
|
62
|
+
doc_list=["The customers table contains information about customers and their sales."],
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This method is used to generate a prompt for the LLM to generate SQL.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
question (str): The question to generate SQL for.
|
|
71
|
+
question_sql_list (list): A list of questions and their corresponding SQL statements.
|
|
72
|
+
ddl_list (list): A list of DDL statements.
|
|
73
|
+
doc_list (list): A list of documentation.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
any: The prompt for the LLM to generate SQL.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
if initial_prompt is None:
|
|
80
|
+
initial_prompt = f"You are a {self.dialect} expert. " + \
|
|
81
|
+
"Please help to generate a SQL to answer the question based on some context.Please don't give any explanation for your answer. Just only generate a SQL \n"
|
|
82
|
+
|
|
83
|
+
initial_prompt = self.add_ddl_to_prompt(
|
|
84
|
+
initial_prompt, ddl_list, max_tokens=self.max_tokens
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
if self.static_documentation != "":
|
|
88
|
+
doc_list.append(self.static_documentation)
|
|
89
|
+
|
|
90
|
+
initial_prompt = self.add_documentation_to_prompt(
|
|
91
|
+
initial_prompt, doc_list, max_tokens=self.max_tokens
|
|
92
|
+
)
|
|
93
|
+
message_log = []
|
|
94
|
+
|
|
95
|
+
if question_sql_list is None or len(question_sql_list) == 0:
|
|
96
|
+
initial_prompt = initial_prompt + f"question: {question}"
|
|
97
|
+
message_log.append(self.user_message(initial_prompt))
|
|
98
|
+
else:
|
|
99
|
+
for i, example in question_sql_list:
|
|
100
|
+
if example is None:
|
|
101
|
+
print("example is None")
|
|
102
|
+
else:
|
|
103
|
+
if example is not None and "question" in example and "sql" in example:
|
|
104
|
+
if i == 0:
|
|
105
|
+
initial_prompt = initial_prompt + f"question: {example['question']}"
|
|
106
|
+
message_log.append(self.user_message(initial_prompt))
|
|
107
|
+
else:
|
|
108
|
+
message_log.append(self.user_message(example["question"]))
|
|
109
|
+
message_log.append(self.assistant_message(example["sql"]))
|
|
110
|
+
|
|
111
|
+
message_log.append(self.user_message(question))
|
|
112
|
+
return message_log
|
|
113
|
+
|
|
114
|
+
def submit_prompt(self, prompt, **kwargs) -> str:
|
|
115
|
+
if prompt is None:
|
|
116
|
+
raise Exception("Prompt is None")
|
|
117
|
+
|
|
118
|
+
if len(prompt) == 0:
|
|
119
|
+
raise Exception("Prompt is empty")
|
|
120
|
+
|
|
121
|
+
# Count the number of tokens in the message log
|
|
122
|
+
# Use 4 as an approximation for the number of characters per token
|
|
123
|
+
num_tokens = 0
|
|
124
|
+
for message in prompt:
|
|
125
|
+
num_tokens += len(message["content"]) / 4
|
|
126
|
+
|
|
127
|
+
if kwargs.get("model", None) is not None:
|
|
128
|
+
model = kwargs.get("model", None)
|
|
129
|
+
print(
|
|
130
|
+
f"Using model {model} for {num_tokens} tokens (approx)"
|
|
131
|
+
)
|
|
132
|
+
response = self.client.do(
|
|
133
|
+
model=self.model,
|
|
134
|
+
messages=prompt,
|
|
135
|
+
max_output_tokens=self.max_tokens,
|
|
136
|
+
stop=None,
|
|
137
|
+
temperature=self.temperature,
|
|
138
|
+
)
|
|
139
|
+
elif self.config is not None and "model" in self.config:
|
|
140
|
+
print(
|
|
141
|
+
f"Using model {self.config['model']} for {num_tokens} tokens (approx)"
|
|
142
|
+
)
|
|
143
|
+
response = self.client.do(
|
|
144
|
+
model=self.config.get("model"),
|
|
145
|
+
messages=prompt,
|
|
146
|
+
max_output_tokens=self.max_tokens,
|
|
147
|
+
stop=None,
|
|
148
|
+
temperature=self.temperature,
|
|
149
|
+
)
|
|
150
|
+
else:
|
|
151
|
+
if num_tokens > 3500:
|
|
152
|
+
model = "ERNIE-Speed-128K"
|
|
153
|
+
else:
|
|
154
|
+
model = "ERNIE-Speed-8K"
|
|
155
|
+
|
|
156
|
+
print(f"Using model {model} for {num_tokens} tokens (approx)")
|
|
157
|
+
response = self.client.do(
|
|
158
|
+
model=model,
|
|
159
|
+
messages=prompt,
|
|
160
|
+
max_output_tokens=self.max_tokens,
|
|
161
|
+
stop=None,
|
|
162
|
+
temperature=self.temperature,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
return response.body.get("result")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import qianfan
|
|
2
|
+
|
|
3
|
+
from ..base import VannaBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Qianfan_Embeddings(VannaBase):
|
|
7
|
+
def __init__(self, client=None, config=None):
|
|
8
|
+
VannaBase.__init__(self, config=config)
|
|
9
|
+
|
|
10
|
+
if client is not None:
|
|
11
|
+
self.client = client
|
|
12
|
+
return
|
|
13
|
+
|
|
14
|
+
if "api_key" not in config:
|
|
15
|
+
raise Exception("Missing api_key in config")
|
|
16
|
+
self.api_key = config["api_key"]
|
|
17
|
+
|
|
18
|
+
if "secret_key" not in config:
|
|
19
|
+
raise Exception("Missing secret_key in config")
|
|
20
|
+
self.secret_key = config["secret_key"]
|
|
21
|
+
|
|
22
|
+
self.client = qianfan.Embedding(ak=self.api_key, sk=self.secret_key)
|
|
23
|
+
|
|
24
|
+
def generate_embedding(self, data: str, **kwargs) -> list[float]:
|
|
25
|
+
if self.config is not None and "model" in self.config:
|
|
26
|
+
embedding = self.client.do(
|
|
27
|
+
model=self.config["model"],
|
|
28
|
+
input=[data],
|
|
29
|
+
)
|
|
30
|
+
else:
|
|
31
|
+
embedding = self.client.do(
|
|
32
|
+
model="bge-large-zh",
|
|
33
|
+
input=[data],
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return embedding.get("data")[0]["embedding"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|