vectara-agentic 0.2.6__py3-none-any.whl → 0.2.7__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 +73 -69
- tests/test_agent_planning.py +47 -20
- tests/test_agent_type.py +84 -10
- tests/test_fallback.py +2 -2
- tests/test_private_llm.py +1 -1
- tests/test_tools.py +1 -1
- vectara_agentic/_version.py +1 -1
- vectara_agentic/agent.py +26 -8
- vectara_agentic/sub_query_workflow.py +16 -4
- vectara_agentic/tools.py +95 -74
- vectara_agentic/types.py +1 -0
- vectara_agentic/utils.py +48 -9
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.7.dist-info}/METADATA +1 -1
- vectara_agentic-0.2.7.dist-info/RECORD +28 -0
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.7.dist-info}/WHEEL +1 -1
- vectara_agentic-0.2.6.dist-info/RECORD +0 -28
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.7.dist-info}/licenses/LICENSE +0 -0
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.7.dist-info}/top_level.txt +0 -0
tests/test_agent.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import unittest
|
|
2
|
+
import threading
|
|
2
3
|
from datetime import date
|
|
3
4
|
|
|
4
5
|
from vectara_agentic.agent import _get_prompt, Agent, AgentType
|
|
@@ -6,9 +7,12 @@ from vectara_agentic.agent_config import AgentConfig
|
|
|
6
7
|
from vectara_agentic.types import ModelProvider, ObserverType
|
|
7
8
|
from vectara_agentic.tools import ToolsFactory
|
|
8
9
|
|
|
9
|
-
def mult(x, y):
|
|
10
|
+
def mult(x: float, y: float) -> float:
|
|
10
11
|
return x * y
|
|
11
12
|
|
|
13
|
+
|
|
14
|
+
ARIZE_LOCK = threading.Lock()
|
|
15
|
+
|
|
12
16
|
class TestAgentPackage(unittest.TestCase):
|
|
13
17
|
def test_get_prompt(self):
|
|
14
18
|
prompt_template = "{chat_topic} on {today} with {custom_instructions}"
|
|
@@ -41,38 +45,39 @@ class TestAgentPackage(unittest.TestCase):
|
|
|
41
45
|
)
|
|
42
46
|
|
|
43
47
|
def test_agent_config(self):
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
48
|
+
with ARIZE_LOCK:
|
|
49
|
+
tools = [ToolsFactory().create_tool(mult)]
|
|
50
|
+
topic = "AI topic"
|
|
51
|
+
instructions = "Always do as your father tells you, if your mother agrees!"
|
|
52
|
+
config = AgentConfig(
|
|
53
|
+
agent_type=AgentType.REACT,
|
|
54
|
+
main_llm_provider=ModelProvider.ANTHROPIC,
|
|
55
|
+
main_llm_model_name="claude-3-5-sonnet-20241022",
|
|
56
|
+
tool_llm_provider=ModelProvider.TOGETHER,
|
|
57
|
+
tool_llm_model_name="meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
58
|
+
observer=ObserverType.ARIZE_PHOENIX
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
agent = Agent(
|
|
62
|
+
tools=tools,
|
|
63
|
+
topic=topic,
|
|
64
|
+
custom_instructions=instructions,
|
|
65
|
+
agent_config=config
|
|
66
|
+
)
|
|
67
|
+
self.assertEqual(agent._topic, topic)
|
|
68
|
+
self.assertEqual(agent._custom_instructions, instructions)
|
|
69
|
+
self.assertEqual(agent.agent_type, AgentType.REACT)
|
|
70
|
+
self.assertEqual(agent.agent_config.observer, ObserverType.ARIZE_PHOENIX)
|
|
71
|
+
self.assertEqual(agent.agent_config.main_llm_provider, ModelProvider.ANTHROPIC)
|
|
72
|
+
self.assertEqual(agent.agent_config.tool_llm_provider, ModelProvider.TOGETHER)
|
|
73
|
+
|
|
74
|
+
# To run this test, you must have ANTHROPIC_API_KEY and TOGETHER_API_KEY in your environment
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
agent.chat(
|
|
77
|
+
"What is 5 times 10. Only give the answer, nothing else"
|
|
78
|
+
).response.replace("$", "\\$"),
|
|
79
|
+
"50",
|
|
80
|
+
)
|
|
76
81
|
|
|
77
82
|
def test_multiturn(self):
|
|
78
83
|
tools = [ToolsFactory().create_tool(mult)]
|
|
@@ -102,42 +107,41 @@ class TestAgentPackage(unittest.TestCase):
|
|
|
102
107
|
self.assertEqual(agent._topic, "question answering")
|
|
103
108
|
|
|
104
109
|
def test_serialization(self):
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded_again.agent_config.tool_llm_provider)
|
|
110
|
+
with ARIZE_LOCK:
|
|
111
|
+
config = AgentConfig(
|
|
112
|
+
agent_type=AgentType.REACT,
|
|
113
|
+
main_llm_provider=ModelProvider.ANTHROPIC,
|
|
114
|
+
tool_llm_provider=ModelProvider.TOGETHER,
|
|
115
|
+
observer=ObserverType.ARIZE_PHOENIX
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
agent = Agent.from_corpus(
|
|
119
|
+
tool_name="RAG Tool",
|
|
120
|
+
agent_config=config,
|
|
121
|
+
vectara_corpus_key="corpus_key",
|
|
122
|
+
vectara_api_key="api_key",
|
|
123
|
+
data_description="information",
|
|
124
|
+
assistant_specialty="question answering",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
agent_reloaded = agent.loads(agent.dumps())
|
|
128
|
+
agent_reloaded_again = agent_reloaded.loads(agent_reloaded.dumps())
|
|
129
|
+
|
|
130
|
+
self.assertIsInstance(agent_reloaded, Agent)
|
|
131
|
+
self.assertEqual(agent, agent_reloaded)
|
|
132
|
+
self.assertEqual(agent.agent_type, agent_reloaded.agent_type)
|
|
133
|
+
|
|
134
|
+
self.assertEqual(agent.agent_config.observer, agent_reloaded.agent_config.observer)
|
|
135
|
+
self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded.agent_config.main_llm_provider)
|
|
136
|
+
self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded.agent_config.tool_llm_provider)
|
|
137
|
+
|
|
138
|
+
self.assertIsInstance(agent_reloaded, Agent)
|
|
139
|
+
self.assertEqual(agent, agent_reloaded_again)
|
|
140
|
+
self.assertEqual(agent.agent_type, agent_reloaded_again.agent_type)
|
|
141
|
+
|
|
142
|
+
self.assertEqual(agent.agent_config.observer, agent_reloaded_again.agent_config.observer)
|
|
143
|
+
self.assertEqual(agent.agent_config.main_llm_provider, agent_reloaded_again.agent_config.main_llm_provider)
|
|
144
|
+
self.assertEqual(agent.agent_config.tool_llm_provider, agent_reloaded_again.agent_config.tool_llm_provider)
|
|
141
145
|
|
|
142
146
|
def test_chat_history(self):
|
|
143
147
|
tools = [ToolsFactory().create_tool(mult)]
|
tests/test_agent_planning.py
CHANGED
|
@@ -1,45 +1,72 @@
|
|
|
1
1
|
import unittest
|
|
2
2
|
|
|
3
|
-
from vectara_agentic.agent import Agent
|
|
4
3
|
from vectara_agentic.agent_config import AgentConfig
|
|
5
|
-
from vectara_agentic.
|
|
4
|
+
from vectara_agentic.agent import Agent
|
|
5
|
+
from vectara_agentic.tools import VectaraToolFactory
|
|
6
|
+
|
|
7
|
+
from pydantic import Field, BaseModel
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# SETUP speical test account credentials for vectara
|
|
11
|
+
# It's okay to expose these credentials in the test code
|
|
12
|
+
vectara_corpus_key = "vectara-docs_1"
|
|
13
|
+
vectara_api_key = 'zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA'
|
|
6
14
|
|
|
7
|
-
def mult(x, y):
|
|
8
|
-
return x * y
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
class QueryArgs(BaseModel):
|
|
17
|
+
query: str = Field(..., description="The user query, always in the form of a question.")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
vec_factory = VectaraToolFactory(vectara_api_key=vectara_api_key,
|
|
21
|
+
vectara_corpus_key=vectara_corpus_key)
|
|
22
|
+
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
|
|
23
|
+
ask_vectara = vec_factory.create_rag_tool(
|
|
24
|
+
tool_name = "ask_vectara",
|
|
25
|
+
tool_description = "This tool can respond to questions about Vectara.",
|
|
26
|
+
tool_args_schema = QueryArgs,
|
|
27
|
+
reranker = "multilingual_reranker_v1", rerank_k = 100, rerank_cutoff = 0.1,
|
|
28
|
+
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.005,
|
|
29
|
+
summary_num_results = 10,
|
|
30
|
+
vectara_summarizer = summarizer,
|
|
31
|
+
include_citations = True,
|
|
32
|
+
verbose=False,
|
|
33
|
+
)
|
|
12
34
|
|
|
13
35
|
class TestAgentPlanningPackage(unittest.TestCase):
|
|
14
36
|
|
|
15
37
|
def test_no_planning(self):
|
|
16
|
-
tools = [
|
|
17
|
-
topic = "
|
|
18
|
-
instructions = "
|
|
38
|
+
tools = [ask_vectara]
|
|
39
|
+
topic = "vectara"
|
|
40
|
+
instructions = "Answer user queries about Vectara."
|
|
41
|
+
|
|
42
|
+
query = "What is Vectara and what demos are available of the Vectara platform?"
|
|
19
43
|
agent = Agent(
|
|
20
44
|
tools=tools,
|
|
21
45
|
topic=topic,
|
|
22
46
|
custom_instructions=instructions,
|
|
23
|
-
agent_config
|
|
47
|
+
agent_config=AgentConfig(),
|
|
24
48
|
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
self.assertIn("
|
|
49
|
+
res = agent.chat(query)
|
|
50
|
+
self.assertIn("demos", res.response)
|
|
51
|
+
self.assertIn("Vectara", res.response)
|
|
28
52
|
|
|
29
53
|
def test_structured_planning(self):
|
|
30
|
-
tools = [
|
|
31
|
-
topic = "
|
|
32
|
-
instructions = "
|
|
54
|
+
tools = [ask_vectara]
|
|
55
|
+
topic = "vectara"
|
|
56
|
+
instructions = "Answer user queries about Vectara."
|
|
57
|
+
|
|
58
|
+
query = "What is Vectara and what demos are available of the Vectara platform?"
|
|
33
59
|
agent = Agent(
|
|
34
60
|
tools=tools,
|
|
35
61
|
topic=topic,
|
|
36
62
|
custom_instructions=instructions,
|
|
37
|
-
agent_config
|
|
38
|
-
use_structured_planning
|
|
63
|
+
agent_config=AgentConfig(),
|
|
64
|
+
use_structured_planning=True,
|
|
39
65
|
)
|
|
40
66
|
|
|
41
|
-
res = agent.chat(
|
|
42
|
-
self.assertIn("
|
|
67
|
+
res = agent.chat(query)
|
|
68
|
+
self.assertIn("demos", res.response)
|
|
69
|
+
self.assertIn("Vectara", res.response)
|
|
43
70
|
|
|
44
71
|
|
|
45
72
|
if __name__ == "__main__":
|
tests/test_agent_type.py
CHANGED
|
@@ -7,24 +7,48 @@ from vectara_agentic.types import ModelProvider
|
|
|
7
7
|
|
|
8
8
|
import nest_asyncio
|
|
9
9
|
nest_asyncio.apply()
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
def mult(x: float, y: float) -> float:
|
|
11
12
|
return x * y
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
react_config_anthropic = AgentConfig(
|
|
15
16
|
agent_type=AgentType.REACT,
|
|
16
17
|
main_llm_provider=ModelProvider.ANTHROPIC,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
tool_llm_provider=ModelProvider.ANTHROPIC,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
react_config_gemini = AgentConfig(
|
|
22
|
+
agent_type=AgentType.REACT,
|
|
23
|
+
main_llm_provider=ModelProvider.GEMINI,
|
|
24
|
+
tool_llm_provider=ModelProvider.GEMINI,
|
|
20
25
|
)
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
react_config_together = AgentConfig(
|
|
23
28
|
agent_type=AgentType.REACT,
|
|
29
|
+
main_llm_provider=ModelProvider.TOGETHER,
|
|
30
|
+
tool_llm_provider=ModelProvider.TOGETHER,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
fc_config_anthropic = AgentConfig(
|
|
34
|
+
agent_type=AgentType.FUNCTION_CALLING,
|
|
35
|
+
main_llm_provider=ModelProvider.ANTHROPIC,
|
|
36
|
+
tool_llm_provider=ModelProvider.ANTHROPIC,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
fc_config_gemini = AgentConfig(
|
|
40
|
+
agent_type=AgentType.FUNCTION_CALLING,
|
|
24
41
|
main_llm_provider=ModelProvider.GEMINI,
|
|
25
42
|
tool_llm_provider=ModelProvider.GEMINI,
|
|
26
43
|
)
|
|
27
44
|
|
|
45
|
+
fc_config_together = AgentConfig(
|
|
46
|
+
agent_type=AgentType.FUNCTION_CALLING,
|
|
47
|
+
main_llm_provider=ModelProvider.TOGETHER,
|
|
48
|
+
tool_llm_provider=ModelProvider.TOGETHER,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
28
52
|
openai_config = AgentConfig(
|
|
29
53
|
agent_type=AgentType.OPENAI,
|
|
30
54
|
)
|
|
@@ -47,28 +71,78 @@ class TestAgentType(unittest.TestCase):
|
|
|
47
71
|
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
48
72
|
self.assertIn("1050", res.response)
|
|
49
73
|
|
|
50
|
-
def
|
|
74
|
+
def test_gemini(self):
|
|
75
|
+
tools = [ToolsFactory().create_tool(mult)]
|
|
76
|
+
topic = "AI topic"
|
|
77
|
+
instructions = "Always do as your father tells you, if your mother agrees!"
|
|
78
|
+
|
|
79
|
+
agent = Agent(
|
|
80
|
+
agent_config=react_config_gemini,
|
|
81
|
+
tools=tools,
|
|
82
|
+
topic=topic,
|
|
83
|
+
custom_instructions=instructions,
|
|
84
|
+
)
|
|
85
|
+
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
86
|
+
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
87
|
+
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
88
|
+
self.assertIn("1050", res.response)
|
|
89
|
+
|
|
90
|
+
agent = Agent(
|
|
91
|
+
agent_config=fc_config_gemini,
|
|
92
|
+
tools=tools,
|
|
93
|
+
topic=topic,
|
|
94
|
+
custom_instructions=instructions,
|
|
95
|
+
)
|
|
96
|
+
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
97
|
+
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
98
|
+
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
99
|
+
self.assertIn("1050", res.response)
|
|
100
|
+
|
|
101
|
+
def test_together(self):
|
|
51
102
|
tools = [ToolsFactory().create_tool(mult)]
|
|
52
103
|
topic = "AI topic"
|
|
53
104
|
instructions = "Always do as your father tells you, if your mother agrees!"
|
|
105
|
+
|
|
54
106
|
agent = Agent(
|
|
55
|
-
agent_config=
|
|
107
|
+
agent_config=react_config_together,
|
|
56
108
|
tools=tools,
|
|
57
109
|
topic=topic,
|
|
58
110
|
custom_instructions=instructions,
|
|
59
111
|
)
|
|
112
|
+
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
113
|
+
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
114
|
+
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
115
|
+
self.assertIn("1050", res.response)
|
|
60
116
|
|
|
117
|
+
agent = Agent(
|
|
118
|
+
agent_config=fc_config_together,
|
|
119
|
+
tools=tools,
|
|
120
|
+
topic=topic,
|
|
121
|
+
custom_instructions=instructions,
|
|
122
|
+
)
|
|
61
123
|
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
62
124
|
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
63
125
|
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
64
126
|
self.assertIn("1050", res.response)
|
|
65
127
|
|
|
66
|
-
def
|
|
128
|
+
def test_anthropic(self):
|
|
67
129
|
tools = [ToolsFactory().create_tool(mult)]
|
|
68
130
|
topic = "AI topic"
|
|
69
131
|
instructions = "Always do as your father tells you, if your mother agrees!"
|
|
132
|
+
|
|
133
|
+
agent = Agent(
|
|
134
|
+
agent_config=react_config_anthropic,
|
|
135
|
+
tools=tools,
|
|
136
|
+
topic=topic,
|
|
137
|
+
custom_instructions=instructions,
|
|
138
|
+
)
|
|
139
|
+
agent.chat("What is 5 times 10. Only give the answer, nothing else")
|
|
140
|
+
agent.chat("what is 3 times 7. Only give the answer, nothing else")
|
|
141
|
+
res = agent.chat("multiply the results of the last two multiplications. Only give the answer, nothing else.")
|
|
142
|
+
self.assertIn("1050", res.response)
|
|
143
|
+
|
|
70
144
|
agent = Agent(
|
|
71
|
-
agent_config=
|
|
145
|
+
agent_config=fc_config_anthropic,
|
|
72
146
|
tools=tools,
|
|
73
147
|
topic=topic,
|
|
74
148
|
custom_instructions=instructions,
|
tests/test_fallback.py
CHANGED
|
@@ -40,8 +40,8 @@ class TestFallback(unittest.TestCase):
|
|
|
40
40
|
cls.flask_process.send_signal(signal.SIGINT)
|
|
41
41
|
cls.flask_process.wait()
|
|
42
42
|
|
|
43
|
-
def
|
|
44
|
-
def mult(x, y):
|
|
43
|
+
def test_fallback_from_private(self):
|
|
44
|
+
def mult(x: float, y: float) -> float:
|
|
45
45
|
return x * y
|
|
46
46
|
|
|
47
47
|
tools = [ToolsFactory().create_tool(mult)]
|
tests/test_private_llm.py
CHANGED
tests/test_tools.py
CHANGED
vectara_agentic/_version.py
CHANGED
vectara_agentic/agent.py
CHANGED
|
@@ -21,7 +21,7 @@ from pydantic import Field, create_model, ValidationError
|
|
|
21
21
|
from llama_index.core.memory import ChatMemoryBuffer
|
|
22
22
|
from llama_index.core.llms import ChatMessage, MessageRole
|
|
23
23
|
from llama_index.core.tools import FunctionTool
|
|
24
|
-
from llama_index.core.agent import ReActAgent, StructuredPlannerAgent
|
|
24
|
+
from llama_index.core.agent import ReActAgent, StructuredPlannerAgent, FunctionCallingAgent
|
|
25
25
|
from llama_index.core.agent.react.formatter import ReActChatFormatter
|
|
26
26
|
from llama_index.agent.llm_compiler import LLMCompilerAgentWorker
|
|
27
27
|
from llama_index.agent.lats import LATSAgentWorker
|
|
@@ -277,7 +277,19 @@ class Agent:
|
|
|
277
277
|
llm = get_llm(LLMRole.MAIN, config=config)
|
|
278
278
|
llm.callback_manager = llm_callback_manager
|
|
279
279
|
|
|
280
|
-
if agent_type == AgentType.
|
|
280
|
+
if agent_type == AgentType.FUNCTION_CALLING:
|
|
281
|
+
prompt = _get_prompt(GENERAL_PROMPT_TEMPLATE, self._topic, self._custom_instructions)
|
|
282
|
+
agent = FunctionCallingAgent.from_tools(
|
|
283
|
+
tools=self.tools,
|
|
284
|
+
llm=llm,
|
|
285
|
+
memory=self.memory,
|
|
286
|
+
verbose=self.verbose,
|
|
287
|
+
max_function_calls=config.max_reasoning_steps,
|
|
288
|
+
callback_manager=llm_callback_manager,
|
|
289
|
+
system_prompt = prompt,
|
|
290
|
+
allow_parallel_tool_calls=True,
|
|
291
|
+
)
|
|
292
|
+
elif agent_type == AgentType.REACT:
|
|
281
293
|
prompt = _get_prompt(REACT_PROMPT_TEMPLATE, self._topic, self._custom_instructions)
|
|
282
294
|
agent = ReActAgent.from_tools(
|
|
283
295
|
tools=self.tools,
|
|
@@ -295,7 +307,7 @@ class Agent:
|
|
|
295
307
|
llm=llm,
|
|
296
308
|
memory=self.memory,
|
|
297
309
|
verbose=self.verbose,
|
|
298
|
-
|
|
310
|
+
callback_manager=llm_callback_manager,
|
|
299
311
|
max_function_calls=config.max_reasoning_steps,
|
|
300
312
|
system_prompt=prompt,
|
|
301
313
|
)
|
|
@@ -304,7 +316,7 @@ class Agent:
|
|
|
304
316
|
tools=self.tools,
|
|
305
317
|
llm=llm,
|
|
306
318
|
verbose=self.verbose,
|
|
307
|
-
|
|
319
|
+
callback_manager=llm_callback_manager,
|
|
308
320
|
)
|
|
309
321
|
agent_worker.system_prompt = _get_prompt(
|
|
310
322
|
_get_llm_compiler_prompt(agent_worker.system_prompt, self._topic, self._custom_instructions),
|
|
@@ -322,7 +334,7 @@ class Agent:
|
|
|
322
334
|
num_expansions=3,
|
|
323
335
|
max_rollouts=-1,
|
|
324
336
|
verbose=self.verbose,
|
|
325
|
-
|
|
337
|
+
callback_manager=llm_callback_manager,
|
|
326
338
|
)
|
|
327
339
|
prompt = _get_prompt(REACT_PROMPT_TEMPLATE, self._topic, self._custom_instructions)
|
|
328
340
|
agent_worker.chat_formatter = ReActChatFormatter(system_header=prompt)
|
|
@@ -707,6 +719,8 @@ class Agent:
|
|
|
707
719
|
"""
|
|
708
720
|
max_attempts = 4 if self.fallback_agent_config else 2
|
|
709
721
|
attempt = 0
|
|
722
|
+
orig_llm = self.llm.metadata.model_name
|
|
723
|
+
last_error = None
|
|
710
724
|
while attempt < max_attempts:
|
|
711
725
|
try:
|
|
712
726
|
current_agent = self._get_current_agent()
|
|
@@ -718,16 +732,20 @@ class Agent:
|
|
|
718
732
|
self.query_logging_callback(prompt, agent_response.response)
|
|
719
733
|
return agent_response
|
|
720
734
|
|
|
721
|
-
except Exception:
|
|
735
|
+
except Exception as e:
|
|
736
|
+
last_error = e
|
|
722
737
|
if attempt >= 2:
|
|
723
738
|
if self.verbose:
|
|
724
|
-
print(f"LLM call failed on attempt {attempt
|
|
739
|
+
print(f"LLM call failed on attempt {attempt}. Switching agent configuration.")
|
|
725
740
|
self._switch_agent_config()
|
|
726
741
|
time.sleep(1)
|
|
727
742
|
attempt += 1
|
|
728
743
|
|
|
729
744
|
return AgentResponse(
|
|
730
|
-
response=
|
|
745
|
+
response=(
|
|
746
|
+
f"For {orig_llm} LLM - failure can't be resolved after "
|
|
747
|
+
f"{max_attempts} attempts ({last_error}."
|
|
748
|
+
)
|
|
731
749
|
)
|
|
732
750
|
|
|
733
751
|
def stream_chat(self, prompt: str) -> AgentStreamingResponse: # type: ignore
|
|
@@ -252,8 +252,10 @@ class SequentialSubQuestionsWorkflow(Workflow):
|
|
|
252
252
|
As an example, for the question
|
|
253
253
|
"what is the name of the mayor of the largest city within 50 miles of San Francisco?",
|
|
254
254
|
the sub-questions could be:
|
|
255
|
-
- What is the largest city within 50 miles of San Francisco?
|
|
256
|
-
-
|
|
255
|
+
- What is the largest city within 50 miles of San Francisco?
|
|
256
|
+
- Who is the mayor of this city?
|
|
257
|
+
The answer to the first question is San Jose, which is given as context to the second question.
|
|
258
|
+
The answer to the second question is Matt Mahan.
|
|
257
259
|
Here is the user question: {await ctx.get('original_query')}.
|
|
258
260
|
Here are previous chat messages: {chat_history}.
|
|
259
261
|
And here is the list of tools: {await ctx.get('tools')}
|
|
@@ -277,7 +279,16 @@ class SequentialSubQuestionsWorkflow(Workflow):
|
|
|
277
279
|
if await ctx.get("verbose"):
|
|
278
280
|
print(f"Sub-question is {ev.question}")
|
|
279
281
|
agent = await ctx.get("agent")
|
|
280
|
-
|
|
282
|
+
sub_questions = await ctx.get("sub_questions")
|
|
283
|
+
if ev.prev_answer:
|
|
284
|
+
prev_question = sub_questions[ev.num - 1]
|
|
285
|
+
prompt = f"""
|
|
286
|
+
The answer to the question '{prev_question}' is: '{ev.prev_answer}'
|
|
287
|
+
Now answer the following question: '{ev.question}'
|
|
288
|
+
"""
|
|
289
|
+
response = await agent.achat(prompt)
|
|
290
|
+
else:
|
|
291
|
+
response = await agent.achat(ev.question)
|
|
281
292
|
if await ctx.get("verbose"):
|
|
282
293
|
print(f"Answer is {response}")
|
|
283
294
|
|
|
@@ -286,7 +297,8 @@ class SequentialSubQuestionsWorkflow(Workflow):
|
|
|
286
297
|
return self.QueryEvent(
|
|
287
298
|
question=sub_questions[ev.num + 1],
|
|
288
299
|
prev_answer = response.response,
|
|
289
|
-
num=ev.num + 1
|
|
300
|
+
num=ev.num + 1
|
|
301
|
+
)
|
|
290
302
|
|
|
291
303
|
output = self.OutputsModel(response=response.response)
|
|
292
304
|
return StopEvent(result=output)
|
vectara_agentic/tools.py
CHANGED
|
@@ -8,7 +8,7 @@ import importlib
|
|
|
8
8
|
import os
|
|
9
9
|
|
|
10
10
|
from typing import Callable, List, Dict, Any, Optional, Union, Type
|
|
11
|
-
from pydantic import BaseModel, Field
|
|
11
|
+
from pydantic import BaseModel, Field, create_model
|
|
12
12
|
from pydantic_core import PydanticUndefined
|
|
13
13
|
|
|
14
14
|
from llama_index.core.tools import FunctionTool
|
|
@@ -21,7 +21,7 @@ from llama_index.core.workflow.context import Context
|
|
|
21
21
|
from .types import ToolType
|
|
22
22
|
from .tools_catalog import ToolsCatalog, get_bad_topics
|
|
23
23
|
from .db_tools import DBLoadSampleData, DBLoadUniqueValues, DBLoadData
|
|
24
|
-
from .utils import is_float
|
|
24
|
+
from .utils import is_float, summarize_vectara_document
|
|
25
25
|
from .agent_config import AgentConfig
|
|
26
26
|
|
|
27
27
|
LI_packages = {
|
|
@@ -74,6 +74,7 @@ class VectaraToolMetadata(ToolMetadata):
|
|
|
74
74
|
base_repr = super().__repr__()
|
|
75
75
|
return f"{base_repr}, tool_type={self.tool_type}"
|
|
76
76
|
|
|
77
|
+
|
|
77
78
|
class VectaraTool(FunctionTool):
|
|
78
79
|
"""
|
|
79
80
|
A subclass of FunctionTool adding the tool_type attribute.
|
|
@@ -161,7 +162,7 @@ class VectaraTool(FunctionTool):
|
|
|
161
162
|
self, *args: Any, ctx: Optional[Context] = None, **kwargs: Any
|
|
162
163
|
) -> ToolOutput:
|
|
163
164
|
try:
|
|
164
|
-
return super().
|
|
165
|
+
return await super().acall(*args, ctx=ctx, **kwargs)
|
|
165
166
|
except Exception as e:
|
|
166
167
|
err_output = ToolOutput(
|
|
167
168
|
tool_name=self.metadata.name,
|
|
@@ -171,6 +172,65 @@ class VectaraTool(FunctionTool):
|
|
|
171
172
|
)
|
|
172
173
|
return err_output
|
|
173
174
|
|
|
175
|
+
def _create_tool_from_dynamic_function(
|
|
176
|
+
function: Callable[..., ToolOutput],
|
|
177
|
+
tool_name: str,
|
|
178
|
+
tool_description: str,
|
|
179
|
+
base_params: list[inspect.Parameter],
|
|
180
|
+
tool_args_schema: type[BaseModel],
|
|
181
|
+
) -> VectaraTool:
|
|
182
|
+
"""
|
|
183
|
+
Create a VectaraTool from a dynamic function, including
|
|
184
|
+
setting the function signature and creating the tool schema.
|
|
185
|
+
"""
|
|
186
|
+
fields = {}
|
|
187
|
+
for param in base_params:
|
|
188
|
+
default_value = param.default if param.default != inspect.Parameter.empty else ...
|
|
189
|
+
fields[param.name] = (param.annotation, default_value)
|
|
190
|
+
for field_name, field_info in tool_args_schema.model_fields.items():
|
|
191
|
+
if field_name not in fields:
|
|
192
|
+
default_value = field_info.default if field_info.default is not PydanticUndefined else ...
|
|
193
|
+
fields[field_name] = (field_info.annotation, default_value)
|
|
194
|
+
fn_schema = create_model(f"{tool_name}", **fields)
|
|
195
|
+
|
|
196
|
+
schema_params = [
|
|
197
|
+
inspect.Parameter(
|
|
198
|
+
name=field_name,
|
|
199
|
+
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
200
|
+
default=field_info.default if field_info.default is not PydanticUndefined else inspect.Parameter.empty,
|
|
201
|
+
annotation=field_info.annotation if hasattr(field_info, 'annotation') else field_info,
|
|
202
|
+
)
|
|
203
|
+
for field_name, field_info in tool_args_schema.model_fields.items()
|
|
204
|
+
if field_name not in [p.name for p in base_params]
|
|
205
|
+
]
|
|
206
|
+
all_params = base_params + schema_params
|
|
207
|
+
|
|
208
|
+
required_params = [p for p in all_params if p.default is inspect.Parameter.empty]
|
|
209
|
+
optional_params = [p for p in all_params if p.default is not inspect.Parameter.empty]
|
|
210
|
+
sig = inspect.Signature(required_params + optional_params)
|
|
211
|
+
function.__signature__ = sig
|
|
212
|
+
function.__annotations__["return"] = dict[str, Any]
|
|
213
|
+
function.__name__ = "_" + re.sub(r"[^A-Za-z0-9_]", "_", tool_name)
|
|
214
|
+
|
|
215
|
+
# Create the tool function signature string
|
|
216
|
+
param_strs = []
|
|
217
|
+
for param in all_params:
|
|
218
|
+
annotation = param.annotation
|
|
219
|
+
type_name = annotation.__name__ if hasattr(annotation, '__name__') else str(annotation)
|
|
220
|
+
param_strs.append(f"{param.name}: {type_name}")
|
|
221
|
+
args_str = ", ".join(param_strs)
|
|
222
|
+
function_str = f"{tool_name}({args_str}) -> str"
|
|
223
|
+
|
|
224
|
+
# Create the tool
|
|
225
|
+
tool = VectaraTool.from_defaults(
|
|
226
|
+
fn=function,
|
|
227
|
+
name=tool_name,
|
|
228
|
+
description=function_str + "\n" + tool_description,
|
|
229
|
+
fn_schema=fn_schema,
|
|
230
|
+
tool_type=ToolType.QUERY,
|
|
231
|
+
)
|
|
232
|
+
return tool
|
|
233
|
+
|
|
174
234
|
def _build_filter_string(kwargs: Dict[str, Any], tool_args_type: Dict[str, dict], fixed_filter: str) -> str:
|
|
175
235
|
"""
|
|
176
236
|
Build filter string for Vectara from kwargs
|
|
@@ -196,7 +256,7 @@ def _build_filter_string(kwargs: Dict[str, Any], tool_args_type: Dict[str, dict]
|
|
|
196
256
|
|
|
197
257
|
if value is PydanticUndefined:
|
|
198
258
|
raise ValueError(
|
|
199
|
-
f"Value of argument {key} is undefined, and this is invalid.
|
|
259
|
+
f"Value of argument {key} is undefined, and this is invalid."
|
|
200
260
|
"Please form proper arguments and try again."
|
|
201
261
|
)
|
|
202
262
|
|
|
@@ -394,7 +454,7 @@ class VectaraToolFactory:
|
|
|
394
454
|
)
|
|
395
455
|
|
|
396
456
|
# Dynamically generate the search function
|
|
397
|
-
def search_function(*args, **kwargs) -> ToolOutput:
|
|
457
|
+
def search_function(*args: Any, **kwargs: Any) -> ToolOutput:
|
|
398
458
|
"""
|
|
399
459
|
Dynamically generated function for semantic search Vectara.
|
|
400
460
|
"""
|
|
@@ -406,6 +466,7 @@ class VectaraToolFactory:
|
|
|
406
466
|
|
|
407
467
|
query = kwargs.pop("query")
|
|
408
468
|
top_k = kwargs.pop("top_k", 10)
|
|
469
|
+
summarize = kwargs.pop("summarize", True)
|
|
409
470
|
try:
|
|
410
471
|
filter_string = _build_filter_string(kwargs, tool_args_type, fixed_filter)
|
|
411
472
|
except ValueError as e:
|
|
@@ -453,7 +514,11 @@ class VectaraToolFactory:
|
|
|
453
514
|
if doc.id_ in unique_ids:
|
|
454
515
|
continue
|
|
455
516
|
unique_ids.add(doc.id_)
|
|
456
|
-
|
|
517
|
+
if summarize:
|
|
518
|
+
summary = summarize_vectara_document(self.vectara_corpus_key, self.vectara_api_key, doc.id_)
|
|
519
|
+
tool_output += f"document_id: '{doc.id_}'\nmetadata: '{doc.metadata}'\nsummary: '{summary}'\n\n"
|
|
520
|
+
else:
|
|
521
|
+
tool_output += f"document_id: '{doc.id_}'\nmetadata: '{doc.metadata}'\n\n"
|
|
457
522
|
out = ToolOutput(
|
|
458
523
|
tool_name=search_function.__name__,
|
|
459
524
|
content=tool_output,
|
|
@@ -462,42 +527,22 @@ class VectaraToolFactory:
|
|
|
462
527
|
)
|
|
463
528
|
return out
|
|
464
529
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
inspect.Parameter(
|
|
468
|
-
|
|
469
|
-
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
470
|
-
default=field_info.default,
|
|
471
|
-
annotation=field_info,
|
|
472
|
-
)
|
|
473
|
-
for field_name, field_info in fields.items()
|
|
530
|
+
base_params = [
|
|
531
|
+
inspect.Parameter("query", inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=str),
|
|
532
|
+
inspect.Parameter("top_k", inspect.Parameter.POSITIONAL_OR_KEYWORD, default=10, annotation=int),
|
|
533
|
+
inspect.Parameter("summarize", inspect.Parameter.POSITIONAL_OR_KEYWORD, default=True, annotation=bool),
|
|
474
534
|
]
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
search_function.__signature__ = sig
|
|
479
|
-
search_function.__annotations__["return"] = dict[str, Any]
|
|
480
|
-
search_function.__name__ = "_" + re.sub(r"[^A-Za-z0-9_]", "_", tool_name)
|
|
481
|
-
|
|
482
|
-
# Create the tool function signature string
|
|
483
|
-
fields = []
|
|
484
|
-
for name, field in tool_args_schema.model_fields.items():
|
|
485
|
-
annotation = field.annotation
|
|
486
|
-
type_name = annotation.__name__ if hasattr(annotation, '__name__') else str(annotation)
|
|
487
|
-
fields.append(f"{name}: {type_name}")
|
|
488
|
-
args_str = ", ".join(fields)
|
|
489
|
-
function_str = f"{tool_name}({args_str}) -> str"
|
|
490
|
-
|
|
491
|
-
# Create the tool
|
|
492
|
-
search_tool_extra_desc = """
|
|
493
|
-
The response includes metadata about each relevant document, but NOT the text itself.
|
|
535
|
+
search_tool_extra_desc = tool_description + "\n" + """
|
|
536
|
+
The response includes metadata about each relevant document.
|
|
537
|
+
If summarize=True, it also includes a summary of each document.
|
|
494
538
|
"""
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
539
|
+
|
|
540
|
+
tool = _create_tool_from_dynamic_function(
|
|
541
|
+
search_function,
|
|
542
|
+
tool_name,
|
|
543
|
+
search_tool_extra_desc,
|
|
544
|
+
base_params,
|
|
545
|
+
tool_args_schema,
|
|
501
546
|
)
|
|
502
547
|
return tool
|
|
503
548
|
|
|
@@ -597,11 +642,11 @@ class VectaraToolFactory:
|
|
|
597
642
|
vectara_corpus_key=self.vectara_corpus_key,
|
|
598
643
|
x_source_str="vectara-agentic",
|
|
599
644
|
vectara_base_url=vectara_base_url,
|
|
600
|
-
|
|
645
|
+
vectara_verify_ssl=vectara_verify_ssl,
|
|
601
646
|
)
|
|
602
647
|
|
|
603
648
|
# Dynamically generate the RAG function
|
|
604
|
-
def rag_function(*args, **kwargs) -> ToolOutput:
|
|
649
|
+
def rag_function(*args: Any, **kwargs: Any) -> ToolOutput:
|
|
605
650
|
"""
|
|
606
651
|
Dynamically generated function for RAG query with Vectara.
|
|
607
652
|
"""
|
|
@@ -721,39 +766,15 @@ class VectaraToolFactory:
|
|
|
721
766
|
)
|
|
722
767
|
return out
|
|
723
768
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
inspect.Parameter(
|
|
727
|
-
name=field_name,
|
|
728
|
-
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
729
|
-
default=field_info.default,
|
|
730
|
-
annotation=field_info,
|
|
731
|
-
)
|
|
732
|
-
for field_name, field_info in fields.items()
|
|
769
|
+
base_params = [
|
|
770
|
+
inspect.Parameter("query", inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=str),
|
|
733
771
|
]
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
# Create the tool function signature string
|
|
742
|
-
fields = []
|
|
743
|
-
for name, field in tool_args_schema.model_fields.items():
|
|
744
|
-
annotation = field.annotation
|
|
745
|
-
type_name = annotation.__name__ if hasattr(annotation, '__name__') else str(annotation)
|
|
746
|
-
fields.append(f"{name}: {type_name}")
|
|
747
|
-
args_str = ", ".join(fields)
|
|
748
|
-
function_str = f"{tool_name}({args_str}) -> str"
|
|
749
|
-
|
|
750
|
-
# Create the tool
|
|
751
|
-
tool = VectaraTool.from_defaults(
|
|
752
|
-
fn=rag_function,
|
|
753
|
-
name=tool_name,
|
|
754
|
-
description=function_str + ". " + tool_description,
|
|
755
|
-
fn_schema=tool_args_schema,
|
|
756
|
-
tool_type=ToolType.QUERY,
|
|
772
|
+
tool = _create_tool_from_dynamic_function(
|
|
773
|
+
rag_function,
|
|
774
|
+
tool_name,
|
|
775
|
+
tool_description,
|
|
776
|
+
base_params,
|
|
777
|
+
tool_args_schema,
|
|
757
778
|
)
|
|
758
779
|
return tool
|
|
759
780
|
|
vectara_agentic/types.py
CHANGED
vectara_agentic/utils.py
CHANGED
|
@@ -5,6 +5,8 @@ Utilities for the Vectara agentic.
|
|
|
5
5
|
from typing import Tuple, Callable, Optional
|
|
6
6
|
from functools import lru_cache
|
|
7
7
|
from inspect import signature
|
|
8
|
+
import json
|
|
9
|
+
import requests
|
|
8
10
|
|
|
9
11
|
import tiktoken
|
|
10
12
|
|
|
@@ -90,35 +92,50 @@ def get_llm(
|
|
|
90
92
|
Get the LLM for the specified role, using the provided config
|
|
91
93
|
or a default if none is provided.
|
|
92
94
|
"""
|
|
95
|
+
max_tokens = 8192
|
|
93
96
|
model_provider, model_name = _get_llm_params_for_role(role, config)
|
|
94
97
|
if model_provider == ModelProvider.OPENAI:
|
|
95
98
|
llm = OpenAI(model=model_name, temperature=0,
|
|
96
99
|
is_function_calling_model=True,
|
|
97
|
-
strict=True
|
|
100
|
+
strict=True,
|
|
101
|
+
max_tokens=max_tokens
|
|
102
|
+
)
|
|
98
103
|
elif model_provider == ModelProvider.ANTHROPIC:
|
|
99
|
-
llm = Anthropic(model=model_name, temperature=0)
|
|
104
|
+
llm = Anthropic(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
100
105
|
elif model_provider == ModelProvider.GEMINI:
|
|
101
106
|
from llama_index.llms.gemini import Gemini
|
|
102
|
-
llm = Gemini(
|
|
107
|
+
llm = Gemini(
|
|
108
|
+
model=model_name, temperature=0,
|
|
109
|
+
is_function_calling_model=True,
|
|
110
|
+
max_tokens=max_tokens
|
|
111
|
+
)
|
|
103
112
|
elif model_provider == ModelProvider.TOGETHER:
|
|
104
113
|
from llama_index.llms.together import TogetherLLM
|
|
105
|
-
llm = TogetherLLM(
|
|
114
|
+
llm = TogetherLLM(
|
|
115
|
+
model=model_name, temperature=0,
|
|
116
|
+
is_function_calling_model=True,
|
|
117
|
+
max_tokens=max_tokens
|
|
118
|
+
)
|
|
106
119
|
elif model_provider == ModelProvider.GROQ:
|
|
107
120
|
from llama_index.llms.groq import Groq
|
|
108
|
-
llm = Groq(
|
|
121
|
+
llm = Groq(
|
|
122
|
+
model=model_name, temperature=0,
|
|
123
|
+
is_function_calling_model=True, max_tokens=max_tokens
|
|
124
|
+
)
|
|
109
125
|
elif model_provider == ModelProvider.FIREWORKS:
|
|
110
126
|
from llama_index.llms.fireworks import Fireworks
|
|
111
|
-
llm = Fireworks(model=model_name, temperature=0)
|
|
127
|
+
llm = Fireworks(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
112
128
|
elif model_provider == ModelProvider.BEDROCK:
|
|
113
129
|
from llama_index.llms.bedrock import Bedrock
|
|
114
|
-
llm = Bedrock(model=model_name, temperature=0)
|
|
130
|
+
llm = Bedrock(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
115
131
|
elif model_provider == ModelProvider.COHERE:
|
|
116
132
|
from llama_index.llms.cohere import Cohere
|
|
117
|
-
llm = Cohere(model=model_name, temperature=0)
|
|
133
|
+
llm = Cohere(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
118
134
|
elif model_provider == ModelProvider.PRIVATE:
|
|
119
135
|
from llama_index.llms.openai_like import OpenAILike
|
|
120
136
|
llm = OpenAILike(model=model_name, temperature=0, is_function_calling_model=True,is_chat_model=True,
|
|
121
|
-
api_base=config.private_llm_api_base, api_key=config.private_llm_api_key
|
|
137
|
+
api_base=config.private_llm_api_base, api_key=config.private_llm_api_key,
|
|
138
|
+
max_tokens=max_tokens)
|
|
122
139
|
else:
|
|
123
140
|
raise ValueError(f"Unknown LLM provider: {model_provider}")
|
|
124
141
|
return llm
|
|
@@ -141,3 +158,25 @@ def remove_self_from_signature(func):
|
|
|
141
158
|
new_sig = sig.replace(parameters=params)
|
|
142
159
|
func.__signature__ = new_sig
|
|
143
160
|
return func
|
|
161
|
+
|
|
162
|
+
def summarize_vectara_document(corpus_key: str, vectara_api_key, doc_id: str) -> str:
|
|
163
|
+
"""
|
|
164
|
+
Summarize a document in a Vectara corpus using the Vectara API.
|
|
165
|
+
"""
|
|
166
|
+
url = f"https://api.vectara.io/v2/corpora/{corpus_key}/documents/{doc_id}/summarize"
|
|
167
|
+
|
|
168
|
+
payload = json.dumps({
|
|
169
|
+
"llm_name": "gpt-4o",
|
|
170
|
+
"model_parameters": {},
|
|
171
|
+
"stream_response": False
|
|
172
|
+
})
|
|
173
|
+
headers = {
|
|
174
|
+
'Content-Type': 'application/json',
|
|
175
|
+
'Accept': 'application/json',
|
|
176
|
+
'x-api-key': vectara_api_key
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
response = requests.request("POST", url, headers=headers, data=payload, timeout=60)
|
|
180
|
+
if response.status_code != 200:
|
|
181
|
+
return f"Vectara Summarization failed with error code {response.status_code}, error={response.text}"
|
|
182
|
+
return json.loads(response.text)["summary"]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tests/endpoint.py,sha256=frnpdZQpnuQNNKNYgAn2rFTarNG8MCJaNA77Bw_W22A,1420
|
|
3
|
+
tests/test_agent.py,sha256=CU7Zdb1J5kFjrkkIeDr70W1wsikYuOvoYKGYpg4EPxM,6678
|
|
4
|
+
tests/test_agent_planning.py,sha256=_mj73TNP9yUjkUJ-X31r-cQYreJ4qatXOtMrRvVpF4Y,2411
|
|
5
|
+
tests/test_agent_type.py,sha256=JM0Q2GBGHSADoBacz_DW551zWSfbpf7qa8xXqtyWsc4,5671
|
|
6
|
+
tests/test_fallback.py,sha256=M5YD7NHZ0joVU1frYIr9_OiRAIje5mrXrYVcekzlyGs,2829
|
|
7
|
+
tests/test_private_llm.py,sha256=CY-_rCpxGUuxnZ3ypkodw5Jj-sJCNdh6rLbCvULwuJI,2247
|
|
8
|
+
tests/test_tools.py,sha256=IVKn0HoS2erTCr1mOEGzTkktiY0PCfKNvqnD_pizjOg,3977
|
|
9
|
+
tests/test_workflow.py,sha256=lVyrVHdRO5leYNbYtHTmKqMX0c8_xehCpUA7cXQKVsc,2175
|
|
10
|
+
vectara_agentic/__init__.py,sha256=2GLDS3U6KckK-dBRl9v_x1kSV507gEhjOfuMmmu0Qxg,850
|
|
11
|
+
vectara_agentic/_callback.py,sha256=5PfqjLmuaZIR6dnqmhniTD_zwCgfi7kOu-nexb6Kss4,9688
|
|
12
|
+
vectara_agentic/_observability.py,sha256=fTL3KW0jQU-_JSpFgjO6-XzgDut_oiq9kt4QR-FkSqU,3804
|
|
13
|
+
vectara_agentic/_prompts.py,sha256=LYyiOAiC8imz3U7MSJiuCYAP39afsp7ycXY7-9biyJI,9314
|
|
14
|
+
vectara_agentic/_version.py,sha256=FGUM5lA5uZpmWWB52dt2AMCqWcU0M9b-2BB-raX-EN4,65
|
|
15
|
+
vectara_agentic/agent.py,sha256=nbBl66n56kjEZX4Zconb9IZjESzpjBZIEQdL4uLfurI,43333
|
|
16
|
+
vectara_agentic/agent_config.py,sha256=y1hSvU5ns0cE2R7BqF65LFstixF1ytJcoVgicGXo7w0,3691
|
|
17
|
+
vectara_agentic/agent_endpoint.py,sha256=QIMejCLlpW2qzXxeDAxv3anF46XMDdVMdKGWhJh3azY,1996
|
|
18
|
+
vectara_agentic/db_tools.py,sha256=VUdcjDFPwauFd2A92mXNYZnCjeMiTzcTka7S5At_3oQ,3595
|
|
19
|
+
vectara_agentic/sub_query_workflow.py,sha256=eS1S7l5PdyLPLZqxUJSR0oM2kvHb4raPGHk8t8td9sc,10939
|
|
20
|
+
vectara_agentic/tools.py,sha256=RpPGWiPHe-9ZiOxNz389W-gNWxegg7m4RlEx_pH9_W0,42881
|
|
21
|
+
vectara_agentic/tools_catalog.py,sha256=oiw3wAfbpFhh0_6rMvZsyPqWV6QIzHqhZCNzqRxuyV8,4818
|
|
22
|
+
vectara_agentic/types.py,sha256=HcS7vR8P2v2xQTlOc6ZFV2vvlr3OpzSNWhtcLMxqUZc,1792
|
|
23
|
+
vectara_agentic/utils.py,sha256=U4VWCyrvpXfPb9SJpd4Xj7rJCN-cZCNReNm9_uQjnlk,6759
|
|
24
|
+
vectara_agentic-0.2.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
25
|
+
vectara_agentic-0.2.7.dist-info/METADATA,sha256=z-IFDKlGmNh9QSIUV4xOOCYKF-PrTUnDukp8M5BNMe4,25046
|
|
26
|
+
vectara_agentic-0.2.7.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
27
|
+
vectara_agentic-0.2.7.dist-info/top_level.txt,sha256=Y7TQTFdOYGYodQRltUGRieZKIYuzeZj2kHqAUpfCUfg,22
|
|
28
|
+
vectara_agentic-0.2.7.dist-info/RECORD,,
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
tests/endpoint.py,sha256=frnpdZQpnuQNNKNYgAn2rFTarNG8MCJaNA77Bw_W22A,1420
|
|
3
|
-
tests/test_agent.py,sha256=5iYlROsGQV_fPF9IR1JZ_ByhQ3EoaLG_40ntrCgugWo,6461
|
|
4
|
-
tests/test_agent_planning.py,sha256=0GEI-b7g5tV8xP_FbTfIu-a8J9s_EhDXC_9T6HS6DsU,1457
|
|
5
|
-
tests/test_agent_type.py,sha256=-14Y6vwYTaRJuj8VZ-c6d1vIiWpV31k2zs_frdoxR5s,2920
|
|
6
|
-
tests/test_fallback.py,sha256=4ZqP_7XsabhzaVgXa599PDbwp38t_XY5fMzQwr8F6Z8,2793
|
|
7
|
-
tests/test_private_llm.py,sha256=rPXQ-NKL2MnrMcGNEG1Zz3U8uK9pjxUfjvIl2gH9gnw,2224
|
|
8
|
-
tests/test_tools.py,sha256=0-2oWX8DW0WIjViNFl0xj_6JOhIdyx6zV0IlTuMzxjk,3954
|
|
9
|
-
tests/test_workflow.py,sha256=lVyrVHdRO5leYNbYtHTmKqMX0c8_xehCpUA7cXQKVsc,2175
|
|
10
|
-
vectara_agentic/__init__.py,sha256=2GLDS3U6KckK-dBRl9v_x1kSV507gEhjOfuMmmu0Qxg,850
|
|
11
|
-
vectara_agentic/_callback.py,sha256=5PfqjLmuaZIR6dnqmhniTD_zwCgfi7kOu-nexb6Kss4,9688
|
|
12
|
-
vectara_agentic/_observability.py,sha256=fTL3KW0jQU-_JSpFgjO6-XzgDut_oiq9kt4QR-FkSqU,3804
|
|
13
|
-
vectara_agentic/_prompts.py,sha256=LYyiOAiC8imz3U7MSJiuCYAP39afsp7ycXY7-9biyJI,9314
|
|
14
|
-
vectara_agentic/_version.py,sha256=EFHZPv0y0xF__sBHhCA8j-o21yOSHXl15GJEp-lZLy4,65
|
|
15
|
-
vectara_agentic/agent.py,sha256=74_2XzBvl5jPyAqqYhoxsS7PXITWBdJpxs4L_XeyZio,42561
|
|
16
|
-
vectara_agentic/agent_config.py,sha256=y1hSvU5ns0cE2R7BqF65LFstixF1ytJcoVgicGXo7w0,3691
|
|
17
|
-
vectara_agentic/agent_endpoint.py,sha256=QIMejCLlpW2qzXxeDAxv3anF46XMDdVMdKGWhJh3azY,1996
|
|
18
|
-
vectara_agentic/db_tools.py,sha256=VUdcjDFPwauFd2A92mXNYZnCjeMiTzcTka7S5At_3oQ,3595
|
|
19
|
-
vectara_agentic/sub_query_workflow.py,sha256=KcIfUaDcv25n8iLQmZ9ZhNlKyZAKAu-3otXADukBios,10394
|
|
20
|
-
vectara_agentic/tools.py,sha256=xWxl1ixSCsBPjZ-GNpkjN_nXRBxvH_vr8oDauAYrIW0,41763
|
|
21
|
-
vectara_agentic/tools_catalog.py,sha256=oiw3wAfbpFhh0_6rMvZsyPqWV6QIzHqhZCNzqRxuyV8,4818
|
|
22
|
-
vectara_agentic/types.py,sha256=tLpyDY-UbFN2Iqk_fgWoOxlGexh_AQ5BaXQ593sCkRc,1750
|
|
23
|
-
vectara_agentic/utils.py,sha256=AUyWrL8aY67AGx6j9m00k75JRHTI44EAKtal73aMczM,5504
|
|
24
|
-
vectara_agentic-0.2.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
25
|
-
vectara_agentic-0.2.6.dist-info/METADATA,sha256=u9gIGxK3XEPeSItrUevqwJVOWWzRJ3Mqdo55-l3o098,25046
|
|
26
|
-
vectara_agentic-0.2.6.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
|
27
|
-
vectara_agentic-0.2.6.dist-info/top_level.txt,sha256=Y7TQTFdOYGYodQRltUGRieZKIYuzeZj2kHqAUpfCUfg,22
|
|
28
|
-
vectara_agentic-0.2.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|