vectara-agentic 0.1.17__py3-none-any.whl → 0.1.18__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.
Potentially problematic release.
This version of vectara-agentic might be problematic. Click here for more details.
- vectara_agentic/__init__.py +1 -1
- vectara_agentic/_prompts.py +7 -3
- vectara_agentic/db_tools.py +74 -0
- vectara_agentic/tools.py +36 -7
- vectara_agentic/tools_catalog.py +2 -36
- {vectara_agentic-0.1.17.dist-info → vectara_agentic-0.1.18.dist-info}/METADATA +14 -4
- {vectara_agentic-0.1.17.dist-info → vectara_agentic-0.1.18.dist-info}/RECORD +10 -9
- {vectara_agentic-0.1.17.dist-info → vectara_agentic-0.1.18.dist-info}/WHEEL +1 -1
- {vectara_agentic-0.1.17.dist-info → vectara_agentic-0.1.18.dist-info}/LICENSE +0 -0
- {vectara_agentic-0.1.17.dist-info → vectara_agentic-0.1.18.dist-info}/top_level.txt +0 -0
vectara_agentic/__init__.py
CHANGED
vectara_agentic/_prompts.py
CHANGED
|
@@ -24,9 +24,11 @@ GENERAL_INSTRUCTIONS = """
|
|
|
24
24
|
- If you are provided with database tools use them for analytical queries (such as counting, calculating max, min, average, sum, or other statistics).
|
|
25
25
|
For each database, the database tools include: x_list_tables, x_load_data, x_describe_tables, and x_load_sample_data, where 'x' in the database name.
|
|
26
26
|
The x_list_tables tool provides a list of available tables in the x database.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
Before issuing a SQL query, always:
|
|
28
|
+
- Use the x_describe_tables tool to understand the schema of each table
|
|
29
|
+
- Use the x_load_unique_values tool to understand the unique values in each column.
|
|
30
|
+
Sometimes the user may ask for a specific column value, but the actual value in the table may be different, and you will need to use the correct value.
|
|
31
|
+
- Use the x_load_sample_data tool to understand the column names, and typical values in each column.
|
|
30
32
|
- Never call x_load_data to retrieve values from each row in the table.
|
|
31
33
|
- Do not mention table names or database names in your response.
|
|
32
34
|
"""
|
|
@@ -89,6 +91,8 @@ NEVER surround your response with markdown code markers. You may use code marker
|
|
|
89
91
|
|
|
90
92
|
Please use a valid JSON format for the Action Input. Do NOT do this {{'input': 'hello world', 'num_beams': 5}}.
|
|
91
93
|
|
|
94
|
+
Do not include the Action Input in a wrapper dictionary 'properties' like this: {{'properties': {{'input': 'hello world', 'num_beams': 5}} }}.
|
|
95
|
+
|
|
92
96
|
If this format is used, the user will respond in the following format:
|
|
93
97
|
|
|
94
98
|
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module contains the code to extend and improve DatabaseToolSpec
|
|
3
|
+
Specifically adding load_sample_data and load_unique_values methods, as well as
|
|
4
|
+
making sure the load_data method returns a list of text values from the database, not Document[] objects.
|
|
5
|
+
"""
|
|
6
|
+
from abc import ABC
|
|
7
|
+
from typing import Callable, Any
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# Additional database tool
|
|
11
|
+
#
|
|
12
|
+
class DBTool(ABC):
|
|
13
|
+
"""
|
|
14
|
+
A base class for vectara-agentic database tools extensions
|
|
15
|
+
"""
|
|
16
|
+
def __init__(self, load_data_fn: Callable):
|
|
17
|
+
self.load_data_fn = load_data_fn
|
|
18
|
+
|
|
19
|
+
class DBLoadData(DBTool):
|
|
20
|
+
"""
|
|
21
|
+
A tool to Run SQL query on the database and return the result.
|
|
22
|
+
"""
|
|
23
|
+
def __call__(self, query: str) -> Any:
|
|
24
|
+
"""Query and load data from the Database, returning a list of Documents.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
query (str): an SQL query to filter tables and rows.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
List[text]: a list of text values from the database.
|
|
31
|
+
"""
|
|
32
|
+
res = self.load_data_fn(query)
|
|
33
|
+
return [d.text for d in res]
|
|
34
|
+
|
|
35
|
+
class DBLoadSampleData(DBTool):
|
|
36
|
+
"""
|
|
37
|
+
A tool to load a sample of data from the specified database table.
|
|
38
|
+
|
|
39
|
+
This tool fetches the first num_rows (default 25) rows from the given table
|
|
40
|
+
using a provided database query function.
|
|
41
|
+
"""
|
|
42
|
+
def __call__(self, table_name: str, num_rows: int = 25) -> Any:
|
|
43
|
+
"""
|
|
44
|
+
Fetches the first num_rows rows from the specified database table.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
table_name (str): The name of the database table.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
Any: The result of the database query.
|
|
51
|
+
"""
|
|
52
|
+
return self.load_data_fn(f"SELECT * FROM {table_name} LIMIT {num_rows}")
|
|
53
|
+
|
|
54
|
+
class DBLoadUniqueValues(DBTool):
|
|
55
|
+
"""
|
|
56
|
+
A tool to list all unique values for each column in a set of columns of a database table.
|
|
57
|
+
"""
|
|
58
|
+
def __call__(self, table_name: str, columns: list[str], num_vals: int = 200) -> dict:
|
|
59
|
+
"""
|
|
60
|
+
Fetches the first num_vals unique values from the specified columns of the database table.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
table_name (str): The name of the database table.
|
|
64
|
+
columns (list[str]): The list of columns to fetch unique values from.
|
|
65
|
+
num_vals (int): The number of unique values to fetch for each column. Default is 200.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
dict: A dictionary containing the unique values for each column.
|
|
69
|
+
"""
|
|
70
|
+
res = {}
|
|
71
|
+
for column in columns:
|
|
72
|
+
unique_vals = self.load_data_fn(f'SELECT DISTINCT "{column}" FROM {table_name} LIMIT {num_vals}')
|
|
73
|
+
res[column] = [d.text for d in unique_vals]
|
|
74
|
+
return res
|
vectara_agentic/tools.py
CHANGED
|
@@ -7,7 +7,7 @@ import re
|
|
|
7
7
|
import importlib
|
|
8
8
|
import os
|
|
9
9
|
|
|
10
|
-
from typing import Callable, List, Any, Optional, Type
|
|
10
|
+
from typing import Callable, List, Dict, Any, Optional, Type
|
|
11
11
|
from pydantic import BaseModel, Field
|
|
12
12
|
|
|
13
13
|
from llama_index.core.tools import FunctionTool
|
|
@@ -18,7 +18,8 @@ from llama_index.core.tools.types import ToolMetadata, ToolOutput
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
from .types import ToolType
|
|
21
|
-
from .tools_catalog import summarize_text, rephrase_text, critique_text, get_bad_topics
|
|
21
|
+
from .tools_catalog import summarize_text, rephrase_text, critique_text, get_bad_topics
|
|
22
|
+
from .db_tools import DBLoadSampleData, DBLoadUniqueValues, DBLoadData
|
|
22
23
|
|
|
23
24
|
LI_packages = {
|
|
24
25
|
"yahoo_finance": ToolType.QUERY,
|
|
@@ -42,9 +43,15 @@ LI_packages = {
|
|
|
42
43
|
},
|
|
43
44
|
"GoogleSearchToolSpec": {"google_search": ToolType.QUERY},
|
|
44
45
|
},
|
|
46
|
+
"slack": {
|
|
47
|
+
"SlackToolSpec": {
|
|
48
|
+
"load_data": ToolType.QUERY,
|
|
49
|
+
"send_message": ToolType.ACTION,
|
|
50
|
+
"fetch_channel": ToolType.QUERY,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
|
|
48
55
|
class VectaraToolMetadata(ToolMetadata):
|
|
49
56
|
"""
|
|
50
57
|
A subclass of ToolMetadata adding the tool_type attribute.
|
|
@@ -152,6 +159,8 @@ class VectaraToolFactory:
|
|
|
152
159
|
reranker: str = "mmr",
|
|
153
160
|
rerank_k: int = 50,
|
|
154
161
|
mmr_diversity_bias: float = 0.2,
|
|
162
|
+
udf_expression: str = None,
|
|
163
|
+
rerank_chain: List[Dict] = None,
|
|
155
164
|
include_citations: bool = True,
|
|
156
165
|
fcs_threshold: float = 0.0,
|
|
157
166
|
) -> VectaraTool:
|
|
@@ -171,10 +180,16 @@ class VectaraToolFactory:
|
|
|
171
180
|
reranker (str, optional): The reranker mode.
|
|
172
181
|
rerank_k (int, optional): Number of top-k documents for reranking.
|
|
173
182
|
mmr_diversity_bias (float, optional): MMR diversity bias.
|
|
183
|
+
udf_expression (str, optional): the user defined expression for reranking results.
|
|
184
|
+
rerank_chain (List[Dict], optional): A list of rerankers to be applied sequentially.
|
|
185
|
+
Each dictionary should specify the "type" of reranker (mmr, slingshot, udf)
|
|
186
|
+
and any other parameters (e.g. "limit" or "cutoff" for any type,
|
|
187
|
+
"diversity_bias" for mmr, and "user_function" for udf).
|
|
188
|
+
If using slingshot/multilingual_reranker_v1, it must be first in the list.
|
|
174
189
|
include_citations (bool, optional): Whether to include citations in the response.
|
|
175
190
|
If True, uses markdown vectara citations that requires the Vectara scale plan.
|
|
176
191
|
fcs_threshold (float, optional): a threshold for factual consistency.
|
|
177
|
-
If set above 0, the tool notifies the calling agent that it "cannot respond" if FCS is too low
|
|
192
|
+
If set above 0, the tool notifies the calling agent that it "cannot respond" if FCS is too low.
|
|
178
193
|
|
|
179
194
|
Returns:
|
|
180
195
|
VectaraTool: A VectaraTool object.
|
|
@@ -218,6 +233,8 @@ class VectaraToolFactory:
|
|
|
218
233
|
reranker=reranker,
|
|
219
234
|
rerank_k=rerank_k if rerank_k * self.num_corpora <= 100 else int(100 / self.num_corpora),
|
|
220
235
|
mmr_diversity_bias=mmr_diversity_bias,
|
|
236
|
+
udf_expression=udf_expression,
|
|
237
|
+
rerank_chain=rerank_chain,
|
|
221
238
|
n_sentence_before=n_sentences_before,
|
|
222
239
|
n_sentence_after=n_sentences_after,
|
|
223
240
|
lambda_val=lambda_val,
|
|
@@ -495,10 +512,22 @@ class ToolsFactory:
|
|
|
495
512
|
tool.metadata.description + f"The database tables include data about {content_description}."
|
|
496
513
|
)
|
|
497
514
|
|
|
498
|
-
#
|
|
515
|
+
# Add two new tools: load_sample_data and load_unique_values
|
|
499
516
|
load_data_tool_index = next(i for i, t in enumerate(tools) if t.metadata.name.endswith("load_data"))
|
|
500
|
-
|
|
517
|
+
load_data_fn_original = tools[load_data_tool_index].fn
|
|
518
|
+
|
|
519
|
+
load_data_fn = DBLoadData(load_data_fn_original)
|
|
520
|
+
load_data_fn.__name__ = f"{tool_name_prefix}_load_data"
|
|
521
|
+
load_data_tool = self.create_tool(load_data_fn, ToolType.QUERY)
|
|
522
|
+
|
|
523
|
+
sample_data_fn = DBLoadSampleData(load_data_fn_original)
|
|
501
524
|
sample_data_fn.__name__ = f"{tool_name_prefix}_load_sample_data"
|
|
502
525
|
sample_data_tool = self.create_tool(sample_data_fn, ToolType.QUERY)
|
|
503
|
-
|
|
526
|
+
|
|
527
|
+
load_unique_values_fn = DBLoadUniqueValues(load_data_fn_original)
|
|
528
|
+
load_unique_values_fn.__name__ = f"{tool_name_prefix}_load_unique_values"
|
|
529
|
+
load_unique_values_tool = self.create_tool(load_unique_values_fn, ToolType.QUERY)
|
|
530
|
+
|
|
531
|
+
tools[load_data_tool_index] = load_data_tool
|
|
532
|
+
tools.extend([sample_data_tool, load_unique_values_tool])
|
|
504
533
|
return tools
|
vectara_agentic/tools_catalog.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"""
|
|
2
2
|
This module contains the tools catalog for the Vectara Agentic.
|
|
3
3
|
"""
|
|
4
|
-
|
|
5
|
-
from typing import Callable, Any, List
|
|
4
|
+
from typing import List
|
|
6
5
|
from functools import lru_cache
|
|
7
6
|
from pydantic import Field
|
|
8
7
|
import requests
|
|
@@ -114,7 +113,7 @@ def critique_text(
|
|
|
114
113
|
|
|
115
114
|
|
|
116
115
|
#
|
|
117
|
-
# Guardrails
|
|
116
|
+
# Guardrails tool: returns list of topics to avoid
|
|
118
117
|
#
|
|
119
118
|
def get_bad_topics() -> List[str]:
|
|
120
119
|
"""
|
|
@@ -128,36 +127,3 @@ def get_bad_topics() -> List[str]:
|
|
|
128
127
|
"adult content",
|
|
129
128
|
"illegal activities",
|
|
130
129
|
]
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
#
|
|
134
|
-
# Additional database tool
|
|
135
|
-
#
|
|
136
|
-
class DBLoadSampleData:
|
|
137
|
-
"""
|
|
138
|
-
A tool to load a sample of data from the specified database table.
|
|
139
|
-
|
|
140
|
-
This tool fetches the first num_rows (default 25) rows from the given table
|
|
141
|
-
using a provided database query function.
|
|
142
|
-
"""
|
|
143
|
-
|
|
144
|
-
def __init__(self, load_data_tool: Callable):
|
|
145
|
-
"""
|
|
146
|
-
Initializes the DBLoadSampleData object with the provided load_data_tool function.
|
|
147
|
-
|
|
148
|
-
Args:
|
|
149
|
-
load_data_tool (Callable): A function to execute the SQL query.
|
|
150
|
-
"""
|
|
151
|
-
self.load_data_tool = load_data_tool
|
|
152
|
-
|
|
153
|
-
def __call__(self, table_name: str, num_rows: int = 25) -> Any:
|
|
154
|
-
"""
|
|
155
|
-
Fetches the first num_rows rows from the specified database table.
|
|
156
|
-
|
|
157
|
-
Args:
|
|
158
|
-
table_name (str): The name of the database table.
|
|
159
|
-
|
|
160
|
-
Returns:
|
|
161
|
-
Any: The result of the database query.
|
|
162
|
-
"""
|
|
163
|
-
return self.load_data_tool(f"SELECT * FROM {table_name} LIMIT {num_rows}")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.18
|
|
4
4
|
Summary: A Python package for creating AI Assistants and AI Agents with Vectara
|
|
5
5
|
Home-page: https://github.com/vectara/py-vectara-agentic
|
|
6
6
|
Author: Ofer Mendelevitch
|
|
@@ -17,7 +17,7 @@ Requires-Python: >=3.10
|
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
19
|
Requires-Dist: llama-index==0.11.20
|
|
20
|
-
Requires-Dist: llama-index-indices-managed-vectara==0.2.
|
|
20
|
+
Requires-Dist: llama-index-indices-managed-vectara==0.2.3
|
|
21
21
|
Requires-Dist: llama-index-agent-llm-compiler==0.2.0
|
|
22
22
|
Requires-Dist: llama-index-agent-openai==0.3.4
|
|
23
23
|
Requires-Dist: llama-index-llms-openai==0.2.16
|
|
@@ -33,6 +33,7 @@ Requires-Dist: llama-index-tools-database==0.2.0
|
|
|
33
33
|
Requires-Dist: llama-index-tools-google==0.2.0
|
|
34
34
|
Requires-Dist: llama-index-tools-tavily-research==0.2.0
|
|
35
35
|
Requires-Dist: llama-index-tools-neo4j==0.2.0
|
|
36
|
+
Requires-Dist: llama-index-tools-slack==0.2.0
|
|
36
37
|
Requires-Dist: tavily-python==0.5.0
|
|
37
38
|
Requires-Dist: yahoo-finance==1.4.0
|
|
38
39
|
Requires-Dist: openinference-instrumentation-llama-index==3.0.2
|
|
@@ -182,12 +183,21 @@ print(response)
|
|
|
182
183
|
- `stock_news`: provides news about a company
|
|
183
184
|
- `stock_analyst_recommendations`: provides stock analyst recommendations for a company.
|
|
184
185
|
|
|
185
|
-
|
|
186
|
+
4. **Database tools**: providing tools to inspect and query a database
|
|
186
187
|
- `list_tables`: list all tables in the database
|
|
187
188
|
- `describe_tables`: describe the schema of tables in the database
|
|
188
189
|
- `load_data`: returns data based on a SQL query
|
|
190
|
+
- `load_sample_data`: returns the first 25 rows of a table
|
|
191
|
+
- `load_unique_values`: returns the top unique values for a given column
|
|
189
192
|
|
|
190
|
-
|
|
193
|
+
In addition, we include various other tools from LlamaIndex ToolSpecs:
|
|
194
|
+
* Tavily search
|
|
195
|
+
* arxiv
|
|
196
|
+
* neo4j
|
|
197
|
+
* Google tools (including gmail, calendar, and search)
|
|
198
|
+
* Slack
|
|
199
|
+
|
|
200
|
+
Note that some of these tools may require API keys as environment variables
|
|
191
201
|
|
|
192
202
|
You can create your own tool directly from a Python function using the `create_tool()` method of the `ToolsFactory` class:
|
|
193
203
|
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
tests/test_agent.py,sha256=aQYYr_8hKlFiDgyI5Dd39TG5vkmDJe7F_nIzMTCLsTQ,2517
|
|
3
3
|
tests/test_tools.py,sha256=hDAlXkWKuXHnAjeQwMuTLTwNdRsM-xR7muBzFkZRefw,2942
|
|
4
|
-
vectara_agentic/__init__.py,sha256=
|
|
4
|
+
vectara_agentic/__init__.py,sha256=anqWxWDvo9azuZJN7qgh8CgTS13vCXtOtetc0wV7WOc,508
|
|
5
5
|
vectara_agentic/_callback.py,sha256=EexD7-Qx2lZuQk4kjzwvIJAyfIzroWKz2VaVPD4TTkM,4621
|
|
6
6
|
vectara_agentic/_observability.py,sha256=v0xxTk8KI8nVK2rpyGqOVhyva9ymqOmZK5brKqFOwMM,3828
|
|
7
|
-
vectara_agentic/_prompts.py,sha256=
|
|
7
|
+
vectara_agentic/_prompts.py,sha256=EMSiTriaKQLiD0gPiGFAriOII2cfr2_b-_8qkD7UUz0,5848
|
|
8
8
|
vectara_agentic/agent.py,sha256=9nzPVb16wpeT5RiWQJiO5LuR9VTYp8yScKUqqgem7h8,19963
|
|
9
9
|
vectara_agentic/agent_endpoint.py,sha256=I3zTEezbAiNeW5I41r0NjIaR8Ucn4oe1XVcALekakaA,1959
|
|
10
|
-
vectara_agentic/
|
|
11
|
-
vectara_agentic/
|
|
10
|
+
vectara_agentic/db_tools.py,sha256=QFMU1A08n-ql4eVygfp-RtSKrPATq3JtPUTIr5nZZIQ,2604
|
|
11
|
+
vectara_agentic/tools.py,sha256=HLAiBglGEkrOBXmUK4EKi60hNDmzhHGwK9855HxcViQ,21590
|
|
12
|
+
vectara_agentic/tools_catalog.py,sha256=5NlJypdu0IKa7mODxVOwo05lw3PqQJtSl_ZOsUDH_TA,3986
|
|
12
13
|
vectara_agentic/types.py,sha256=FbZXc5oPje6kdimfrksDc8F-tYHSLK8ReAv7O291YkI,1131
|
|
13
14
|
vectara_agentic/utils.py,sha256=BCd5tI9LKVXuPc4WsxGwgbouLcWr200JDWSsGNUwZg0,3822
|
|
14
|
-
vectara_agentic-0.1.
|
|
15
|
-
vectara_agentic-0.1.
|
|
16
|
-
vectara_agentic-0.1.
|
|
17
|
-
vectara_agentic-0.1.
|
|
18
|
-
vectara_agentic-0.1.
|
|
15
|
+
vectara_agentic-0.1.18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
16
|
+
vectara_agentic-0.1.18.dist-info/METADATA,sha256=1lsOej02Xt3sMXFgLO1JGpEXY26U6GUoSxjR0bWKYFo,13990
|
|
17
|
+
vectara_agentic-0.1.18.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
|
18
|
+
vectara_agentic-0.1.18.dist-info/top_level.txt,sha256=Y7TQTFdOYGYodQRltUGRieZKIYuzeZj2kHqAUpfCUfg,22
|
|
19
|
+
vectara_agentic-0.1.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|