vectara-agentic 0.2.6__py3-none-any.whl → 0.2.8__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 +38 -71
- 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_serialization.py +110 -0
- tests/test_tools.py +1 -1
- vectara_agentic/_version.py +1 -1
- vectara_agentic/agent.py +34 -12
- vectara_agentic/db_tools.py +205 -39
- vectara_agentic/sub_query_workflow.py +20 -7
- vectara_agentic/tools.py +139 -110
- vectara_agentic/types.py +1 -0
- vectara_agentic/utils.py +76 -10
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.8.dist-info}/METADATA +2 -2
- vectara_agentic-0.2.8.dist-info/RECORD +29 -0
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.8.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.8.dist-info}/licenses/LICENSE +0 -0
- {vectara_agentic-0.2.6.dist-info → vectara_agentic-0.2.8.dist-info}/top_level.txt +0 -0
vectara_agentic/tools.py
CHANGED
|
@@ -6,9 +6,10 @@ import inspect
|
|
|
6
6
|
import re
|
|
7
7
|
import importlib
|
|
8
8
|
import os
|
|
9
|
+
import asyncio
|
|
9
10
|
|
|
10
11
|
from typing import Callable, List, Dict, Any, Optional, Union, Type
|
|
11
|
-
from pydantic import BaseModel, Field
|
|
12
|
+
from pydantic import BaseModel, Field, create_model
|
|
12
13
|
from pydantic_core import PydanticUndefined
|
|
13
14
|
|
|
14
15
|
from llama_index.core.tools import FunctionTool
|
|
@@ -20,8 +21,8 @@ from llama_index.core.workflow.context import Context
|
|
|
20
21
|
|
|
21
22
|
from .types import ToolType
|
|
22
23
|
from .tools_catalog import ToolsCatalog, get_bad_topics
|
|
23
|
-
from .db_tools import
|
|
24
|
-
from .utils import is_float
|
|
24
|
+
from .db_tools import DatabaseTools
|
|
25
|
+
from .utils import is_float, summarize_documents
|
|
25
26
|
from .agent_config import AgentConfig
|
|
26
27
|
|
|
27
28
|
LI_packages = {
|
|
@@ -31,7 +32,6 @@ LI_packages = {
|
|
|
31
32
|
"exa": ToolType.QUERY,
|
|
32
33
|
"neo4j": ToolType.QUERY,
|
|
33
34
|
"kuzu": ToolType.QUERY,
|
|
34
|
-
"database": ToolType.QUERY,
|
|
35
35
|
"google": {
|
|
36
36
|
"GmailToolSpec": {
|
|
37
37
|
"load_data": ToolType.QUERY,
|
|
@@ -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.
|
|
@@ -108,9 +109,20 @@ class VectaraTool(FunctionTool):
|
|
|
108
109
|
fn, name, description, return_direct, fn_schema, async_fn, tool_metadata,
|
|
109
110
|
callback, async_callback
|
|
110
111
|
)
|
|
111
|
-
vectara_tool = cls(
|
|
112
|
+
vectara_tool = cls(
|
|
113
|
+
tool_type=tool_type, fn=tool.fn, metadata=tool.metadata, async_fn=tool.async_fn,
|
|
114
|
+
)
|
|
112
115
|
return vectara_tool
|
|
113
116
|
|
|
117
|
+
def __str__(self) -> str:
|
|
118
|
+
return (
|
|
119
|
+
f"Tool(name={self.metadata.name}, "
|
|
120
|
+
f"Tool metadata={self.metadata})"
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def __repr__(self) -> str:
|
|
124
|
+
return str(self)
|
|
125
|
+
|
|
114
126
|
def __eq__(self, other):
|
|
115
127
|
if not isinstance(other, VectaraTool):
|
|
116
128
|
return False
|
|
@@ -161,7 +173,7 @@ class VectaraTool(FunctionTool):
|
|
|
161
173
|
self, *args: Any, ctx: Optional[Context] = None, **kwargs: Any
|
|
162
174
|
) -> ToolOutput:
|
|
163
175
|
try:
|
|
164
|
-
return super().
|
|
176
|
+
return await super().acall(*args, ctx=ctx, **kwargs)
|
|
165
177
|
except Exception as e:
|
|
166
178
|
err_output = ToolOutput(
|
|
167
179
|
tool_name=self.metadata.name,
|
|
@@ -171,6 +183,65 @@ class VectaraTool(FunctionTool):
|
|
|
171
183
|
)
|
|
172
184
|
return err_output
|
|
173
185
|
|
|
186
|
+
def _create_tool_from_dynamic_function(
|
|
187
|
+
function: Callable[..., ToolOutput],
|
|
188
|
+
tool_name: str,
|
|
189
|
+
tool_description: str,
|
|
190
|
+
base_params: list[inspect.Parameter],
|
|
191
|
+
tool_args_schema: type[BaseModel],
|
|
192
|
+
) -> VectaraTool:
|
|
193
|
+
"""
|
|
194
|
+
Create a VectaraTool from a dynamic function, including
|
|
195
|
+
setting the function signature and creating the tool schema.
|
|
196
|
+
"""
|
|
197
|
+
fields = {}
|
|
198
|
+
for param in base_params:
|
|
199
|
+
default_value = param.default if param.default != inspect.Parameter.empty else ...
|
|
200
|
+
fields[param.name] = (param.annotation, default_value)
|
|
201
|
+
for field_name, field_info in tool_args_schema.model_fields.items():
|
|
202
|
+
if field_name not in fields:
|
|
203
|
+
default_value = field_info.default if field_info.default is not PydanticUndefined else ...
|
|
204
|
+
fields[field_name] = (field_info.annotation, default_value)
|
|
205
|
+
fn_schema = create_model(f"{tool_name}", **fields)
|
|
206
|
+
|
|
207
|
+
schema_params = [
|
|
208
|
+
inspect.Parameter(
|
|
209
|
+
name=field_name,
|
|
210
|
+
kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
211
|
+
default=field_info.default if field_info.default is not PydanticUndefined else inspect.Parameter.empty,
|
|
212
|
+
annotation=field_info.annotation if hasattr(field_info, 'annotation') else field_info,
|
|
213
|
+
)
|
|
214
|
+
for field_name, field_info in tool_args_schema.model_fields.items()
|
|
215
|
+
if field_name not in [p.name for p in base_params]
|
|
216
|
+
]
|
|
217
|
+
all_params = base_params + schema_params
|
|
218
|
+
|
|
219
|
+
required_params = [p for p in all_params if p.default is inspect.Parameter.empty]
|
|
220
|
+
optional_params = [p for p in all_params if p.default is not inspect.Parameter.empty]
|
|
221
|
+
sig = inspect.Signature(required_params + optional_params)
|
|
222
|
+
function.__signature__ = sig
|
|
223
|
+
function.__annotations__["return"] = dict[str, Any]
|
|
224
|
+
function.__name__ = "_" + re.sub(r"[^A-Za-z0-9_]", "_", tool_name)
|
|
225
|
+
|
|
226
|
+
# Create the tool function signature string
|
|
227
|
+
param_strs = []
|
|
228
|
+
for param in all_params:
|
|
229
|
+
annotation = param.annotation
|
|
230
|
+
type_name = annotation.__name__ if hasattr(annotation, '__name__') else str(annotation)
|
|
231
|
+
param_strs.append(f"{param.name}: {type_name}")
|
|
232
|
+
args_str = ", ".join(param_strs)
|
|
233
|
+
function_str = f"{tool_name}({args_str}) -> str"
|
|
234
|
+
|
|
235
|
+
# Create the tool
|
|
236
|
+
tool = VectaraTool.from_defaults(
|
|
237
|
+
fn=function,
|
|
238
|
+
name=tool_name,
|
|
239
|
+
description=function_str + "\n" + tool_description,
|
|
240
|
+
fn_schema=fn_schema,
|
|
241
|
+
tool_type=ToolType.QUERY,
|
|
242
|
+
)
|
|
243
|
+
return tool
|
|
244
|
+
|
|
174
245
|
def _build_filter_string(kwargs: Dict[str, Any], tool_args_type: Dict[str, dict], fixed_filter: str) -> str:
|
|
175
246
|
"""
|
|
176
247
|
Build filter string for Vectara from kwargs
|
|
@@ -196,7 +267,7 @@ def _build_filter_string(kwargs: Dict[str, Any], tool_args_type: Dict[str, dict]
|
|
|
196
267
|
|
|
197
268
|
if value is PydanticUndefined:
|
|
198
269
|
raise ValueError(
|
|
199
|
-
f"Value of argument {key} is undefined, and this is invalid.
|
|
270
|
+
f"Value of argument {key} is undefined, and this is invalid."
|
|
200
271
|
"Please form proper arguments and try again."
|
|
201
272
|
)
|
|
202
273
|
|
|
@@ -394,7 +465,7 @@ class VectaraToolFactory:
|
|
|
394
465
|
)
|
|
395
466
|
|
|
396
467
|
# Dynamically generate the search function
|
|
397
|
-
def search_function(*args, **kwargs) -> ToolOutput:
|
|
468
|
+
def search_function(*args: Any, **kwargs: Any) -> ToolOutput:
|
|
398
469
|
"""
|
|
399
470
|
Dynamically generated function for semantic search Vectara.
|
|
400
471
|
"""
|
|
@@ -406,6 +477,7 @@ class VectaraToolFactory:
|
|
|
406
477
|
|
|
407
478
|
query = kwargs.pop("query")
|
|
408
479
|
top_k = kwargs.pop("top_k", 10)
|
|
480
|
+
summarize = kwargs.pop("summarize", True)
|
|
409
481
|
try:
|
|
410
482
|
filter_string = _build_filter_string(kwargs, tool_args_type, fixed_filter)
|
|
411
483
|
except ValueError as e:
|
|
@@ -447,13 +519,29 @@ class VectaraToolFactory:
|
|
|
447
519
|
raw_input={"args": args, "kwargs": kwargs},
|
|
448
520
|
raw_output={"response": msg},
|
|
449
521
|
)
|
|
450
|
-
tool_output = "Matching documents:\n"
|
|
451
522
|
unique_ids = set()
|
|
523
|
+
docs = []
|
|
452
524
|
for doc in response:
|
|
453
525
|
if doc.id_ in unique_ids:
|
|
454
526
|
continue
|
|
455
527
|
unique_ids.add(doc.id_)
|
|
456
|
-
|
|
528
|
+
docs.append((doc.id_, doc.metadata))
|
|
529
|
+
tool_output = "Matching documents:\n"
|
|
530
|
+
if summarize:
|
|
531
|
+
summaries_dict = asyncio.run(
|
|
532
|
+
summarize_documents(
|
|
533
|
+
self.vectara_corpus_key,
|
|
534
|
+
self.vectara_api_key,
|
|
535
|
+
list(unique_ids)
|
|
536
|
+
)
|
|
537
|
+
)
|
|
538
|
+
for doc_id, metadata in docs:
|
|
539
|
+
summary = summaries_dict.get(doc_id, "")
|
|
540
|
+
tool_output += f"document_id: '{doc_id}'\nmetadata: '{metadata}'\nsummary: '{summary}'\n\n"
|
|
541
|
+
else:
|
|
542
|
+
for doc in docs:
|
|
543
|
+
tool_output += f"document_id: '{doc.id_}'\nmetadata: '{doc.metadata}'\n\n"
|
|
544
|
+
|
|
457
545
|
out = ToolOutput(
|
|
458
546
|
tool_name=search_function.__name__,
|
|
459
547
|
content=tool_output,
|
|
@@ -462,42 +550,24 @@ class VectaraToolFactory:
|
|
|
462
550
|
)
|
|
463
551
|
return out
|
|
464
552
|
|
|
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()
|
|
553
|
+
base_params = [
|
|
554
|
+
inspect.Parameter("query", inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=str),
|
|
555
|
+
inspect.Parameter("top_k", inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=int),
|
|
556
|
+
inspect.Parameter("summarize", inspect.Parameter.POSITIONAL_OR_KEYWORD, default=True, annotation=bool),
|
|
474
557
|
]
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
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.
|
|
558
|
+
search_tool_extra_desc = tool_description + "\n" + """
|
|
559
|
+
This tool is meant to perform a search for relevant documents, it is not meant for asking questions.
|
|
560
|
+
The response includes metadata about each relevant document.
|
|
561
|
+
If summarize=True, it also includes a summary of each document, but takes a lot longer to respond,
|
|
562
|
+
so avoid using it unless necessary.
|
|
494
563
|
"""
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
564
|
+
|
|
565
|
+
tool = _create_tool_from_dynamic_function(
|
|
566
|
+
search_function,
|
|
567
|
+
tool_name,
|
|
568
|
+
search_tool_extra_desc,
|
|
569
|
+
base_params,
|
|
570
|
+
tool_args_schema,
|
|
501
571
|
)
|
|
502
572
|
return tool
|
|
503
573
|
|
|
@@ -597,11 +667,11 @@ class VectaraToolFactory:
|
|
|
597
667
|
vectara_corpus_key=self.vectara_corpus_key,
|
|
598
668
|
x_source_str="vectara-agentic",
|
|
599
669
|
vectara_base_url=vectara_base_url,
|
|
600
|
-
|
|
670
|
+
vectara_verify_ssl=vectara_verify_ssl,
|
|
601
671
|
)
|
|
602
672
|
|
|
603
673
|
# Dynamically generate the RAG function
|
|
604
|
-
def rag_function(*args, **kwargs) -> ToolOutput:
|
|
674
|
+
def rag_function(*args: Any, **kwargs: Any) -> ToolOutput:
|
|
605
675
|
"""
|
|
606
676
|
Dynamically generated function for RAG query with Vectara.
|
|
607
677
|
"""
|
|
@@ -721,39 +791,15 @@ class VectaraToolFactory:
|
|
|
721
791
|
)
|
|
722
792
|
return out
|
|
723
793
|
|
|
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()
|
|
794
|
+
base_params = [
|
|
795
|
+
inspect.Parameter("query", inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=str),
|
|
733
796
|
]
|
|
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,
|
|
797
|
+
tool = _create_tool_from_dynamic_function(
|
|
798
|
+
rag_function,
|
|
799
|
+
tool_name,
|
|
800
|
+
tool_description,
|
|
801
|
+
base_params,
|
|
802
|
+
tool_args_schema,
|
|
757
803
|
)
|
|
758
804
|
return tool
|
|
759
805
|
|
|
@@ -884,7 +930,7 @@ class ToolsFactory:
|
|
|
884
930
|
user: str = "postgres",
|
|
885
931
|
password: str = "Password",
|
|
886
932
|
dbname: str = "postgres",
|
|
887
|
-
max_rows: int =
|
|
933
|
+
max_rows: int = 1000,
|
|
888
934
|
) -> List[VectaraTool]:
|
|
889
935
|
"""
|
|
890
936
|
Returns a list of database tools.
|
|
@@ -902,24 +948,16 @@ class ToolsFactory:
|
|
|
902
948
|
dbname (str, optional): The database name. Defaults to "postgres".
|
|
903
949
|
You must specify either the sql_database object or the scheme, host, port, user, password, and dbname.
|
|
904
950
|
max_rows (int, optional): if specified, instructs the load_data tool to never return more than max_rows
|
|
905
|
-
rows. Defaults to
|
|
951
|
+
rows. Defaults to 1000.
|
|
906
952
|
|
|
907
953
|
Returns:
|
|
908
954
|
List[VectaraTool]: A list of VectaraTool objects.
|
|
909
955
|
"""
|
|
910
956
|
if sql_database:
|
|
911
|
-
|
|
912
|
-
tool_package_name="database",
|
|
913
|
-
tool_spec_name="DatabaseToolSpec",
|
|
914
|
-
tool_name_prefix=tool_name_prefix,
|
|
915
|
-
sql_database=sql_database,
|
|
916
|
-
)
|
|
957
|
+
dbt = DatabaseTools(sql_database=sql_database)
|
|
917
958
|
else:
|
|
918
959
|
if scheme in ["postgresql", "mysql", "sqlite", "mssql", "oracle"]:
|
|
919
|
-
|
|
920
|
-
tool_package_name="database",
|
|
921
|
-
tool_spec_name="DatabaseToolSpec",
|
|
922
|
-
tool_name_prefix=tool_name_prefix,
|
|
960
|
+
dbt = DatabaseTools(
|
|
923
961
|
scheme=scheme,
|
|
924
962
|
host=host,
|
|
925
963
|
port=port,
|
|
@@ -934,28 +972,19 @@ class ToolsFactory:
|
|
|
934
972
|
)
|
|
935
973
|
|
|
936
974
|
# Update tools with description
|
|
975
|
+
tools = dbt.to_tool_list()
|
|
976
|
+
vtools = []
|
|
937
977
|
for tool in tools:
|
|
938
978
|
if content_description:
|
|
939
979
|
tool.metadata.description = (
|
|
940
980
|
tool.metadata.description + f"The database tables include data about {content_description}."
|
|
941
981
|
)
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
sample_data_fn = DBLoadSampleData(load_data_fn_original)
|
|
952
|
-
sample_data_fn.__name__ = f"{tool_name_prefix}_load_sample_data"
|
|
953
|
-
sample_data_tool = self.create_tool(sample_data_fn, ToolType.QUERY)
|
|
954
|
-
|
|
955
|
-
load_unique_values_fn = DBLoadUniqueValues(load_data_fn_original)
|
|
956
|
-
load_unique_values_fn.__name__ = f"{tool_name_prefix}_load_unique_values"
|
|
957
|
-
load_unique_values_tool = self.create_tool(load_unique_values_fn, ToolType.QUERY)
|
|
958
|
-
|
|
959
|
-
tools[load_data_tool_index] = load_data_tool
|
|
960
|
-
tools.extend([sample_data_tool, load_unique_values_tool])
|
|
961
|
-
return tools
|
|
982
|
+
if len(tool_name_prefix) > 0:
|
|
983
|
+
tool.metadata.name = tool_name_prefix + "_" + tool.metadata.name
|
|
984
|
+
vtool = VectaraTool(
|
|
985
|
+
tool_type=ToolType.QUERY,
|
|
986
|
+
fn=tool.fn, async_fn=tool.async_fn,
|
|
987
|
+
metadata=tool.metadata
|
|
988
|
+
)
|
|
989
|
+
vtools.append(vtool)
|
|
990
|
+
return vtools
|
vectara_agentic/types.py
CHANGED
vectara_agentic/utils.py
CHANGED
|
@@ -5,8 +5,10 @@ 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
|
-
|
|
8
|
+
import json
|
|
9
|
+
import asyncio
|
|
9
10
|
import tiktoken
|
|
11
|
+
import aiohttp
|
|
10
12
|
|
|
11
13
|
from llama_index.core.llms import LLM
|
|
12
14
|
from llama_index.llms.openai import OpenAI
|
|
@@ -90,35 +92,53 @@ 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(
|
|
104
|
+
llm = Anthropic(
|
|
105
|
+
model=model_name, temperature=0,
|
|
106
|
+
max_tokens=max_tokens, cache_idx=2,
|
|
107
|
+
)
|
|
100
108
|
elif model_provider == ModelProvider.GEMINI:
|
|
101
109
|
from llama_index.llms.gemini import Gemini
|
|
102
|
-
llm = Gemini(
|
|
110
|
+
llm = Gemini(
|
|
111
|
+
model=model_name, temperature=0,
|
|
112
|
+
is_function_calling_model=True,
|
|
113
|
+
max_tokens=max_tokens,
|
|
114
|
+
)
|
|
103
115
|
elif model_provider == ModelProvider.TOGETHER:
|
|
104
116
|
from llama_index.llms.together import TogetherLLM
|
|
105
|
-
llm = TogetherLLM(
|
|
117
|
+
llm = TogetherLLM(
|
|
118
|
+
model=model_name, temperature=0,
|
|
119
|
+
is_function_calling_model=True,
|
|
120
|
+
max_tokens=max_tokens
|
|
121
|
+
)
|
|
106
122
|
elif model_provider == ModelProvider.GROQ:
|
|
107
123
|
from llama_index.llms.groq import Groq
|
|
108
|
-
llm = Groq(
|
|
124
|
+
llm = Groq(
|
|
125
|
+
model=model_name, temperature=0,
|
|
126
|
+
is_function_calling_model=True, max_tokens=max_tokens
|
|
127
|
+
)
|
|
109
128
|
elif model_provider == ModelProvider.FIREWORKS:
|
|
110
129
|
from llama_index.llms.fireworks import Fireworks
|
|
111
|
-
llm = Fireworks(model=model_name, temperature=0)
|
|
130
|
+
llm = Fireworks(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
112
131
|
elif model_provider == ModelProvider.BEDROCK:
|
|
113
132
|
from llama_index.llms.bedrock import Bedrock
|
|
114
|
-
llm = Bedrock(model=model_name, temperature=0)
|
|
133
|
+
llm = Bedrock(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
115
134
|
elif model_provider == ModelProvider.COHERE:
|
|
116
135
|
from llama_index.llms.cohere import Cohere
|
|
117
|
-
llm = Cohere(model=model_name, temperature=0)
|
|
136
|
+
llm = Cohere(model=model_name, temperature=0, max_tokens=max_tokens)
|
|
118
137
|
elif model_provider == ModelProvider.PRIVATE:
|
|
119
138
|
from llama_index.llms.openai_like import OpenAILike
|
|
120
139
|
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
|
|
140
|
+
api_base=config.private_llm_api_base, api_key=config.private_llm_api_key,
|
|
141
|
+
max_tokens=max_tokens)
|
|
122
142
|
else:
|
|
123
143
|
raise ValueError(f"Unknown LLM provider: {model_provider}")
|
|
124
144
|
return llm
|
|
@@ -141,3 +161,49 @@ def remove_self_from_signature(func):
|
|
|
141
161
|
new_sig = sig.replace(parameters=params)
|
|
142
162
|
func.__signature__ = new_sig
|
|
143
163
|
return func
|
|
164
|
+
|
|
165
|
+
async def summarize_vectara_document(corpus_key: str, vectara_api_key: str, doc_id: str) -> str:
|
|
166
|
+
"""
|
|
167
|
+
Summarize a document in a Vectara corpus using the Vectara API.
|
|
168
|
+
"""
|
|
169
|
+
url = f"https://api.vectara.io/v2/corpora/{corpus_key}/documents/{doc_id}/summarize"
|
|
170
|
+
|
|
171
|
+
payload = json.dumps({
|
|
172
|
+
"llm_name": "gpt-4o",
|
|
173
|
+
"model_parameters": {},
|
|
174
|
+
"stream_response": False
|
|
175
|
+
})
|
|
176
|
+
headers = {
|
|
177
|
+
'Content-Type': 'application/json',
|
|
178
|
+
'Accept': 'application/json',
|
|
179
|
+
'x-api-key': vectara_api_key
|
|
180
|
+
}
|
|
181
|
+
timeout = aiohttp.ClientTimeout(total=60)
|
|
182
|
+
async with aiohttp.ClientSession(timeout=timeout) as session:
|
|
183
|
+
async with session.post(url, headers=headers, data=payload) as response:
|
|
184
|
+
if response.status != 200:
|
|
185
|
+
error_json = await response.json()
|
|
186
|
+
return (
|
|
187
|
+
f"Vectara Summarization failed with error code {response.status}, "
|
|
188
|
+
f"error={error_json['messages'][0]}"
|
|
189
|
+
)
|
|
190
|
+
data = await response.json()
|
|
191
|
+
return data["summary"]
|
|
192
|
+
return json.loads(response.text)["summary"]
|
|
193
|
+
|
|
194
|
+
async def summarize_documents(
|
|
195
|
+
vectara_corpus_key: str,
|
|
196
|
+
vectara_api_key: str,
|
|
197
|
+
doc_ids: list[str]
|
|
198
|
+
) -> dict[str, str]:
|
|
199
|
+
"""
|
|
200
|
+
Summarize multiple documents in a Vectara corpus using the Vectara API.
|
|
201
|
+
"""
|
|
202
|
+
if not doc_ids:
|
|
203
|
+
return {}
|
|
204
|
+
tasks = [
|
|
205
|
+
summarize_vectara_document(vectara_corpus_key, vectara_api_key, doc_id)
|
|
206
|
+
for doc_id in doc_ids
|
|
207
|
+
]
|
|
208
|
+
summaries = await asyncio.gather(*tasks, return_exceptions=True)
|
|
209
|
+
return dict(zip(doc_ids, summaries))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vectara_agentic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8
|
|
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
|
|
@@ -16,7 +16,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
16
16
|
Requires-Python: >=3.10
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
|
-
Requires-Dist: llama-index==0.12.
|
|
19
|
+
Requires-Dist: llama-index==0.12.26
|
|
20
20
|
Requires-Dist: llama-index-indices-managed-vectara==0.4.2
|
|
21
21
|
Requires-Dist: llama-index-agent-llm-compiler==0.3.0
|
|
22
22
|
Requires-Dist: llama-index-agent-lats==0.3.0
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
tests/endpoint.py,sha256=frnpdZQpnuQNNKNYgAn2rFTarNG8MCJaNA77Bw_W22A,1420
|
|
3
|
+
tests/test_agent.py,sha256=t4omKBg9207hpT8b05v9TwuXJCM4knYSTdsXe740eho,4845
|
|
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_serialization.py,sha256=Ed23GN2zhSJNdPFrVK4aqLkOhJKviczR_o0t-r9TuRI,4762
|
|
9
|
+
tests/test_tools.py,sha256=IVKn0HoS2erTCr1mOEGzTkktiY0PCfKNvqnD_pizjOg,3977
|
|
10
|
+
tests/test_workflow.py,sha256=lVyrVHdRO5leYNbYtHTmKqMX0c8_xehCpUA7cXQKVsc,2175
|
|
11
|
+
vectara_agentic/__init__.py,sha256=2GLDS3U6KckK-dBRl9v_x1kSV507gEhjOfuMmmu0Qxg,850
|
|
12
|
+
vectara_agentic/_callback.py,sha256=5PfqjLmuaZIR6dnqmhniTD_zwCgfi7kOu-nexb6Kss4,9688
|
|
13
|
+
vectara_agentic/_observability.py,sha256=fTL3KW0jQU-_JSpFgjO6-XzgDut_oiq9kt4QR-FkSqU,3804
|
|
14
|
+
vectara_agentic/_prompts.py,sha256=LYyiOAiC8imz3U7MSJiuCYAP39afsp7ycXY7-9biyJI,9314
|
|
15
|
+
vectara_agentic/_version.py,sha256=HOBvs3gmojKxd7sNMHt6Q-0_rlFpgzlI1gXNZOS_Fqc,65
|
|
16
|
+
vectara_agentic/agent.py,sha256=ioC6EN86_d7SS1jEZ6CUe6OtetuGmLdWftj5bklPfMs,43522
|
|
17
|
+
vectara_agentic/agent_config.py,sha256=y1hSvU5ns0cE2R7BqF65LFstixF1ytJcoVgicGXo7w0,3691
|
|
18
|
+
vectara_agentic/agent_endpoint.py,sha256=QIMejCLlpW2qzXxeDAxv3anF46XMDdVMdKGWhJh3azY,1996
|
|
19
|
+
vectara_agentic/db_tools.py,sha256=Go03bzma9m-qDH0CPP8hWhf1nu_4S6s7ke0jGqz58Pk,10296
|
|
20
|
+
vectara_agentic/sub_query_workflow.py,sha256=3WoVnryR2NXyYXbLDM1XVLd7DtbCG0jgrVqeDUN4YNQ,10943
|
|
21
|
+
vectara_agentic/tools.py,sha256=Mm2qfJZWnbNa9G-ycYMP7NPLSo4uUJ9_y45YmXxtlSc,42571
|
|
22
|
+
vectara_agentic/tools_catalog.py,sha256=oiw3wAfbpFhh0_6rMvZsyPqWV6QIzHqhZCNzqRxuyV8,4818
|
|
23
|
+
vectara_agentic/types.py,sha256=HcS7vR8P2v2xQTlOc6ZFV2vvlr3OpzSNWhtcLMxqUZc,1792
|
|
24
|
+
vectara_agentic/utils.py,sha256=nBQqVb4_UNummqVz28DHm3VaKzy8OAq-xSjhU23uxWU,7646
|
|
25
|
+
vectara_agentic-0.2.8.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
26
|
+
vectara_agentic-0.2.8.dist-info/METADATA,sha256=IV5fm77XOPOvqfcpCZUKRxq9QgnoF3mPu-om_sTKEK8,25046
|
|
27
|
+
vectara_agentic-0.2.8.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
28
|
+
vectara_agentic-0.2.8.dist-info/top_level.txt,sha256=Y7TQTFdOYGYodQRltUGRieZKIYuzeZj2kHqAUpfCUfg,22
|
|
29
|
+
vectara_agentic-0.2.8.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
|