vectara-agentic 0.2.11__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 +8 -10
- vectara_agentic/_version.py +1 -1
- vectara_agentic/agent.py +240 -79
- vectara_agentic/db_tools.py +2 -2
- vectara_agentic/tools.py +330 -193
- vectara_agentic/utils.py +76 -47
- {vectara_agentic-0.2.11.dist-info → vectara_agentic-0.2.13.dist-info}/METADATA +338 -233
- vectara_agentic-0.2.13.dist-info/RECORD +30 -0
- {vectara_agentic-0.2.11.dist-info → vectara_agentic-0.2.13.dist-info}/WHEEL +1 -1
- vectara_agentic-0.2.11.dist-info/RECORD +0 -29
- {vectara_agentic-0.2.11.dist-info → vectara_agentic-0.2.13.dist-info}/licenses/LICENSE +0 -0
- {vectara_agentic-0.2.11.dist-info → vectara_agentic-0.2.13.dist-info}/top_level.txt +0 -0
vectara_agentic/utils.py
CHANGED
|
@@ -19,21 +19,21 @@ from .agent_config import AgentConfig
|
|
|
19
19
|
|
|
20
20
|
provider_to_default_model_name = {
|
|
21
21
|
ModelProvider.OPENAI: "gpt-4o",
|
|
22
|
-
ModelProvider.ANTHROPIC: "claude-3-7-sonnet-
|
|
23
|
-
ModelProvider.TOGETHER: "
|
|
24
|
-
ModelProvider.GROQ: "llama-
|
|
22
|
+
ModelProvider.ANTHROPIC: "claude-3-7-sonnet-latest",
|
|
23
|
+
ModelProvider.TOGETHER: "Qwen/Qwen2.5-72B-Instruct-Turbo",
|
|
24
|
+
ModelProvider.GROQ: "meta-llama/llama-4-scout-17b-16e-instruct",
|
|
25
25
|
ModelProvider.FIREWORKS: "accounts/fireworks/models/firefunction-v2",
|
|
26
|
-
ModelProvider.BEDROCK: "anthropic.claude-3-
|
|
27
|
-
ModelProvider.COHERE: "command-
|
|
26
|
+
ModelProvider.BEDROCK: "anthropic.claude-3-7-sonnet-20250219-v1:0",
|
|
27
|
+
ModelProvider.COHERE: "command-a-03-2025",
|
|
28
28
|
ModelProvider.GEMINI: "models/gemini-2.0-flash",
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
DEFAULT_MODEL_PROVIDER = ModelProvider.OPENAI
|
|
32
32
|
|
|
33
|
+
|
|
33
34
|
@lru_cache(maxsize=None)
|
|
34
35
|
def _get_llm_params_for_role(
|
|
35
|
-
role: LLMRole,
|
|
36
|
-
config: Optional[AgentConfig] = None
|
|
36
|
+
role: LLMRole, config: Optional[AgentConfig] = None
|
|
37
37
|
) -> Tuple[ModelProvider, str]:
|
|
38
38
|
"""
|
|
39
39
|
Get the model provider and model name for the specified role.
|
|
@@ -46,15 +46,13 @@ def _get_llm_params_for_role(
|
|
|
46
46
|
model_provider = ModelProvider(config.tool_llm_provider)
|
|
47
47
|
# If the user hasn’t explicitly set a tool_llm_model_name,
|
|
48
48
|
# fallback to provider default from provider_to_default_model_name
|
|
49
|
-
model_name = (
|
|
50
|
-
|
|
51
|
-
or provider_to_default_model_name.get(model_provider)
|
|
49
|
+
model_name = config.tool_llm_model_name or provider_to_default_model_name.get(
|
|
50
|
+
model_provider
|
|
52
51
|
)
|
|
53
52
|
else:
|
|
54
53
|
model_provider = ModelProvider(config.main_llm_provider)
|
|
55
|
-
model_name = (
|
|
56
|
-
|
|
57
|
-
or provider_to_default_model_name.get(model_provider)
|
|
54
|
+
model_name = config.main_llm_model_name or provider_to_default_model_name.get(
|
|
55
|
+
model_provider
|
|
58
56
|
)
|
|
59
57
|
|
|
60
58
|
# If the agent type is OpenAI, check that the main LLM provider is also OpenAI.
|
|
@@ -66,10 +64,10 @@ def _get_llm_params_for_role(
|
|
|
66
64
|
|
|
67
65
|
return model_provider, model_name
|
|
68
66
|
|
|
67
|
+
|
|
69
68
|
@lru_cache(maxsize=None)
|
|
70
69
|
def get_tokenizer_for_model(
|
|
71
|
-
role: LLMRole,
|
|
72
|
-
config: Optional[AgentConfig] = None
|
|
70
|
+
role: LLMRole, config: Optional[AgentConfig] = None
|
|
73
71
|
) -> Optional[Callable]:
|
|
74
72
|
"""
|
|
75
73
|
Get the tokenizer for the specified model, as determined by the role & config.
|
|
@@ -84,10 +82,7 @@ def get_tokenizer_for_model(
|
|
|
84
82
|
|
|
85
83
|
|
|
86
84
|
@lru_cache(maxsize=None)
|
|
87
|
-
def get_llm(
|
|
88
|
-
role: LLMRole,
|
|
89
|
-
config: Optional[AgentConfig] = None
|
|
90
|
-
) -> LLM:
|
|
85
|
+
def get_llm(role: LLMRole, config: Optional[AgentConfig] = None) -> LLM:
|
|
91
86
|
"""
|
|
92
87
|
Get the LLM for the specified role, using the provided config
|
|
93
88
|
or a default if none is provided.
|
|
@@ -95,55 +90,77 @@ def get_llm(
|
|
|
95
90
|
max_tokens = 8192
|
|
96
91
|
model_provider, model_name = _get_llm_params_for_role(role, config)
|
|
97
92
|
if model_provider == ModelProvider.OPENAI:
|
|
98
|
-
llm = OpenAI(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
93
|
+
llm = OpenAI(
|
|
94
|
+
model=model_name,
|
|
95
|
+
temperature=0,
|
|
96
|
+
is_function_calling_model=True,
|
|
97
|
+
strict=True,
|
|
98
|
+
max_tokens=max_tokens,
|
|
99
|
+
pydantic_program_mode="openai",
|
|
100
|
+
)
|
|
103
101
|
elif model_provider == ModelProvider.ANTHROPIC:
|
|
104
102
|
llm = Anthropic(
|
|
105
|
-
model=model_name,
|
|
106
|
-
|
|
103
|
+
model=model_name,
|
|
104
|
+
temperature=0,
|
|
105
|
+
max_tokens=max_tokens,
|
|
107
106
|
)
|
|
108
107
|
elif model_provider == ModelProvider.GEMINI:
|
|
109
108
|
from llama_index.llms.gemini import Gemini
|
|
109
|
+
|
|
110
110
|
llm = Gemini(
|
|
111
|
-
model=model_name,
|
|
111
|
+
model=model_name,
|
|
112
|
+
temperature=0,
|
|
112
113
|
is_function_calling_model=True,
|
|
113
114
|
allow_parallel_tool_calls=True,
|
|
114
115
|
max_tokens=max_tokens,
|
|
115
116
|
)
|
|
116
117
|
elif model_provider == ModelProvider.TOGETHER:
|
|
117
118
|
from llama_index.llms.together import TogetherLLM
|
|
119
|
+
|
|
118
120
|
llm = TogetherLLM(
|
|
119
|
-
model=model_name,
|
|
121
|
+
model=model_name,
|
|
122
|
+
temperature=0,
|
|
120
123
|
is_function_calling_model=True,
|
|
121
|
-
max_tokens=max_tokens
|
|
124
|
+
max_tokens=max_tokens,
|
|
122
125
|
)
|
|
123
126
|
elif model_provider == ModelProvider.GROQ:
|
|
124
127
|
from llama_index.llms.groq import Groq
|
|
128
|
+
|
|
125
129
|
llm = Groq(
|
|
126
|
-
model=model_name,
|
|
127
|
-
|
|
130
|
+
model=model_name,
|
|
131
|
+
temperature=0,
|
|
132
|
+
is_function_calling_model=True,
|
|
133
|
+
max_tokens=max_tokens,
|
|
128
134
|
)
|
|
129
135
|
elif model_provider == ModelProvider.FIREWORKS:
|
|
130
136
|
from llama_index.llms.fireworks import Fireworks
|
|
137
|
+
|
|
131
138
|
llm = Fireworks(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
132
139
|
elif model_provider == ModelProvider.BEDROCK:
|
|
133
140
|
from llama_index.llms.bedrock import Bedrock
|
|
141
|
+
|
|
134
142
|
llm = Bedrock(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
135
143
|
elif model_provider == ModelProvider.COHERE:
|
|
136
144
|
from llama_index.llms.cohere import Cohere
|
|
145
|
+
|
|
137
146
|
llm = Cohere(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
138
147
|
elif model_provider == ModelProvider.PRIVATE:
|
|
139
148
|
from llama_index.llms.openai_like import OpenAILike
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
149
|
+
|
|
150
|
+
llm = OpenAILike(
|
|
151
|
+
model=model_name,
|
|
152
|
+
temperature=0,
|
|
153
|
+
is_function_calling_model=True,
|
|
154
|
+
is_chat_model=True,
|
|
155
|
+
api_base=config.private_llm_api_base,
|
|
156
|
+
api_key=config.private_llm_api_key,
|
|
157
|
+
max_tokens=max_tokens,
|
|
158
|
+
)
|
|
143
159
|
else:
|
|
144
160
|
raise ValueError(f"Unknown LLM provider: {model_provider}")
|
|
145
161
|
return llm
|
|
146
162
|
|
|
163
|
+
|
|
147
164
|
def is_float(value: str) -> bool:
|
|
148
165
|
"""Check if a string can be converted to a float."""
|
|
149
166
|
try:
|
|
@@ -152,6 +169,7 @@ def is_float(value: str) -> bool:
|
|
|
152
169
|
except ValueError:
|
|
153
170
|
return False
|
|
154
171
|
|
|
172
|
+
|
|
155
173
|
def remove_self_from_signature(func):
|
|
156
174
|
"""Decorator to remove 'self' from a method's signature for introspection."""
|
|
157
175
|
sig = signature(func)
|
|
@@ -163,21 +181,26 @@ def remove_self_from_signature(func):
|
|
|
163
181
|
func.__signature__ = new_sig
|
|
164
182
|
return func
|
|
165
183
|
|
|
166
|
-
|
|
184
|
+
|
|
185
|
+
async def summarize_vectara_document(
|
|
186
|
+
llm_name: str, corpus_key: str, api_key: str, doc_id: str
|
|
187
|
+
) -> str:
|
|
167
188
|
"""
|
|
168
189
|
Summarize a document in a Vectara corpus using the Vectara API.
|
|
169
190
|
"""
|
|
170
191
|
url = f"https://api.vectara.io/v2/corpora/{corpus_key}/documents/{doc_id}/summarize"
|
|
171
192
|
|
|
172
|
-
payload = json.dumps(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
193
|
+
payload = json.dumps(
|
|
194
|
+
{
|
|
195
|
+
"llm_name": llm_name,
|
|
196
|
+
"model_parameters": {"temperature": 0.0},
|
|
197
|
+
"stream_response": False,
|
|
198
|
+
}
|
|
199
|
+
)
|
|
177
200
|
headers = {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
201
|
+
"Content-Type": "application/json",
|
|
202
|
+
"Accept": "application/json",
|
|
203
|
+
"x-api-key": api_key,
|
|
181
204
|
}
|
|
182
205
|
timeout = aiohttp.ClientTimeout(total=60)
|
|
183
206
|
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
@@ -192,18 +215,24 @@ async def summarize_vectara_document(corpus_key: str, vectara_api_key: str, doc_
|
|
|
192
215
|
return data["summary"]
|
|
193
216
|
return json.loads(response.text)["summary"]
|
|
194
217
|
|
|
218
|
+
|
|
195
219
|
async def summarize_documents(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
doc_ids: list[str]
|
|
220
|
+
corpus_key: str,
|
|
221
|
+
api_key: str,
|
|
222
|
+
doc_ids: list[str],
|
|
223
|
+
llm_name: str = "gpt-4o",
|
|
199
224
|
) -> dict[str, str]:
|
|
200
225
|
"""
|
|
201
226
|
Summarize multiple documents in a Vectara corpus using the Vectara API.
|
|
202
227
|
"""
|
|
203
228
|
if not doc_ids:
|
|
204
229
|
return {}
|
|
230
|
+
if llm_name is None:
|
|
231
|
+
llm_name = "gpt-4o"
|
|
205
232
|
tasks = [
|
|
206
|
-
summarize_vectara_document(
|
|
233
|
+
summarize_vectara_document(
|
|
234
|
+
corpus_key=corpus_key, api_key=api_key, llm_name=llm_name, doc_id=doc_id
|
|
235
|
+
)
|
|
207
236
|
for doc_id in doc_ids
|
|
208
237
|
]
|
|
209
238
|
summaries = await asyncio.gather(*tasks, return_exceptions=True)
|