vectara-agentic 0.2.12__py3-none-any.whl → 0.2.13__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.
- tests/test_agent.py +18 -1
- tests/test_agent_planning.py +0 -9
- tests/test_agent_type.py +40 -0
- tests/test_tools.py +139 -41
- tests/test_vectara_llms.py +77 -0
- vectara_agentic/_prompts.py +6 -8
- vectara_agentic/_version.py +1 -1
- vectara_agentic/agent.py +239 -78
- vectara_agentic/tools.py +209 -140
- vectara_agentic/utils.py +74 -46
- {vectara_agentic-0.2.12.dist-info → vectara_agentic-0.2.13.dist-info}/METADATA +335 -230
- {vectara_agentic-0.2.12.dist-info → vectara_agentic-0.2.13.dist-info}/RECORD +15 -14
- {vectara_agentic-0.2.12.dist-info → vectara_agentic-0.2.13.dist-info}/WHEEL +1 -1
- {vectara_agentic-0.2.12.dist-info → vectara_agentic-0.2.13.dist-info}/licenses/LICENSE +0 -0
- {vectara_agentic-0.2.12.dist-info → vectara_agentic-0.2.13.dist-info}/top_level.txt +0 -0
tests/test_agent.py
CHANGED
|
@@ -7,6 +7,9 @@ from vectara_agentic.agent_config import AgentConfig
|
|
|
7
7
|
from vectara_agentic.types import ModelProvider, ObserverType
|
|
8
8
|
from vectara_agentic.tools import ToolsFactory
|
|
9
9
|
|
|
10
|
+
from vectara_agentic._prompts import GENERAL_INSTRUCTIONS
|
|
11
|
+
|
|
12
|
+
|
|
10
13
|
def mult(x: float, y: float) -> float:
|
|
11
14
|
return x * y
|
|
12
15
|
|
|
@@ -24,7 +27,7 @@ class TestAgentPackage(unittest.TestCase):
|
|
|
24
27
|
+ " with Always do as your mother tells you!"
|
|
25
28
|
)
|
|
26
29
|
self.assertEqual(
|
|
27
|
-
_get_prompt(prompt_template, topic, custom_instructions), expected_output
|
|
30
|
+
_get_prompt(prompt_template, GENERAL_INSTRUCTIONS, topic, custom_instructions), expected_output
|
|
28
31
|
)
|
|
29
32
|
|
|
30
33
|
def test_agent_init(self):
|
|
@@ -120,6 +123,20 @@ class TestAgentPackage(unittest.TestCase):
|
|
|
120
123
|
res = agent.chat("multiply the results of the last two questions. Output only the answer.")
|
|
121
124
|
self.assertEqual(res.response, "1050")
|
|
122
125
|
|
|
126
|
+
def test_custom_general_instruction(self):
|
|
127
|
+
general_instructions = "Always respond with 'I DIDNT DO IT'"
|
|
128
|
+
agent = Agent.from_corpus(
|
|
129
|
+
tool_name="RAG Tool",
|
|
130
|
+
vectara_corpus_key="corpus_key",
|
|
131
|
+
vectara_api_key="api_key",
|
|
132
|
+
data_description="information",
|
|
133
|
+
assistant_specialty="question answering",
|
|
134
|
+
general_instructions=general_instructions,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
res = agent.chat("What is the meaning of the universe?")
|
|
138
|
+
self.assertEqual(res.response, "I DIDNT DO IT")
|
|
139
|
+
|
|
123
140
|
|
|
124
141
|
if __name__ == "__main__":
|
|
125
142
|
unittest.main()
|
tests/test_agent_planning.py
CHANGED
|
@@ -4,26 +4,17 @@ from vectara_agentic.agent_config import AgentConfig
|
|
|
4
4
|
from vectara_agentic.agent import Agent
|
|
5
5
|
from vectara_agentic.tools import VectaraToolFactory
|
|
6
6
|
|
|
7
|
-
from pydantic import Field, BaseModel
|
|
8
|
-
|
|
9
|
-
|
|
10
7
|
# SETUP speical test account credentials for vectara
|
|
11
8
|
# It's okay to expose these credentials in the test code
|
|
12
9
|
vectara_corpus_key = "vectara-docs_1"
|
|
13
10
|
vectara_api_key = 'zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA'
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
class QueryArgs(BaseModel):
|
|
17
|
-
query: str = Field(..., description="The user query, always in the form of a question.")
|
|
18
|
-
|
|
19
|
-
|
|
20
12
|
vec_factory = VectaraToolFactory(vectara_api_key=vectara_api_key,
|
|
21
13
|
vectara_corpus_key=vectara_corpus_key)
|
|
22
14
|
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
|
|
23
15
|
ask_vectara = vec_factory.create_rag_tool(
|
|
24
16
|
tool_name = "ask_vectara",
|
|
25
17
|
tool_description = "This tool can respond to questions about Vectara.",
|
|
26
|
-
tool_args_schema = QueryArgs,
|
|
27
18
|
reranker = "multilingual_reranker_v1", rerank_k = 100, rerank_cutoff = 0.1,
|
|
28
19
|
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
|
29
20
|
summary_num_results = 10,
|
tests/test_agent_type.py
CHANGED
|
@@ -9,6 +9,7 @@ import nest_asyncio
|
|
|
9
9
|
nest_asyncio.apply()
|
|
10
10
|
|
|
11
11
|
def mult(x: float, y: float) -> float:
|
|
12
|
+
"Multiply two numbers"
|
|
12
13
|
return x * y
|
|
13
14
|
|
|
14
15
|
|
|
@@ -30,6 +31,12 @@ react_config_together = AgentConfig(
|
|
|
30
31
|
tool_llm_provider=ModelProvider.TOGETHER,
|
|
31
32
|
)
|
|
32
33
|
|
|
34
|
+
react_config_groq = AgentConfig(
|
|
35
|
+
agent_type=AgentType.REACT,
|
|
36
|
+
main_llm_provider=ModelProvider.GROQ,
|
|
37
|
+
tool_llm_provider=ModelProvider.GROQ,
|
|
38
|
+
)
|
|
39
|
+
|
|
33
40
|
fc_config_anthropic = AgentConfig(
|
|
34
41
|
agent_type=AgentType.FUNCTION_CALLING,
|
|
35
42
|
main_llm_provider=ModelProvider.ANTHROPIC,
|
|
@@ -48,6 +55,12 @@ fc_config_together = AgentConfig(
|
|
|
48
55
|
tool_llm_provider=ModelProvider.TOGETHER,
|
|
49
56
|
)
|
|
50
57
|
|
|
58
|
+
fc_config_groq = AgentConfig(
|
|
59
|
+
agent_type=AgentType.FUNCTION_CALLING,
|
|
60
|
+
main_llm_provider=ModelProvider.GROQ,
|
|
61
|
+
tool_llm_provider=ModelProvider.GROQ,
|
|
62
|
+
)
|
|
63
|
+
|
|
51
64
|
|
|
52
65
|
openai_config = AgentConfig(
|
|
53
66
|
agent_type=AgentType.OPENAI,
|
|
@@ -125,6 +138,33 @@ class TestAgentType(unittest.TestCase):
|
|
|
125
138
|
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
126
139
|
self.assertIn("1050", res.response)
|
|
127
140
|
|
|
141
|
+
def test_groq(self):
|
|
142
|
+
tools = [ToolsFactory().create_tool(mult)]
|
|
143
|
+
topic = "AI topic"
|
|
144
|
+
instructions = "Always do as your father tells you, if your mother agrees!"
|
|
145
|
+
|
|
146
|
+
agent = Agent(
|
|
147
|
+
agent_config=react_config_groq,
|
|
148
|
+
tools=tools,
|
|
149
|
+
topic=topic,
|
|
150
|
+
custom_instructions=instructions,
|
|
151
|
+
)
|
|
152
|
+
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
153
|
+
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
154
|
+
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
155
|
+
self.assertIn("1050", res.response)
|
|
156
|
+
|
|
157
|
+
agent = Agent(
|
|
158
|
+
agent_config=fc_config_groq,
|
|
159
|
+
tools=tools,
|
|
160
|
+
topic=topic,
|
|
161
|
+
custom_instructions=instructions,
|
|
162
|
+
)
|
|
163
|
+
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
164
|
+
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
165
|
+
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
166
|
+
self.assertIn("1050", res.response)
|
|
167
|
+
|
|
128
168
|
def test_anthropic(self):
|
|
129
169
|
tools = [ToolsFactory().create_tool(mult)]
|
|
130
170
|
topic = "AI topic"
|
tests/test_tools.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import unittest
|
|
2
|
-
|
|
3
2
|
from pydantic import Field, BaseModel
|
|
4
3
|
|
|
5
4
|
from vectara_agentic.tools import (
|
|
@@ -13,83 +12,118 @@ from vectara_agentic.agent_config import AgentConfig
|
|
|
13
12
|
|
|
14
13
|
from llama_index.core.tools import FunctionTool
|
|
15
14
|
|
|
15
|
+
# Special test account credentials for Vectara
|
|
16
|
+
vectara_corpus_key = "vectara-docs_1"
|
|
17
|
+
vectara_api_key = "zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA"
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
class TestToolsPackage(unittest.TestCase):
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
vectara_api_key = "api_key"
|
|
21
|
+
|
|
22
|
+
def test_vectara_rag_tool(self):
|
|
21
23
|
vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
|
|
22
24
|
|
|
23
25
|
self.assertEqual(vectara_corpus_key, vec_factory.vectara_corpus_key)
|
|
24
26
|
self.assertEqual(vectara_api_key, vec_factory.vectara_api_key)
|
|
25
27
|
|
|
26
|
-
class QueryToolArgs(BaseModel):
|
|
27
|
-
query: str = Field(description="The user query")
|
|
28
|
-
|
|
29
28
|
query_tool = vec_factory.create_rag_tool(
|
|
30
29
|
tool_name="rag_tool",
|
|
31
30
|
tool_description="""
|
|
32
31
|
Returns a response (str) to the user query based on the data in this corpus.
|
|
33
32
|
""",
|
|
34
|
-
tool_args_schema=QueryToolArgs,
|
|
35
33
|
)
|
|
36
34
|
|
|
37
35
|
self.assertIsInstance(query_tool, VectaraTool)
|
|
38
36
|
self.assertIsInstance(query_tool, FunctionTool)
|
|
39
37
|
self.assertEqual(query_tool.metadata.tool_type, ToolType.QUERY)
|
|
40
38
|
|
|
39
|
+
res = query_tool(query="What is Vectara?")
|
|
40
|
+
self.assertIn("Vectara is an end-to-end platform", str(res))
|
|
41
|
+
|
|
42
|
+
def test_vectara_search_tool(self):
|
|
43
|
+
vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
|
|
44
|
+
|
|
41
45
|
search_tool = vec_factory.create_search_tool(
|
|
42
46
|
tool_name="search_tool",
|
|
43
|
-
tool_description=""
|
|
44
|
-
Returns a list of documents (str) that match the user query.
|
|
45
|
-
""",
|
|
46
|
-
tool_args_schema=QueryToolArgs,
|
|
47
|
+
tool_description="Returns a list of documents (str) that match the user query.",
|
|
47
48
|
)
|
|
48
49
|
self.assertIsInstance(search_tool, VectaraTool)
|
|
49
50
|
self.assertIsInstance(search_tool, FunctionTool)
|
|
50
51
|
self.assertEqual(search_tool.metadata.tool_type, ToolType.QUERY)
|
|
52
|
+
self.assertIn("summarize", search_tool.metadata.description)
|
|
53
|
+
|
|
54
|
+
res = search_tool(query="What is Vectara?")
|
|
55
|
+
self.assertIn("https-docs-vectara-com-docs", str(res))
|
|
56
|
+
|
|
57
|
+
search_tool = vec_factory.create_search_tool(
|
|
58
|
+
tool_name="search_tool",
|
|
59
|
+
tool_description="Returns a list of documents (str) that match the user query.",
|
|
60
|
+
summarize_docs=False,
|
|
61
|
+
)
|
|
62
|
+
self.assertIsInstance(search_tool, VectaraTool)
|
|
63
|
+
self.assertIsInstance(search_tool, FunctionTool)
|
|
64
|
+
self.assertEqual(search_tool.metadata.tool_type, ToolType.QUERY)
|
|
65
|
+
self.assertNotIn("summarize", search_tool.metadata.description)
|
|
66
|
+
|
|
67
|
+
res = search_tool(query="What is Vectara?")
|
|
68
|
+
self.assertIn("https-docs-vectara-com-docs", str(res))
|
|
69
|
+
|
|
70
|
+
search_tool = vec_factory.create_search_tool(
|
|
71
|
+
tool_name="search_tool",
|
|
72
|
+
tool_description="Returns a list of documents (str) that match the user query.",
|
|
73
|
+
summarize_docs=True,
|
|
74
|
+
)
|
|
75
|
+
self.assertIsInstance(search_tool, VectaraTool)
|
|
76
|
+
self.assertIsInstance(search_tool, FunctionTool)
|
|
77
|
+
self.assertEqual(search_tool.metadata.tool_type, ToolType.QUERY)
|
|
78
|
+
self.assertNotIn("summarize", search_tool.metadata.description)
|
|
79
|
+
|
|
80
|
+
res = search_tool(query="What is Vectara?")
|
|
81
|
+
self.assertIn("summary: 'Vectara is", str(res))
|
|
51
82
|
|
|
52
83
|
def test_vectara_tool_validation(self):
|
|
53
|
-
vectara_corpus_key = "corpus_key"
|
|
54
|
-
vectara_api_key = "api_key"
|
|
55
84
|
vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
|
|
56
85
|
|
|
57
86
|
class QueryToolArgs(BaseModel):
|
|
58
|
-
query: str = Field(description="The user query")
|
|
59
|
-
year: int = Field(
|
|
60
|
-
description="The year of the document",
|
|
61
|
-
example=2023,
|
|
62
|
-
)
|
|
63
87
|
ticker: str = Field(
|
|
64
|
-
description="The
|
|
65
|
-
|
|
88
|
+
description="The ticker symbol for the company",
|
|
89
|
+
examples=["AAPL", "GOOG"],
|
|
90
|
+
)
|
|
91
|
+
year: int | str = Field(
|
|
92
|
+
default=None,
|
|
93
|
+
description="The year this query relates to. An integer between 2015 and 2024 or a string specifying a condition on the year",
|
|
94
|
+
examples=[
|
|
95
|
+
2020,
|
|
96
|
+
">2021",
|
|
97
|
+
"<2023",
|
|
98
|
+
">=2021",
|
|
99
|
+
"<=2023",
|
|
100
|
+
"[2021, 2023]",
|
|
101
|
+
"[2021, 2023)",
|
|
102
|
+
],
|
|
66
103
|
)
|
|
67
104
|
|
|
68
105
|
query_tool = vec_factory.create_rag_tool(
|
|
69
106
|
tool_name="rag_tool",
|
|
70
|
-
tool_description=""
|
|
71
|
-
Returns a response (str) to the user query based on the data in this corpus.
|
|
72
|
-
""",
|
|
107
|
+
tool_description="Returns a response (str) to the user query based on the data in this corpus.",
|
|
73
108
|
tool_args_schema=QueryToolArgs,
|
|
74
109
|
)
|
|
110
|
+
|
|
75
111
|
res = query_tool(
|
|
76
112
|
query="What is the stock price?",
|
|
77
113
|
the_year=2023,
|
|
78
114
|
)
|
|
79
|
-
self.assertIn("
|
|
115
|
+
self.assertIn("got an unexpected keyword argument 'the_year'", str(res))
|
|
80
116
|
|
|
81
117
|
search_tool = vec_factory.create_search_tool(
|
|
82
118
|
tool_name="search_tool",
|
|
83
|
-
tool_description=""
|
|
84
|
-
Returns a list of documents (str) that match the user query.
|
|
85
|
-
""",
|
|
119
|
+
tool_description="Returns a list of documents (str) that match the user query.",
|
|
86
120
|
tool_args_schema=QueryToolArgs,
|
|
87
121
|
)
|
|
88
122
|
res = search_tool(
|
|
89
123
|
query="What is the stock price?",
|
|
90
124
|
the_year=2023,
|
|
91
125
|
)
|
|
92
|
-
self.assertIn("
|
|
126
|
+
self.assertIn("got an unexpected keyword argument 'the_year'", str(res))
|
|
93
127
|
|
|
94
128
|
def test_tool_factory(self):
|
|
95
129
|
def mult(x: float, y: float) -> float:
|
|
@@ -104,20 +138,84 @@ class TestToolsPackage(unittest.TestCase):
|
|
|
104
138
|
def test_llama_index_tools(self):
|
|
105
139
|
tools_factory = ToolsFactory()
|
|
106
140
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
141
|
+
for name, spec in [
|
|
142
|
+
("arxiv", "ArxivToolSpec"),
|
|
143
|
+
("yahoo_finance", "YahooFinanceToolSpec"),
|
|
144
|
+
("wikipedia", "WikipediaToolSpec"),
|
|
145
|
+
]:
|
|
146
|
+
tool = tools_factory.get_llama_index_tools(
|
|
147
|
+
tool_package_name=name, tool_spec_name=spec
|
|
148
|
+
)[0]
|
|
149
|
+
self.assertIsInstance(tool, VectaraTool)
|
|
150
|
+
self.assertIsInstance(tool, FunctionTool)
|
|
151
|
+
self.assertEqual(tool.metadata.tool_type, ToolType.QUERY)
|
|
152
|
+
|
|
153
|
+
def test_tool_with_many_arguments(self):
|
|
154
|
+
vectara_corpus_key = "corpus_key"
|
|
155
|
+
vectara_api_key = "api_key"
|
|
156
|
+
vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
|
|
110
157
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
158
|
+
class QueryToolArgs(BaseModel):
|
|
159
|
+
arg1: str = Field(description="the first argument", examples=["val1"])
|
|
160
|
+
arg2: str = Field(description="the second argument", examples=["val2"])
|
|
161
|
+
arg3: str = Field(description="the third argument", examples=["val3"])
|
|
162
|
+
arg4: str = Field(description="the fourth argument", examples=["val4"])
|
|
163
|
+
arg5: str = Field(description="the fifth argument", examples=["val5"])
|
|
164
|
+
arg6: str = Field(description="the sixth argument", examples=["val6"])
|
|
165
|
+
arg7: str = Field(description="the seventh argument", examples=["val7"])
|
|
166
|
+
arg8: str = Field(description="the eighth argument", examples=["val8"])
|
|
167
|
+
arg9: str = Field(description="the ninth argument", examples=["val9"])
|
|
168
|
+
arg10: str = Field(description="the tenth argument", examples=["val10"])
|
|
169
|
+
arg11: str = Field(description="the eleventh argument", examples=["val11"])
|
|
170
|
+
arg12: str = Field(description="the twelfth argument", examples=["val12"])
|
|
171
|
+
arg13: str = Field(
|
|
172
|
+
description="the thirteenth argument", examples=["val13"]
|
|
173
|
+
)
|
|
174
|
+
arg14: str = Field(
|
|
175
|
+
description="the fourteenth argument", examples=["val14"]
|
|
176
|
+
)
|
|
177
|
+
arg15: str = Field(description="the fifteenth argument", examples=["val15"])
|
|
114
178
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
179
|
+
query_tool_1 = vec_factory.create_rag_tool(
|
|
180
|
+
tool_name="rag_tool",
|
|
181
|
+
tool_description="""
|
|
182
|
+
A dummy tool that takes 20 arguments and returns a response (str) to the user query based on the data in this corpus.
|
|
183
|
+
We are using this tool to test the tool factory works and does not crash with OpenAI.
|
|
184
|
+
""",
|
|
185
|
+
tool_args_schema=QueryToolArgs,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
config = AgentConfig()
|
|
189
|
+
agent = Agent(
|
|
190
|
+
tools=[query_tool_1],
|
|
191
|
+
topic="Sample topic",
|
|
192
|
+
custom_instructions="Call the tool with 20 arguments",
|
|
193
|
+
agent_config=config,
|
|
194
|
+
)
|
|
195
|
+
res = agent.chat("What is the stock price?")
|
|
196
|
+
self.assertIn("maximum length of 1024 characters", str(res))
|
|
197
|
+
|
|
198
|
+
vec_factory = VectaraToolFactory(
|
|
199
|
+
vectara_corpus_key, vectara_api_key, compact_docstring=True
|
|
200
|
+
)
|
|
201
|
+
query_tool_2 = vec_factory.create_rag_tool(
|
|
202
|
+
tool_name="rag_tool",
|
|
203
|
+
tool_description="""
|
|
204
|
+
A dummy tool that takes 15 arguments and returns a response (str) to the user query based on the data in this corpus.
|
|
205
|
+
We are using this tool to test the tool factory works and doesn not crash with OpenAI.
|
|
206
|
+
""",
|
|
207
|
+
tool_args_schema=QueryToolArgs,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
config = AgentConfig()
|
|
211
|
+
agent = Agent(
|
|
212
|
+
tools=[query_tool_2],
|
|
213
|
+
topic="Sample topic",
|
|
214
|
+
custom_instructions="Call the tool with 20 arguments",
|
|
215
|
+
agent_config=config,
|
|
216
|
+
)
|
|
217
|
+
res = agent.chat("What is the stock price?")
|
|
218
|
+
self.assertIn("stock price", str(res))
|
|
121
219
|
|
|
122
220
|
def test_public_repo(self):
|
|
123
221
|
vectara_corpus_key = "vectara-docs_1"
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
from vectara_agentic.tools import (
|
|
4
|
+
VectaraTool,
|
|
5
|
+
VectaraToolFactory,
|
|
6
|
+
ToolType,
|
|
7
|
+
)
|
|
8
|
+
from llama_index.core.tools import FunctionTool
|
|
9
|
+
|
|
10
|
+
# Special test account credentials for Vectara
|
|
11
|
+
vectara_corpus_key = "vectara-docs_1"
|
|
12
|
+
vectara_api_key = "zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class TestLLMPackage(unittest.TestCase):
|
|
16
|
+
|
|
17
|
+
def test_vectara_openai(self):
|
|
18
|
+
vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
|
|
19
|
+
|
|
20
|
+
self.assertEqual(vectara_corpus_key, vec_factory.vectara_corpus_key)
|
|
21
|
+
self.assertEqual(vectara_api_key, vec_factory.vectara_api_key)
|
|
22
|
+
|
|
23
|
+
query_tool = vec_factory.create_rag_tool(
|
|
24
|
+
tool_name="rag_tool",
|
|
25
|
+
tool_description="""
|
|
26
|
+
Returns a response (str) to the user query based on the data in this corpus.
|
|
27
|
+
""",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
self.assertIsInstance(query_tool, VectaraTool)
|
|
31
|
+
self.assertIsInstance(query_tool, FunctionTool)
|
|
32
|
+
self.assertEqual(query_tool.metadata.tool_type, ToolType.QUERY)
|
|
33
|
+
|
|
34
|
+
res = query_tool(query="What is Vectara?")
|
|
35
|
+
self.assertIn("Vectara is an end-to-end platform", str(res))
|
|
36
|
+
|
|
37
|
+
query_tool = vec_factory.create_rag_tool(
|
|
38
|
+
tool_name="rag_tool",
|
|
39
|
+
tool_description="""
|
|
40
|
+
Returns a response (str) to the user query based on the data in this corpus.
|
|
41
|
+
""",
|
|
42
|
+
llm_name="gpt-4o-mini",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
self.assertIsInstance(query_tool, VectaraTool)
|
|
46
|
+
self.assertIsInstance(query_tool, FunctionTool)
|
|
47
|
+
self.assertEqual(query_tool.metadata.tool_type, ToolType.QUERY)
|
|
48
|
+
|
|
49
|
+
res = query_tool(query="What is Vectara?")
|
|
50
|
+
self.assertIn("Vectara is an end-to-end platform", str(res))
|
|
51
|
+
|
|
52
|
+
def test_vectara_mockingbird(self):
|
|
53
|
+
vec_factory = VectaraToolFactory(vectara_corpus_key, vectara_api_key)
|
|
54
|
+
|
|
55
|
+
query_tool = vec_factory.create_rag_tool(
|
|
56
|
+
tool_name="rag_tool",
|
|
57
|
+
tool_description="""
|
|
58
|
+
Returns a response (str) to the user query based on the data in this corpus.
|
|
59
|
+
""",
|
|
60
|
+
vectara_summarizer="mockingbird-1.0-2024-07-16",
|
|
61
|
+
)
|
|
62
|
+
res = query_tool(query="What is Vectara?")
|
|
63
|
+
self.assertIn("Vectara is an end-to-end platform", str(res))
|
|
64
|
+
|
|
65
|
+
query_tool = vec_factory.create_rag_tool(
|
|
66
|
+
tool_name="rag_tool",
|
|
67
|
+
tool_description="""
|
|
68
|
+
Returns a response (str) to the user query based on the data in this corpus.
|
|
69
|
+
""",
|
|
70
|
+
vectara_summarizer="mockingbird-2.0",
|
|
71
|
+
)
|
|
72
|
+
res = query_tool(query="What is Vectara?")
|
|
73
|
+
self.assertIn("Vectara is an end-to-end platform", str(res))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
unittest.main()
|
vectara_agentic/_prompts.py
CHANGED
|
@@ -42,7 +42,7 @@ GENERAL_INSTRUCTIONS = """
|
|
|
42
42
|
Before using the x_load_data with a SQL query, always follow these discovery steps:
|
|
43
43
|
- call the x_list_tables tool to list of available tables in the x database.
|
|
44
44
|
- Call the x_describe_tables tool to understand the schema of each table you want to query data from.
|
|
45
|
-
- Use the x_load_unique_values tool to
|
|
45
|
+
- Use the x_load_unique_values tool to retrieve the unique values in each column, before crafting any SQL query.
|
|
46
46
|
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.
|
|
47
47
|
- Use the x_load_sample_data tool to understand the column names, and typical values in each column.
|
|
48
48
|
- For x_load_data, if the tool response indicates the output data is too large, try to refine or refactor your query to return fewer rows.
|
|
@@ -52,7 +52,7 @@ GENERAL_INSTRUCTIONS = """
|
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
54
|
#
|
|
55
|
-
# For OpenAI and other agents that just require systems
|
|
55
|
+
# For OpenAI and other agents that just require a systems prompt
|
|
56
56
|
#
|
|
57
57
|
GENERAL_PROMPT_TEMPLATE = """
|
|
58
58
|
You are a helpful chatbot in conversation with a user, with expertise in {chat_topic}.
|
|
@@ -65,9 +65,7 @@ IMPORTANT - FOLLOW THESE INSTRUCTIONS CAREFULLY:
|
|
|
65
65
|
{INSTRUCTIONS}
|
|
66
66
|
{custom_instructions}
|
|
67
67
|
|
|
68
|
-
"""
|
|
69
|
-
"{INSTRUCTIONS}", GENERAL_INSTRUCTIONS
|
|
70
|
-
)
|
|
68
|
+
"""
|
|
71
69
|
|
|
72
70
|
#
|
|
73
71
|
# Custom REACT prompt
|
|
@@ -132,15 +130,14 @@ Answer: [your answer here (In the same language as the user's question)]
|
|
|
132
130
|
## Current Conversation
|
|
133
131
|
|
|
134
132
|
Below is the current conversation consisting of interleaving human and assistant messages.
|
|
135
|
-
"""
|
|
136
|
-
"{INSTRUCTIONS}", GENERAL_INSTRUCTIONS
|
|
137
|
-
)
|
|
133
|
+
"""
|
|
138
134
|
|
|
139
135
|
#
|
|
140
136
|
# Prompts for structured planning agent
|
|
141
137
|
#
|
|
142
138
|
STRUCTURED_PLANNER_INITIAL_PLAN_PROMPT = """\
|
|
143
139
|
Think step-by-step. Given a task and a set of tools, create a comprehensive, end-to-end plan to accomplish the task, using the tools.
|
|
140
|
+
Only use the tools that are relevant to completing the task.
|
|
144
141
|
Keep in mind not every task needs to be decomposed into multiple sub-tasks if it is simple enough.
|
|
145
142
|
The plan should end with a sub-task that can achieve the overall task.
|
|
146
143
|
|
|
@@ -152,6 +149,7 @@ Overall Task: {task}
|
|
|
152
149
|
|
|
153
150
|
STRUCTURED_PLANNER_PLAN_REFINE_PROMPT = """\
|
|
154
151
|
Think step-by-step. Given an overall task, a set of tools, and completed sub-tasks, update (if needed) the remaining sub-tasks so that the overall task can still be completed.
|
|
152
|
+
Only use the tools that are relevant to completing the task.
|
|
155
153
|
Do not add new sub-tasks that are not needed to achieve the overall task.
|
|
156
154
|
The final sub-task in the plan should be the one that can satisfy the overall task.
|
|
157
155
|
If you do update the plan, only create new sub-tasks that will replace the remaining sub-tasks, do NOT repeat tasks that are already completed.
|
vectara_agentic/_version.py
CHANGED