vanna 0.6.3__py3-none-any.whl → 0.6.5__py3-none-any.whl

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.
@@ -11,14 +11,10 @@ class OpenAI_Chat(VannaBase):
11
11
 
12
12
  # default parameters - can be overrided using config
13
13
  self.temperature = 0.7
14
- self.max_tokens = 500
15
14
 
16
15
  if "temperature" in config:
17
16
  self.temperature = config["temperature"]
18
17
 
19
- if "max_tokens" in config:
20
- self.max_tokens = config["max_tokens"]
21
-
22
18
  if "api_type" in config:
23
19
  raise Exception(
24
20
  "Passing api_type is now deprecated. Please pass an OpenAI client instead."
@@ -75,7 +71,6 @@ class OpenAI_Chat(VannaBase):
75
71
  response = self.client.chat.completions.create(
76
72
  model=model,
77
73
  messages=prompt,
78
- max_tokens=self.max_tokens,
79
74
  stop=None,
80
75
  temperature=self.temperature,
81
76
  )
@@ -87,7 +82,6 @@ class OpenAI_Chat(VannaBase):
87
82
  response = self.client.chat.completions.create(
88
83
  engine=engine,
89
84
  messages=prompt,
90
- max_tokens=self.max_tokens,
91
85
  stop=None,
92
86
  temperature=self.temperature,
93
87
  )
@@ -98,7 +92,6 @@ class OpenAI_Chat(VannaBase):
98
92
  response = self.client.chat.completions.create(
99
93
  engine=self.config["engine"],
100
94
  messages=prompt,
101
- max_tokens=self.max_tokens,
102
95
  stop=None,
103
96
  temperature=self.temperature,
104
97
  )
@@ -109,7 +102,6 @@ class OpenAI_Chat(VannaBase):
109
102
  response = self.client.chat.completions.create(
110
103
  model=self.config["model"],
111
104
  messages=prompt,
112
- max_tokens=self.max_tokens,
113
105
  stop=None,
114
106
  temperature=self.temperature,
115
107
  )
@@ -123,7 +115,6 @@ class OpenAI_Chat(VannaBase):
123
115
  response = self.client.chat.completions.create(
124
116
  model=model,
125
117
  messages=prompt,
126
- max_tokens=self.max_tokens,
127
118
  stop=None,
128
119
  temperature=self.temperature,
129
120
  )
@@ -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"]
@@ -0,0 +1,2 @@
1
+ from .Qianfan_Chat import Qianfan_Chat
2
+ from .Qianfan_embeddings import Qianfan_Embeddings
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vanna
3
- Version: 0.6.3
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
@@ -16,6 +16,7 @@ Requires-Dist: sqlparse
16
16
  Requires-Dist: kaleido
17
17
  Requires-Dist: flask
18
18
  Requires-Dist: flask-sock
19
+ Requires-Dist: flasgger
19
20
  Requires-Dist: sqlalchemy
20
21
  Requires-Dist: psycopg2-binary ; extra == "all"
21
22
  Requires-Dist: db-dtypes ; extra == "all"
@@ -24,6 +25,7 @@ Requires-Dist: google-cloud-bigquery ; extra == "all"
24
25
  Requires-Dist: snowflake-connector-python ; extra == "all"
25
26
  Requires-Dist: duckdb ; extra == "all"
26
27
  Requires-Dist: openai ; extra == "all"
28
+ Requires-Dist: qianfan ; extra == "all"
27
29
  Requires-Dist: mistralai ; extra == "all"
28
30
  Requires-Dist: chromadb ; extra == "all"
29
31
  Requires-Dist: anthropic ; extra == "all"
@@ -67,6 +69,7 @@ Requires-Dist: psycopg2-binary ; extra == "postgres"
67
69
  Requires-Dist: db-dtypes ; extra == "postgres"
68
70
  Requires-Dist: qdrant-client ; extra == "qdrant"
69
71
  Requires-Dist: fastembed ; extra == "qdrant"
72
+ Requires-Dist: qianfan ; extra == "qianfan"
70
73
  Requires-Dist: snowflake-connector-python ; extra == "snowflake"
71
74
  Requires-Dist: tox ; extra == "test"
72
75
  Requires-Dist: vllm ; extra == "vllm"
@@ -94,6 +97,7 @@ Provides-Extra: opensearch
94
97
  Provides-Extra: pinecone
95
98
  Provides-Extra: postgres
96
99
  Provides-Extra: qdrant
100
+ Provides-Extra: qianfan
97
101
  Provides-Extra: snowflake
98
102
  Provides-Extra: test
99
103
  Provides-Extra: vllm
@@ -7,15 +7,15 @@ vanna/ZhipuAI/ZhipuAI_embeddings.py,sha256=lUqzJg9fOx7rVFhjdkFjXcDeVGV4aAB5Ss0oE
7
7
  vanna/ZhipuAI/__init__.py,sha256=NlsijtcZp5Tj9jkOe9fNcOQND_QsGgu7otODsCLBPr0,116
8
8
  vanna/advanced/__init__.py,sha256=oDj9g1JbrbCfp4WWdlr_bhgdMqNleyHgr6VXX6DcEbo,658
9
9
  vanna/anthropic/__init__.py,sha256=85s_2mAyyPxc0T_0JEvYeAkEKWJwkwqoyUwSC5dw9Gk,43
10
- vanna/anthropic/anthropic_chat.py,sha256=Wk0o-NMW1uvR2fhSWxrR_2FqNh-dLprNG4uuVqpqAkY,2615
10
+ vanna/anthropic/anthropic_chat.py,sha256=7X3x8SYwDY28aGyBnt0YNRMG8YY1p_t-foMfKGj8_Oo,2627
11
11
  vanna/base/__init__.py,sha256=Sl-HM1RRYzAZoSqmL1CZQmF3ZF-byYTCFQP3JZ2A5MU,28
12
- vanna/base/base.py,sha256=Cz5fW0Odg5GaRg2svvl6YPeBULKXKMNODAb3Zc1Q8bU,70993
12
+ vanna/base/base.py,sha256=3Du70NrXQMn_LOif2YFPRRVKo4wH5-f6eZcLlXEX0X8,71705
13
13
  vanna/bedrock/__init__.py,sha256=hRT2bgJbHEqViLdL-t9hfjSfFdIOkPU2ADBt-B1En-8,46
14
14
  vanna/bedrock/bedrock_converse.py,sha256=Nx5kYm-diAfYmsWAnTP5xnv7V84Og69-AP9b3seIe0E,2869
15
15
  vanna/chromadb/__init__.py,sha256=-iL0nW_g4uM8nWKMuWnNePfN4nb9uk8P3WzGvezOqRg,50
16
16
  vanna/chromadb/chromadb_vector.py,sha256=eKyPck99Y6Jt-BNWojvxLG-zvAERzLSm-3zY-bKXvaA,8792
17
17
  vanna/exceptions/__init__.py,sha256=dJ65xxxZh1lqBeg6nz6Tq_r34jLVmjvBvPO9Q6hFaQ8,685
18
- vanna/flask/__init__.py,sha256=urPrHUqM1mpx96VHiQWVXCy3NQwDh6OsSkm4V4wqccY,30211
18
+ vanna/flask/__init__.py,sha256=r1ucQupb6wuTcjVVKpkdrg6R38FZe6KQoKw9AtcghDQ,42889
19
19
  vanna/flask/assets.py,sha256=_UoUr57sS0QL2BuTxAOe9k4yy8T7-fp2NpbRSVtW3IM,451769
20
20
  vanna/flask/auth.py,sha256=UpKxh7W5cd43W0LGch0VqhncKwB78L6dtOQkl1JY5T0,1246
21
21
  vanna/google/__init__.py,sha256=M-dCxCZcKL4bTQyMLj6r6VRs65YNX9Tl2aoPCuqGm-8,41
@@ -35,7 +35,7 @@ vanna/mock/vectordb.py,sha256=h45znfYMUnttE2BBC8v6TKeMaA58pFJL-5B3OGeRNFI,2681
35
35
  vanna/ollama/__init__.py,sha256=4xyu8aHPdnEHg5a-QAMwr5o0ns5wevsp_zkI-ndMO2k,27
36
36
  vanna/ollama/ollama.py,sha256=rXa7cfvdlO1E5SLysXIl3IZpIaA2r0RBvV5jX2-upiE,3794
37
37
  vanna/openai/__init__.py,sha256=tGkeQ7wTIPsando7QhoSHehtoQVdYLwFbKNlSmCmNeQ,86
38
- vanna/openai/openai_chat.py,sha256=lm-hUsQxu6Q1t06A2csC037zI4VkMk0wFbQ-_Lj74Wg,4764
38
+ vanna/openai/openai_chat.py,sha256=KU6ynOQ5v7vwrQQ13phXoUXeQUrH6_vmhfiPvWddTrQ,4427
39
39
  vanna/openai/openai_embeddings.py,sha256=g4pNh9LVcYP9wOoO8ecaccDFWmCUYMInebfHucAa2Gc,1260
40
40
  vanna/opensearch/__init__.py,sha256=0unDevWOTs7o8S79TOHUKF1mSiuQbBUVm-7k9jV5WW4,54
41
41
  vanna/opensearch/opensearch_vector.py,sha256=VhIcrSyNzWR9ZrqrJnyGFOyuQZs3swfbhr8QyVGI0eI,12226
@@ -43,6 +43,9 @@ vanna/pinecone/__init__.py,sha256=eO5l8aX8vKL6aIUMgAXGPt1jdqKxB_Hic6cmoVAUrD0,90
43
43
  vanna/pinecone/pinecone_vector.py,sha256=mpq1lzo3KRj2QfJEw8pwFclFQK1Oi_Nx-lDkx9Gp0mw,11448
44
44
  vanna/qdrant/__init__.py,sha256=PX_OsDOiPMvwCJ2iGER1drSdQ9AyM8iN5PEBhRb6qqY,73
45
45
  vanna/qdrant/qdrant.py,sha256=qkTWhGrVSAngJZkrcRQ8YFVHcI9j_ZoOGbF6ZVUUdsU,12567
46
+ vanna/qianfan/Qianfan_Chat.py,sha256=Z-s9MwH22T4KMR8AViAjms6qoj67pHeQkMsbK-aXf1M,5273
47
+ vanna/qianfan/Qianfan_embeddings.py,sha256=TYynAJXlyuZfmoj49h8nU6bXu_GjlXREp3tgfQUca04,954
48
+ vanna/qianfan/__init__.py,sha256=QpR43BjZQZcrcDRkyYcYiS-kyqtYmu23AHDzK0Wy1D0,90
46
49
  vanna/types/__init__.py,sha256=Qhn_YscKtJh7mFPCyCDLa2K8a4ORLMGVnPpTbv9uB2U,4957
47
50
  vanna/vannadb/__init__.py,sha256=C6UkYocmO6dmzfPKZaWojN0mI5YlZZ9VIbdcquBE58A,48
48
51
  vanna/vannadb/vannadb_vector.py,sha256=N8poMYvAojoaOF5gI4STD5pZWK9lBKPvyIjbh9dPBa0,14189
@@ -50,6 +53,6 @@ vanna/vllm/__init__.py,sha256=aNlUkF9tbURdeXAJ8ytuaaF1gYwcG3ny1MfNl_cwQYg,23
50
53
  vanna/vllm/vllm.py,sha256=oM_aA-1Chyl7T_Qc_yRKlL6oSX1etsijY9zQdjeMGMQ,2827
51
54
  vanna/weaviate/__init__.py,sha256=HL6PAl7ePBAkeG8uln-BmM7IUtWohyTPvDfcPzSGSCg,46
52
55
  vanna/weaviate/weaviate_vector.py,sha256=GEiu4Vd9w-7j10aB-zTxJ8gefqe_F-LUUGvttFs1vlg,7539
53
- vanna-0.6.3.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
54
- vanna-0.6.3.dist-info/METADATA,sha256=-CFXJd2aKy2tq2Gxipp-52YCPHJBlI0wIOPzcOV5s80,11865
55
- vanna-0.6.3.dist-info/RECORD,,
56
+ vanna-0.6.5.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
57
+ vanna-0.6.5.dist-info/METADATA,sha256=77ggtzQplTTDdsOI0_U4k-t5UwHVmI5O3TSkpm5OXzY,11997
58
+ vanna-0.6.5.dist-info/RECORD,,
File without changes