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.

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-20250219",
23
- ModelProvider.TOGETHER: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
24
- ModelProvider.GROQ: "llama-3.3-70b-versatile",
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-5-sonnet-20241022-v2:0",
27
- ModelProvider.COHERE: "command-r-plus",
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
- config.tool_llm_model_name
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
- config.main_llm_model_name
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,56 +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(model=model_name, temperature=0,
99
- is_function_calling_model=True,
100
- strict=True,
101
- max_tokens=max_tokens
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, temperature=0,
103
+ model=model_name,
104
+ temperature=0,
106
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, temperature=0,
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, temperature=0,
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, temperature=0,
130
+ model=model_name,
131
+ temperature=0,
127
132
  is_function_calling_model=True,
128
- max_tokens=max_tokens
133
+ max_tokens=max_tokens,
129
134
  )
130
135
  elif model_provider == ModelProvider.FIREWORKS:
131
136
  from llama_index.llms.fireworks import Fireworks
137
+
132
138
  llm = Fireworks(model=model_name, temperature=0, max_tokens=max_tokens)
133
139
  elif model_provider == ModelProvider.BEDROCK:
134
140
  from llama_index.llms.bedrock import Bedrock
141
+
135
142
  llm = Bedrock(model=model_name, temperature=0, max_tokens=max_tokens)
136
143
  elif model_provider == ModelProvider.COHERE:
137
144
  from llama_index.llms.cohere import Cohere
145
+
138
146
  llm = Cohere(model=model_name, temperature=0, max_tokens=max_tokens)
139
147
  elif model_provider == ModelProvider.PRIVATE:
140
148
  from llama_index.llms.openai_like import OpenAILike
141
- llm = OpenAILike(model=model_name, temperature=0, is_function_calling_model=True,is_chat_model=True,
142
- api_base=config.private_llm_api_base, api_key=config.private_llm_api_key,
143
- max_tokens=max_tokens)
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
+ )
144
159
  else:
145
160
  raise ValueError(f"Unknown LLM provider: {model_provider}")
146
161
  return llm
147
162
 
163
+
148
164
  def is_float(value: str) -> bool:
149
165
  """Check if a string can be converted to a float."""
150
166
  try:
@@ -153,6 +169,7 @@ def is_float(value: str) -> bool:
153
169
  except ValueError:
154
170
  return False
155
171
 
172
+
156
173
  def remove_self_from_signature(func):
157
174
  """Decorator to remove 'self' from a method's signature for introspection."""
158
175
  sig = signature(func)
@@ -164,21 +181,26 @@ def remove_self_from_signature(func):
164
181
  func.__signature__ = new_sig
165
182
  return func
166
183
 
167
- async def summarize_vectara_document(corpus_key: str, vectara_api_key: str, doc_id: str) -> str:
184
+
185
+ async def summarize_vectara_document(
186
+ llm_name: str, corpus_key: str, api_key: str, doc_id: str
187
+ ) -> str:
168
188
  """
169
189
  Summarize a document in a Vectara corpus using the Vectara API.
170
190
  """
171
191
  url = f"https://api.vectara.io/v2/corpora/{corpus_key}/documents/{doc_id}/summarize"
172
192
 
173
- payload = json.dumps({
174
- "llm_name": "gpt-4o",
175
- "model_parameters": {},
176
- "stream_response": False
177
- })
193
+ payload = json.dumps(
194
+ {
195
+ "llm_name": llm_name,
196
+ "model_parameters": {"temperature": 0.0},
197
+ "stream_response": False,
198
+ }
199
+ )
178
200
  headers = {
179
- 'Content-Type': 'application/json',
180
- 'Accept': 'application/json',
181
- 'x-api-key': vectara_api_key
201
+ "Content-Type": "application/json",
202
+ "Accept": "application/json",
203
+ "x-api-key": api_key,
182
204
  }
183
205
  timeout = aiohttp.ClientTimeout(total=60)
184
206
  async with aiohttp.ClientSession(timeout=timeout) as session:
@@ -193,18 +215,24 @@ async def summarize_vectara_document(corpus_key: str, vectara_api_key: str, doc_
193
215
  return data["summary"]
194
216
  return json.loads(response.text)["summary"]
195
217
 
218
+
196
219
  async def summarize_documents(
197
- vectara_corpus_key: str,
198
- vectara_api_key: str,
199
- doc_ids: list[str]
220
+ corpus_key: str,
221
+ api_key: str,
222
+ doc_ids: list[str],
223
+ llm_name: str = "gpt-4o",
200
224
  ) -> dict[str, str]:
201
225
  """
202
226
  Summarize multiple documents in a Vectara corpus using the Vectara API.
203
227
  """
204
228
  if not doc_ids:
205
229
  return {}
230
+ if llm_name is None:
231
+ llm_name = "gpt-4o"
206
232
  tasks = [
207
- summarize_vectara_document(vectara_corpus_key, vectara_api_key, doc_id)
233
+ summarize_vectara_document(
234
+ corpus_key=corpus_key, api_key=api_key, llm_name=llm_name, doc_id=doc_id
235
+ )
208
236
  for doc_id in doc_ids
209
237
  ]
210
238
  summaries = await asyncio.gather(*tasks, return_exceptions=True)