vanna 0.7.9__py3-none-any.whl → 2.0.0__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.
- vanna/__init__.py +167 -395
- vanna/agents/__init__.py +7 -0
- vanna/capabilities/__init__.py +17 -0
- vanna/capabilities/agent_memory/__init__.py +21 -0
- vanna/capabilities/agent_memory/base.py +103 -0
- vanna/capabilities/agent_memory/models.py +53 -0
- vanna/capabilities/file_system/__init__.py +14 -0
- vanna/capabilities/file_system/base.py +71 -0
- vanna/capabilities/file_system/models.py +25 -0
- vanna/capabilities/sql_runner/__init__.py +13 -0
- vanna/capabilities/sql_runner/base.py +37 -0
- vanna/capabilities/sql_runner/models.py +13 -0
- vanna/components/__init__.py +92 -0
- vanna/components/base.py +11 -0
- vanna/components/rich/__init__.py +83 -0
- vanna/components/rich/containers/__init__.py +7 -0
- vanna/components/rich/containers/card.py +20 -0
- vanna/components/rich/data/__init__.py +9 -0
- vanna/components/rich/data/chart.py +17 -0
- vanna/components/rich/data/dataframe.py +93 -0
- vanna/components/rich/feedback/__init__.py +21 -0
- vanna/components/rich/feedback/badge.py +16 -0
- vanna/components/rich/feedback/icon_text.py +14 -0
- vanna/components/rich/feedback/log_viewer.py +41 -0
- vanna/components/rich/feedback/notification.py +19 -0
- vanna/components/rich/feedback/progress.py +37 -0
- vanna/components/rich/feedback/status_card.py +28 -0
- vanna/components/rich/feedback/status_indicator.py +14 -0
- vanna/components/rich/interactive/__init__.py +21 -0
- vanna/components/rich/interactive/button.py +95 -0
- vanna/components/rich/interactive/task_list.py +58 -0
- vanna/components/rich/interactive/ui_state.py +93 -0
- vanna/components/rich/specialized/__init__.py +7 -0
- vanna/components/rich/specialized/artifact.py +20 -0
- vanna/components/rich/text.py +16 -0
- vanna/components/simple/__init__.py +15 -0
- vanna/components/simple/image.py +15 -0
- vanna/components/simple/link.py +15 -0
- vanna/components/simple/text.py +11 -0
- vanna/core/__init__.py +193 -0
- vanna/core/_compat.py +19 -0
- vanna/core/agent/__init__.py +10 -0
- vanna/core/agent/agent.py +1407 -0
- vanna/core/agent/config.py +123 -0
- vanna/core/audit/__init__.py +28 -0
- vanna/core/audit/base.py +299 -0
- vanna/core/audit/models.py +131 -0
- vanna/core/component_manager.py +329 -0
- vanna/core/components.py +53 -0
- vanna/core/enhancer/__init__.py +11 -0
- vanna/core/enhancer/base.py +94 -0
- vanna/core/enhancer/default.py +118 -0
- vanna/core/enricher/__init__.py +10 -0
- vanna/core/enricher/base.py +59 -0
- vanna/core/errors.py +47 -0
- vanna/core/evaluation/__init__.py +81 -0
- vanna/core/evaluation/base.py +186 -0
- vanna/core/evaluation/dataset.py +254 -0
- vanna/core/evaluation/evaluators.py +376 -0
- vanna/core/evaluation/report.py +289 -0
- vanna/core/evaluation/runner.py +313 -0
- vanna/core/filter/__init__.py +10 -0
- vanna/core/filter/base.py +67 -0
- vanna/core/lifecycle/__init__.py +10 -0
- vanna/core/lifecycle/base.py +83 -0
- vanna/core/llm/__init__.py +16 -0
- vanna/core/llm/base.py +40 -0
- vanna/core/llm/models.py +61 -0
- vanna/core/middleware/__init__.py +10 -0
- vanna/core/middleware/base.py +69 -0
- vanna/core/observability/__init__.py +11 -0
- vanna/core/observability/base.py +88 -0
- vanna/core/observability/models.py +47 -0
- vanna/core/recovery/__init__.py +11 -0
- vanna/core/recovery/base.py +84 -0
- vanna/core/recovery/models.py +32 -0
- vanna/core/registry.py +278 -0
- vanna/core/rich_component.py +156 -0
- vanna/core/simple_component.py +27 -0
- vanna/core/storage/__init__.py +14 -0
- vanna/core/storage/base.py +46 -0
- vanna/core/storage/models.py +46 -0
- vanna/core/system_prompt/__init__.py +13 -0
- vanna/core/system_prompt/base.py +36 -0
- vanna/core/system_prompt/default.py +157 -0
- vanna/core/tool/__init__.py +18 -0
- vanna/core/tool/base.py +70 -0
- vanna/core/tool/models.py +84 -0
- vanna/core/user/__init__.py +17 -0
- vanna/core/user/base.py +29 -0
- vanna/core/user/models.py +25 -0
- vanna/core/user/request_context.py +70 -0
- vanna/core/user/resolver.py +42 -0
- vanna/core/validation.py +164 -0
- vanna/core/workflow/__init__.py +12 -0
- vanna/core/workflow/base.py +254 -0
- vanna/core/workflow/default.py +789 -0
- vanna/examples/__init__.py +1 -0
- vanna/examples/__main__.py +44 -0
- vanna/examples/anthropic_quickstart.py +80 -0
- vanna/examples/artifact_example.py +293 -0
- vanna/examples/claude_sqlite_example.py +236 -0
- vanna/examples/coding_agent_example.py +300 -0
- vanna/examples/custom_system_prompt_example.py +174 -0
- vanna/examples/default_workflow_handler_example.py +208 -0
- vanna/examples/email_auth_example.py +340 -0
- vanna/examples/evaluation_example.py +269 -0
- vanna/examples/extensibility_example.py +262 -0
- vanna/examples/minimal_example.py +67 -0
- vanna/examples/mock_auth_example.py +227 -0
- vanna/examples/mock_custom_tool.py +311 -0
- vanna/examples/mock_quickstart.py +79 -0
- vanna/examples/mock_quota_example.py +145 -0
- vanna/examples/mock_rich_components_demo.py +396 -0
- vanna/examples/mock_sqlite_example.py +223 -0
- vanna/examples/openai_quickstart.py +83 -0
- vanna/examples/primitive_components_demo.py +305 -0
- vanna/examples/quota_lifecycle_example.py +139 -0
- vanna/examples/visualization_example.py +251 -0
- vanna/integrations/__init__.py +17 -0
- vanna/integrations/anthropic/__init__.py +9 -0
- vanna/integrations/anthropic/llm.py +270 -0
- vanna/integrations/azureopenai/__init__.py +9 -0
- vanna/integrations/azureopenai/llm.py +329 -0
- vanna/integrations/azuresearch/__init__.py +7 -0
- vanna/integrations/azuresearch/agent_memory.py +413 -0
- vanna/integrations/bigquery/__init__.py +5 -0
- vanna/integrations/bigquery/sql_runner.py +81 -0
- vanna/integrations/chromadb/__init__.py +104 -0
- vanna/integrations/chromadb/agent_memory.py +416 -0
- vanna/integrations/clickhouse/__init__.py +5 -0
- vanna/integrations/clickhouse/sql_runner.py +82 -0
- vanna/integrations/duckdb/__init__.py +5 -0
- vanna/integrations/duckdb/sql_runner.py +65 -0
- vanna/integrations/faiss/__init__.py +7 -0
- vanna/integrations/faiss/agent_memory.py +431 -0
- vanna/integrations/google/__init__.py +9 -0
- vanna/integrations/google/gemini.py +370 -0
- vanna/integrations/hive/__init__.py +5 -0
- vanna/integrations/hive/sql_runner.py +87 -0
- vanna/integrations/local/__init__.py +17 -0
- vanna/integrations/local/agent_memory/__init__.py +7 -0
- vanna/integrations/local/agent_memory/in_memory.py +285 -0
- vanna/integrations/local/audit.py +59 -0
- vanna/integrations/local/file_system.py +242 -0
- vanna/integrations/local/file_system_conversation_store.py +255 -0
- vanna/integrations/local/storage.py +62 -0
- vanna/integrations/marqo/__init__.py +7 -0
- vanna/integrations/marqo/agent_memory.py +354 -0
- vanna/integrations/milvus/__init__.py +7 -0
- vanna/integrations/milvus/agent_memory.py +458 -0
- vanna/integrations/mock/__init__.py +9 -0
- vanna/integrations/mock/llm.py +65 -0
- vanna/integrations/mssql/__init__.py +5 -0
- vanna/integrations/mssql/sql_runner.py +66 -0
- vanna/integrations/mysql/__init__.py +5 -0
- vanna/integrations/mysql/sql_runner.py +92 -0
- vanna/integrations/ollama/__init__.py +7 -0
- vanna/integrations/ollama/llm.py +252 -0
- vanna/integrations/openai/__init__.py +10 -0
- vanna/integrations/openai/llm.py +267 -0
- vanna/integrations/openai/responses.py +163 -0
- vanna/integrations/opensearch/__init__.py +7 -0
- vanna/integrations/opensearch/agent_memory.py +411 -0
- vanna/integrations/oracle/__init__.py +5 -0
- vanna/integrations/oracle/sql_runner.py +75 -0
- vanna/integrations/pinecone/__init__.py +7 -0
- vanna/integrations/pinecone/agent_memory.py +329 -0
- vanna/integrations/plotly/__init__.py +5 -0
- vanna/integrations/plotly/chart_generator.py +313 -0
- vanna/integrations/postgres/__init__.py +9 -0
- vanna/integrations/postgres/sql_runner.py +112 -0
- vanna/integrations/premium/agent_memory/__init__.py +7 -0
- vanna/integrations/premium/agent_memory/premium.py +186 -0
- vanna/integrations/presto/__init__.py +5 -0
- vanna/integrations/presto/sql_runner.py +107 -0
- vanna/integrations/qdrant/__init__.py +7 -0
- vanna/integrations/qdrant/agent_memory.py +461 -0
- vanna/integrations/snowflake/__init__.py +5 -0
- vanna/integrations/snowflake/sql_runner.py +147 -0
- vanna/integrations/sqlite/__init__.py +9 -0
- vanna/integrations/sqlite/sql_runner.py +65 -0
- vanna/integrations/weaviate/__init__.py +7 -0
- vanna/integrations/weaviate/agent_memory.py +428 -0
- vanna/{ZhipuAI → legacy/ZhipuAI}/ZhipuAI_embeddings.py +11 -11
- vanna/legacy/__init__.py +403 -0
- vanna/legacy/adapter.py +463 -0
- vanna/{advanced → legacy/advanced}/__init__.py +3 -1
- vanna/{anthropic → legacy/anthropic}/anthropic_chat.py +9 -7
- vanna/{azuresearch → legacy/azuresearch}/azuresearch_vector.py +79 -41
- vanna/{base → legacy/base}/base.py +224 -217
- vanna/legacy/bedrock/__init__.py +1 -0
- vanna/{bedrock → legacy/bedrock}/bedrock_converse.py +13 -12
- vanna/{chromadb → legacy/chromadb}/chromadb_vector.py +3 -1
- vanna/legacy/cohere/__init__.py +2 -0
- vanna/{cohere → legacy/cohere}/cohere_chat.py +19 -14
- vanna/{cohere → legacy/cohere}/cohere_embeddings.py +25 -19
- vanna/{deepseek → legacy/deepseek}/deepseek_chat.py +5 -6
- vanna/legacy/faiss/__init__.py +1 -0
- vanna/{faiss → legacy/faiss}/faiss.py +113 -59
- vanna/{flask → legacy/flask}/__init__.py +84 -43
- vanna/{flask → legacy/flask}/assets.py +5 -5
- vanna/{flask → legacy/flask}/auth.py +5 -4
- vanna/{google → legacy/google}/bigquery_vector.py +75 -42
- vanna/{google → legacy/google}/gemini_chat.py +7 -3
- vanna/{hf → legacy/hf}/hf.py +0 -1
- vanna/{milvus → legacy/milvus}/milvus_vector.py +58 -35
- vanna/{mock → legacy/mock}/llm.py +0 -1
- vanna/legacy/mock/vectordb.py +67 -0
- vanna/legacy/ollama/ollama.py +110 -0
- vanna/{openai → legacy/openai}/openai_chat.py +2 -6
- vanna/legacy/opensearch/opensearch_vector.py +369 -0
- vanna/legacy/opensearch/opensearch_vector_semantic.py +200 -0
- vanna/legacy/oracle/oracle_vector.py +584 -0
- vanna/{pgvector → legacy/pgvector}/pgvector.py +42 -13
- vanna/{qdrant → legacy/qdrant}/qdrant.py +2 -6
- vanna/legacy/qianfan/Qianfan_Chat.py +170 -0
- vanna/legacy/qianfan/Qianfan_embeddings.py +36 -0
- vanna/legacy/qianwen/QianwenAI_chat.py +132 -0
- vanna/{remote.py → legacy/remote.py} +28 -26
- vanna/{utils.py → legacy/utils.py} +6 -11
- vanna/{vannadb → legacy/vannadb}/vannadb_vector.py +115 -46
- vanna/{vllm → legacy/vllm}/vllm.py +5 -6
- vanna/{weaviate → legacy/weaviate}/weaviate_vector.py +59 -40
- vanna/{xinference → legacy/xinference}/xinference.py +6 -6
- vanna/py.typed +0 -0
- vanna/servers/__init__.py +16 -0
- vanna/servers/__main__.py +8 -0
- vanna/servers/base/__init__.py +18 -0
- vanna/servers/base/chat_handler.py +65 -0
- vanna/servers/base/models.py +111 -0
- vanna/servers/base/rich_chat_handler.py +141 -0
- vanna/servers/base/templates.py +331 -0
- vanna/servers/cli/__init__.py +7 -0
- vanna/servers/cli/server_runner.py +204 -0
- vanna/servers/fastapi/__init__.py +7 -0
- vanna/servers/fastapi/app.py +163 -0
- vanna/servers/fastapi/routes.py +183 -0
- vanna/servers/flask/__init__.py +7 -0
- vanna/servers/flask/app.py +132 -0
- vanna/servers/flask/routes.py +137 -0
- vanna/tools/__init__.py +41 -0
- vanna/tools/agent_memory.py +322 -0
- vanna/tools/file_system.py +879 -0
- vanna/tools/python.py +222 -0
- vanna/tools/run_sql.py +165 -0
- vanna/tools/visualize_data.py +195 -0
- vanna/utils/__init__.py +0 -0
- vanna/web_components/__init__.py +44 -0
- vanna-2.0.0.dist-info/METADATA +485 -0
- vanna-2.0.0.dist-info/RECORD +289 -0
- vanna-2.0.0.dist-info/entry_points.txt +3 -0
- vanna/bedrock/__init__.py +0 -1
- vanna/cohere/__init__.py +0 -2
- vanna/faiss/__init__.py +0 -1
- vanna/mock/vectordb.py +0 -55
- vanna/ollama/ollama.py +0 -103
- vanna/opensearch/opensearch_vector.py +0 -392
- vanna/opensearch/opensearch_vector_semantic.py +0 -175
- vanna/oracle/oracle_vector.py +0 -585
- vanna/qianfan/Qianfan_Chat.py +0 -165
- vanna/qianfan/Qianfan_embeddings.py +0 -36
- vanna/qianwen/QianwenAI_chat.py +0 -133
- vanna-0.7.9.dist-info/METADATA +0 -408
- vanna-0.7.9.dist-info/RECORD +0 -79
- /vanna/{ZhipuAI → legacy/ZhipuAI}/ZhipuAI_Chat.py +0 -0
- /vanna/{ZhipuAI → legacy/ZhipuAI}/__init__.py +0 -0
- /vanna/{anthropic → legacy/anthropic}/__init__.py +0 -0
- /vanna/{azuresearch → legacy/azuresearch}/__init__.py +0 -0
- /vanna/{base → legacy/base}/__init__.py +0 -0
- /vanna/{chromadb → legacy/chromadb}/__init__.py +0 -0
- /vanna/{deepseek → legacy/deepseek}/__init__.py +0 -0
- /vanna/{exceptions → legacy/exceptions}/__init__.py +0 -0
- /vanna/{google → legacy/google}/__init__.py +0 -0
- /vanna/{hf → legacy/hf}/__init__.py +0 -0
- /vanna/{local.py → legacy/local.py} +0 -0
- /vanna/{marqo → legacy/marqo}/__init__.py +0 -0
- /vanna/{marqo → legacy/marqo}/marqo.py +0 -0
- /vanna/{milvus → legacy/milvus}/__init__.py +0 -0
- /vanna/{mistral → legacy/mistral}/__init__.py +0 -0
- /vanna/{mistral → legacy/mistral}/mistral.py +0 -0
- /vanna/{mock → legacy/mock}/__init__.py +0 -0
- /vanna/{mock → legacy/mock}/embedding.py +0 -0
- /vanna/{ollama → legacy/ollama}/__init__.py +0 -0
- /vanna/{openai → legacy/openai}/__init__.py +0 -0
- /vanna/{openai → legacy/openai}/openai_embeddings.py +0 -0
- /vanna/{opensearch → legacy/opensearch}/__init__.py +0 -0
- /vanna/{oracle → legacy/oracle}/__init__.py +0 -0
- /vanna/{pgvector → legacy/pgvector}/__init__.py +0 -0
- /vanna/{pinecone → legacy/pinecone}/__init__.py +0 -0
- /vanna/{pinecone → legacy/pinecone}/pinecone_vector.py +0 -0
- /vanna/{qdrant → legacy/qdrant}/__init__.py +0 -0
- /vanna/{qianfan → legacy/qianfan}/__init__.py +0 -0
- /vanna/{qianwen → legacy/qianwen}/QianwenAI_embeddings.py +0 -0
- /vanna/{qianwen → legacy/qianwen}/__init__.py +0 -0
- /vanna/{types → legacy/types}/__init__.py +0 -0
- /vanna/{vannadb → legacy/vannadb}/__init__.py +0 -0
- /vanna/{vllm → legacy/vllm}/__init__.py +0 -0
- /vanna/{weaviate → legacy/weaviate}/__init__.py +0 -0
- /vanna/{xinference → legacy/xinference}/__init__.py +0 -0
- {vanna-0.7.9.dist-info → vanna-2.0.0.dist-info}/WHEEL +0 -0
- {vanna-0.7.9.dist-info → vanna-2.0.0.dist-info}/licenses/LICENSE +0 -0
vanna/qianfan/Qianfan_Chat.py
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
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")
|
|
@@ -1,36 +0,0 @@
|
|
|
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"]
|
vanna/qianwen/QianwenAI_chat.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from openai import OpenAI
|
|
4
|
-
|
|
5
|
-
from ..base import VannaBase
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class QianWenAI_Chat(VannaBase):
|
|
9
|
-
def __init__(self, client=None, config=None):
|
|
10
|
-
VannaBase.__init__(self, config=config)
|
|
11
|
-
|
|
12
|
-
# default parameters - can be overrided using config
|
|
13
|
-
self.temperature = 0.7
|
|
14
|
-
|
|
15
|
-
if "temperature" in config:
|
|
16
|
-
self.temperature = config["temperature"]
|
|
17
|
-
|
|
18
|
-
if "api_type" in config:
|
|
19
|
-
raise Exception(
|
|
20
|
-
"Passing api_type is now deprecated. Please pass an OpenAI client instead."
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
if "api_base" in config:
|
|
24
|
-
raise Exception(
|
|
25
|
-
"Passing api_base is now deprecated. Please pass an OpenAI client instead."
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
if "api_version" in config:
|
|
29
|
-
raise Exception(
|
|
30
|
-
"Passing api_version is now deprecated. Please pass an OpenAI client instead."
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
if client is not None:
|
|
34
|
-
self.client = client
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
if config is None and client is None:
|
|
38
|
-
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
if "api_key" in config:
|
|
42
|
-
if "base_url" not in config:
|
|
43
|
-
self.client = OpenAI(api_key=config["api_key"],
|
|
44
|
-
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1")
|
|
45
|
-
else:
|
|
46
|
-
self.client = OpenAI(api_key=config["api_key"],
|
|
47
|
-
base_url=config["base_url"])
|
|
48
|
-
|
|
49
|
-
def system_message(self, message: str) -> any:
|
|
50
|
-
return {"role": "system", "content": message}
|
|
51
|
-
|
|
52
|
-
def user_message(self, message: str) -> any:
|
|
53
|
-
return {"role": "user", "content": message}
|
|
54
|
-
|
|
55
|
-
def assistant_message(self, message: str) -> any:
|
|
56
|
-
return {"role": "assistant", "content": message}
|
|
57
|
-
|
|
58
|
-
def submit_prompt(self, prompt, **kwargs) -> str:
|
|
59
|
-
if prompt is None:
|
|
60
|
-
raise Exception("Prompt is None")
|
|
61
|
-
|
|
62
|
-
if len(prompt) == 0:
|
|
63
|
-
raise Exception("Prompt is empty")
|
|
64
|
-
|
|
65
|
-
# Count the number of tokens in the message log
|
|
66
|
-
# Use 4 as an approximation for the number of characters per token
|
|
67
|
-
num_tokens = 0
|
|
68
|
-
for message in prompt:
|
|
69
|
-
num_tokens += len(message["content"]) / 4
|
|
70
|
-
|
|
71
|
-
if kwargs.get("model", None) is not None:
|
|
72
|
-
model = kwargs.get("model", None)
|
|
73
|
-
print(
|
|
74
|
-
f"Using model {model} for {num_tokens} tokens (approx)"
|
|
75
|
-
)
|
|
76
|
-
response = self.client.chat.completions.create(
|
|
77
|
-
model=model,
|
|
78
|
-
messages=prompt,
|
|
79
|
-
stop=None,
|
|
80
|
-
temperature=self.temperature,
|
|
81
|
-
)
|
|
82
|
-
elif kwargs.get("engine", None) is not None:
|
|
83
|
-
engine = kwargs.get("engine", None)
|
|
84
|
-
print(
|
|
85
|
-
f"Using model {engine} for {num_tokens} tokens (approx)"
|
|
86
|
-
)
|
|
87
|
-
response = self.client.chat.completions.create(
|
|
88
|
-
engine=engine,
|
|
89
|
-
messages=prompt,
|
|
90
|
-
stop=None,
|
|
91
|
-
temperature=self.temperature,
|
|
92
|
-
)
|
|
93
|
-
elif self.config is not None and "engine" in self.config:
|
|
94
|
-
print(
|
|
95
|
-
f"Using engine {self.config['engine']} for {num_tokens} tokens (approx)"
|
|
96
|
-
)
|
|
97
|
-
response = self.client.chat.completions.create(
|
|
98
|
-
engine=self.config["engine"],
|
|
99
|
-
messages=prompt,
|
|
100
|
-
stop=None,
|
|
101
|
-
temperature=self.temperature,
|
|
102
|
-
)
|
|
103
|
-
elif self.config is not None and "model" in self.config:
|
|
104
|
-
print(
|
|
105
|
-
f"Using model {self.config['model']} for {num_tokens} tokens (approx)"
|
|
106
|
-
)
|
|
107
|
-
response = self.client.chat.completions.create(
|
|
108
|
-
model=self.config["model"],
|
|
109
|
-
messages=prompt,
|
|
110
|
-
stop=None,
|
|
111
|
-
temperature=self.temperature,
|
|
112
|
-
)
|
|
113
|
-
else:
|
|
114
|
-
if num_tokens > 3500:
|
|
115
|
-
model = "qwen-long"
|
|
116
|
-
else:
|
|
117
|
-
model = "qwen-plus"
|
|
118
|
-
|
|
119
|
-
print(f"Using model {model} for {num_tokens} tokens (approx)")
|
|
120
|
-
response = self.client.chat.completions.create(
|
|
121
|
-
model=model,
|
|
122
|
-
messages=prompt,
|
|
123
|
-
stop=None,
|
|
124
|
-
temperature=self.temperature,
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
# Find the first response from the chatbot that has text in it (some responses may not have text)
|
|
128
|
-
for choice in response.choices:
|
|
129
|
-
if "text" in choice:
|
|
130
|
-
return choice.text
|
|
131
|
-
|
|
132
|
-
# If no response with text is found, return the first response's content (which may be empty)
|
|
133
|
-
return response.choices[0].message.content
|