agently 4.0.6.6__py3-none-any.whl → 4.0.6.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.
- agently/builtins/agent_extensions/ConfigurePromptExtension.py +2 -0
- agently/builtins/plugins/ModelRequester/OpenAICompatible.py +3 -3
- agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py +6 -1
- agently/core/ModelRequest.py +170 -18
- agently/integrations/chromadb.py +159 -43
- {agently-4.0.6.6.dist-info → agently-4.0.6.8.dist-info}/METADATA +1 -1
- {agently-4.0.6.6.dist-info → agently-4.0.6.8.dist-info}/RECORD +9 -9
- {agently-4.0.6.6.dist-info → agently-4.0.6.8.dist-info}/WHEEL +0 -0
- {agently-4.0.6.6.dist-info → agently-4.0.6.8.dist-info}/licenses/LICENSE +0 -0
|
@@ -188,6 +188,7 @@ class ConfigurePromptExtension(BaseAgent):
|
|
|
188
188
|
"Cannot execute YAML prompt configures, expect prompt configures as a dictionary data but got:"
|
|
189
189
|
f"{ prompt }"
|
|
190
190
|
)
|
|
191
|
+
return self
|
|
191
192
|
|
|
192
193
|
def load_json_prompt(self, path_or_content: str, mappings: dict[str, Any] | None = None):
|
|
193
194
|
path = Path(path_or_content)
|
|
@@ -209,3 +210,4 @@ class ConfigurePromptExtension(BaseAgent):
|
|
|
209
210
|
"Cannot execute JSON prompt configures, expect prompt configures as a dictionary data but got:"
|
|
210
211
|
f"{ prompt }"
|
|
211
212
|
)
|
|
213
|
+
return self
|
|
@@ -351,13 +351,13 @@ class OpenAICompatible(ModelRequester):
|
|
|
351
351
|
api_key = self.plugin_settings.get("api_key", None)
|
|
352
352
|
if api_key is not None and auth["api_key"] == "None":
|
|
353
353
|
auth["api_key"] = str(api_key)
|
|
354
|
-
if "
|
|
355
|
-
headers_with_auth = {**request_data.headers, "Authorization": f"Bearer { auth['api_key'] }"}
|
|
356
|
-
elif "headers" in auth and isinstance(auth["headers"], dict):
|
|
354
|
+
if "headers" in auth and isinstance(auth["headers"], dict):
|
|
357
355
|
headers_with_auth = {**request_data.headers, **auth["headers"]}
|
|
358
356
|
elif "body" in auth and isinstance(auth["body"], dict):
|
|
359
357
|
headers_with_auth = request_data.headers.copy()
|
|
360
358
|
request_data.data.update(**auth["body"])
|
|
359
|
+
if "api_key" in auth and auth["api_key"] != "None":
|
|
360
|
+
headers_with_auth = {**request_data.headers, "Authorization": f"Bearer { auth['api_key'] }"}
|
|
361
361
|
else:
|
|
362
362
|
headers_with_auth = request_data.headers.copy()
|
|
363
363
|
|
|
@@ -649,7 +649,12 @@ class AgentlyPromptGenerator(PromptGenerator):
|
|
|
649
649
|
}
|
|
650
650
|
)
|
|
651
651
|
|
|
652
|
-
return create_model(
|
|
652
|
+
return create_model(
|
|
653
|
+
name,
|
|
654
|
+
__config__={'extra': 'allow'},
|
|
655
|
+
**fields,
|
|
656
|
+
**validators,
|
|
657
|
+
)
|
|
653
658
|
else:
|
|
654
659
|
item_type = Any
|
|
655
660
|
if len(schema) > 0:
|
agently/core/ModelRequest.py
CHANGED
|
@@ -22,12 +22,13 @@ ContentKindTuple: TypeAlias = Literal["all", "delta", "original"]
|
|
|
22
22
|
ContentKindStreaming: TypeAlias = Literal["instant", "streaming_parse"]
|
|
23
23
|
|
|
24
24
|
from agently.core import Prompt, ExtensionHandlers
|
|
25
|
-
from agently.utils import Settings, FunctionShifter, DataFormatter
|
|
25
|
+
from agently.utils import Settings, FunctionShifter, DataFormatter, DataLocator
|
|
26
26
|
|
|
27
27
|
if TYPE_CHECKING:
|
|
28
28
|
from agently.core import PluginManager
|
|
29
29
|
from agently.types.data import AgentlyModelResponseMessage, PromptStandardSlot, StreamingData, SerializableValue
|
|
30
30
|
from agently.types.plugins import ModelRequester, ResponseParser
|
|
31
|
+
from pydantic import BaseModel
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
class ModelResponseResult:
|
|
@@ -39,6 +40,7 @@ class ModelResponseResult:
|
|
|
39
40
|
response_generator: AsyncGenerator["AgentlyModelResponseMessage", None],
|
|
40
41
|
plugin_manager: "PluginManager",
|
|
41
42
|
settings: Settings,
|
|
43
|
+
extension_handlers: ExtensionHandlers,
|
|
42
44
|
):
|
|
43
45
|
self.agent_name = agent_name
|
|
44
46
|
self.plugin_manager = plugin_manager
|
|
@@ -50,19 +52,145 @@ class ModelResponseResult:
|
|
|
50
52
|
str(self.settings["plugins.ResponseParser.activate"]),
|
|
51
53
|
),
|
|
52
54
|
)
|
|
53
|
-
|
|
55
|
+
self._response_id = response_id
|
|
56
|
+
self._extension_handlers = extension_handlers
|
|
57
|
+
self._response_parser = ResponseParser(agent_name, response_id, prompt, response_generator, self.settings)
|
|
54
58
|
self.prompt = prompt
|
|
55
|
-
self.full_result_data = _response_parser.full_result_data
|
|
56
|
-
self.get_meta = _response_parser.get_meta
|
|
57
|
-
self.async_get_meta = _response_parser.async_get_meta
|
|
58
|
-
self.get_text = _response_parser.get_text
|
|
59
|
-
self.async_get_text = _response_parser.async_get_text
|
|
60
|
-
self.get_data = _response_parser.get_data
|
|
61
|
-
self.async_get_data = _response_parser.async_get_data
|
|
62
|
-
self.get_data_object = _response_parser.get_data_object
|
|
63
|
-
self.async_get_data_object = _response_parser.async_get_data_object
|
|
64
|
-
self.
|
|
65
|
-
self.
|
|
59
|
+
self.full_result_data = self._response_parser.full_result_data
|
|
60
|
+
self.get_meta = self._response_parser.get_meta
|
|
61
|
+
self.async_get_meta = self._response_parser.async_get_meta
|
|
62
|
+
self.get_text = self._response_parser.get_text
|
|
63
|
+
self.async_get_text = self._response_parser.async_get_text
|
|
64
|
+
# self.get_data = self._response_parser.get_data
|
|
65
|
+
# self.async_get_data = self._response_parser.async_get_data
|
|
66
|
+
# self.get_data_object = self._response_parser.get_data_object
|
|
67
|
+
# self.async_get_data_object = self._response_parser.async_get_data_object
|
|
68
|
+
self.get_data = FunctionShifter.syncify(self.async_get_data)
|
|
69
|
+
self.get_data_object = FunctionShifter.syncify(self.async_get_data_object)
|
|
70
|
+
self.get_generator = self._response_parser.get_generator
|
|
71
|
+
self.get_async_generator = self._response_parser.get_async_generator
|
|
72
|
+
|
|
73
|
+
@overload
|
|
74
|
+
async def async_get_data(
|
|
75
|
+
self,
|
|
76
|
+
*,
|
|
77
|
+
type: Literal['parsed'],
|
|
78
|
+
ensure_keys: list[str],
|
|
79
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
80
|
+
max_retries: int = 3,
|
|
81
|
+
raise_ensure_failure: bool = True,
|
|
82
|
+
_retry_count: int = 0,
|
|
83
|
+
) -> dict[str, Any]: ...
|
|
84
|
+
|
|
85
|
+
@overload
|
|
86
|
+
async def async_get_data(
|
|
87
|
+
self,
|
|
88
|
+
*,
|
|
89
|
+
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
90
|
+
ensure_keys: list[str] | None = None,
|
|
91
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
92
|
+
max_retries: int = 3,
|
|
93
|
+
raise_ensure_failure: bool = True,
|
|
94
|
+
_retry_count: int = 0,
|
|
95
|
+
) -> Any: ...
|
|
96
|
+
|
|
97
|
+
async def async_get_data(
|
|
98
|
+
self,
|
|
99
|
+
*,
|
|
100
|
+
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
101
|
+
ensure_keys: list[str] | None = None,
|
|
102
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
103
|
+
max_retries: int = 3,
|
|
104
|
+
raise_ensure_failure: bool = True,
|
|
105
|
+
_retry_count: int = 0,
|
|
106
|
+
) -> Any:
|
|
107
|
+
if type == "parsed" and ensure_keys:
|
|
108
|
+
try:
|
|
109
|
+
data = await self._response_parser.async_get_data(type=type)
|
|
110
|
+
for ensure_key in ensure_keys:
|
|
111
|
+
EMPTY = object()
|
|
112
|
+
if DataLocator.locate_path_in_dict(data, ensure_key, key_style, default=EMPTY) is EMPTY:
|
|
113
|
+
raise
|
|
114
|
+
return data
|
|
115
|
+
except:
|
|
116
|
+
from agently.base import async_system_message
|
|
117
|
+
|
|
118
|
+
await async_system_message(
|
|
119
|
+
"MODEL_REQUEST",
|
|
120
|
+
{
|
|
121
|
+
"agent_name": self.agent_name,
|
|
122
|
+
"response_id": self._response_id,
|
|
123
|
+
"content": {
|
|
124
|
+
"stage": "No Target Data in Response, Preparing Retry",
|
|
125
|
+
"detail": f"\n[Response]: { await self.async_get_text() }\n"
|
|
126
|
+
f"[Retried Times]: { _retry_count }",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
self.settings,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if _retry_count < max_retries:
|
|
133
|
+
return await ModelResponse(
|
|
134
|
+
self.agent_name,
|
|
135
|
+
self.plugin_manager,
|
|
136
|
+
self.settings,
|
|
137
|
+
self.prompt,
|
|
138
|
+
self._extension_handlers,
|
|
139
|
+
).result.async_get_data(
|
|
140
|
+
type=type,
|
|
141
|
+
ensure_keys=ensure_keys,
|
|
142
|
+
key_style=key_style,
|
|
143
|
+
max_retries=max_retries,
|
|
144
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
145
|
+
_retry_count=_retry_count + 1,
|
|
146
|
+
)
|
|
147
|
+
else:
|
|
148
|
+
if raise_ensure_failure:
|
|
149
|
+
raise ValueError(
|
|
150
|
+
f"Can not generate ensure keys { ensure_keys } within { max_retries } retires."
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
return await self._response_parser.async_get_data(type=type)
|
|
154
|
+
return await self._response_parser.async_get_data(type=type)
|
|
155
|
+
|
|
156
|
+
@overload
|
|
157
|
+
async def async_get_data_object(
|
|
158
|
+
self,
|
|
159
|
+
*,
|
|
160
|
+
ensure_keys: list[str],
|
|
161
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
162
|
+
max_retries: int = 3,
|
|
163
|
+
raise_ensure_failure: bool = True,
|
|
164
|
+
) -> "BaseModel": ...
|
|
165
|
+
|
|
166
|
+
@overload
|
|
167
|
+
async def async_get_data_object(
|
|
168
|
+
self,
|
|
169
|
+
*,
|
|
170
|
+
ensure_keys: None,
|
|
171
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
172
|
+
max_retries: int = 3,
|
|
173
|
+
raise_ensure_failure: bool = True,
|
|
174
|
+
) -> "BaseModel | None": ...
|
|
175
|
+
|
|
176
|
+
async def async_get_data_object(
|
|
177
|
+
self,
|
|
178
|
+
*,
|
|
179
|
+
ensure_keys: list[str] | None = None,
|
|
180
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
181
|
+
max_retries: int = 3,
|
|
182
|
+
raise_ensure_failure: bool = True,
|
|
183
|
+
):
|
|
184
|
+
if ensure_keys:
|
|
185
|
+
await self.async_get_data(
|
|
186
|
+
ensure_keys=ensure_keys,
|
|
187
|
+
key_style=key_style,
|
|
188
|
+
max_retries=max_retries,
|
|
189
|
+
_retry_count=0,
|
|
190
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
191
|
+
)
|
|
192
|
+
return await self._response_parser.async_get_data_object()
|
|
193
|
+
return await self._response_parser.async_get_data_object()
|
|
66
194
|
|
|
67
195
|
|
|
68
196
|
class ModelResponse:
|
|
@@ -98,8 +226,8 @@ class ModelResponse:
|
|
|
98
226
|
self._get_response_generator(),
|
|
99
227
|
self.plugin_manager,
|
|
100
228
|
self.settings,
|
|
229
|
+
self.extension_handlers,
|
|
101
230
|
)
|
|
102
|
-
self.get_result = self.result
|
|
103
231
|
self.get_meta = self.result.get_meta
|
|
104
232
|
self.async_get_meta = self.result.async_get_meta
|
|
105
233
|
self.get_text = self.result.get_text
|
|
@@ -406,7 +534,7 @@ class ModelRequest:
|
|
|
406
534
|
self.prompt.clear()
|
|
407
535
|
return response
|
|
408
536
|
|
|
409
|
-
|
|
537
|
+
def get_result(self):
|
|
410
538
|
return self.get_response().result
|
|
411
539
|
|
|
412
540
|
async def async_get_meta(self):
|
|
@@ -419,11 +547,35 @@ class ModelRequest:
|
|
|
419
547
|
self,
|
|
420
548
|
*,
|
|
421
549
|
type: Literal['original', 'parsed', 'all'] = "parsed",
|
|
550
|
+
ensure_keys: list[str] | None = None,
|
|
551
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
552
|
+
max_retries: int = 3,
|
|
553
|
+
raise_ensure_failure: bool = True,
|
|
422
554
|
):
|
|
423
|
-
|
|
555
|
+
response = self.get_response()
|
|
556
|
+
return await response.async_get_data(
|
|
557
|
+
type=type,
|
|
558
|
+
ensure_keys=ensure_keys,
|
|
559
|
+
key_style=key_style,
|
|
560
|
+
max_retries=max_retries,
|
|
561
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
562
|
+
)
|
|
424
563
|
|
|
425
|
-
async def async_get_data_object(
|
|
426
|
-
|
|
564
|
+
async def async_get_data_object(
|
|
565
|
+
self,
|
|
566
|
+
*,
|
|
567
|
+
ensure_keys: list[str] | None = None,
|
|
568
|
+
key_style: Literal["dot", "slash"] = "dot",
|
|
569
|
+
max_retries: int = 3,
|
|
570
|
+
raise_ensure_failure: bool = True,
|
|
571
|
+
):
|
|
572
|
+
response = self.get_response()
|
|
573
|
+
return await response.async_get_data_object(
|
|
574
|
+
ensure_keys=ensure_keys,
|
|
575
|
+
key_style=key_style,
|
|
576
|
+
max_retries=max_retries,
|
|
577
|
+
raise_ensure_failure=raise_ensure_failure,
|
|
578
|
+
)
|
|
427
579
|
|
|
428
580
|
@overload
|
|
429
581
|
def get_generator(
|
agently/integrations/chromadb.py
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
from agently.utils import LazyImport
|
|
1
|
+
from agently.utils import LazyImport
|
|
2
2
|
|
|
3
3
|
LazyImport.import_package("chromadb")
|
|
4
4
|
|
|
5
|
-
from typing import Callable, TypedDict, Any, TYPE_CHECKING
|
|
5
|
+
from typing import Literal, Callable, TypedDict, Any, TYPE_CHECKING, overload
|
|
6
|
+
from itertools import zip_longest
|
|
6
7
|
|
|
7
|
-
from chromadb
|
|
8
|
+
from chromadb import Client as ChromaDBClient
|
|
9
|
+
from chromadb.config import Settings
|
|
10
|
+
from chromadb.api.types import EmbeddingFunction
|
|
8
11
|
|
|
9
12
|
if TYPE_CHECKING:
|
|
10
13
|
from chromadb.api.types import (
|
|
@@ -13,9 +16,10 @@ if TYPE_CHECKING:
|
|
|
13
16
|
Embeddings,
|
|
14
17
|
QueryResult,
|
|
15
18
|
Schema,
|
|
16
|
-
CollectionMetadata,
|
|
17
19
|
DataLoader,
|
|
18
20
|
Loadable,
|
|
21
|
+
Where,
|
|
22
|
+
WhereDocument,
|
|
19
23
|
)
|
|
20
24
|
from chromadb.api.collection_configuration import CreateCollectionConfiguration
|
|
21
25
|
from chromadb.api import ClientAPI
|
|
@@ -83,29 +87,54 @@ class ChromaResults:
|
|
|
83
87
|
*,
|
|
84
88
|
queries: str | list[str],
|
|
85
89
|
results: "QueryResult",
|
|
90
|
+
distance: float | None = None,
|
|
86
91
|
):
|
|
87
92
|
if isinstance(queries, str):
|
|
88
93
|
queries = [queries]
|
|
89
|
-
|
|
94
|
+
|
|
95
|
+
ids = results.get("ids") or []
|
|
96
|
+
documents = results.get("documents")
|
|
97
|
+
metadatas = results.get("metadatas")
|
|
98
|
+
distances = results.get("distances")
|
|
99
|
+
|
|
100
|
+
if ids and len(queries) != len(ids):
|
|
90
101
|
raise ValueError(
|
|
91
|
-
f"The length of queries does not equal the length of results.\nQueries: {
|
|
102
|
+
f"The length of queries does not equal the length of results['ids'].\nQueries: {queries}\nIds: {ids}"
|
|
92
103
|
)
|
|
104
|
+
|
|
93
105
|
self._chroma_results = results
|
|
94
|
-
self._results = {}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
self._results: dict[str, list[dict]] = {}
|
|
107
|
+
|
|
108
|
+
doc_iter = documents if documents is not None else []
|
|
109
|
+
meta_iter = metadatas if metadatas is not None else []
|
|
110
|
+
dist_iter = distances if distances is not None else []
|
|
111
|
+
|
|
112
|
+
for query, row_ids, row_documents, row_metadatas, row_distances in zip_longest(
|
|
113
|
+
queries, ids, doc_iter, meta_iter, dist_iter, fillvalue=None
|
|
114
|
+
):
|
|
115
|
+
row_ids = row_ids or []
|
|
116
|
+
query_results: list[dict[str, Any]] = []
|
|
117
|
+
for id_, doc, meta, dist in zip_longest(
|
|
118
|
+
row_ids, row_documents or [], row_metadatas or [], row_distances or [], fillvalue=None
|
|
119
|
+
):
|
|
120
|
+
query_result = {"id": id_, "document": doc, "metadata": meta, "distance": dist}
|
|
121
|
+
if distance is None:
|
|
122
|
+
query_results.append(query_result)
|
|
123
|
+
else:
|
|
124
|
+
if isinstance(dist, (int, float)) and dist < distance:
|
|
125
|
+
query_results.append(query_result)
|
|
126
|
+
|
|
127
|
+
if query:
|
|
128
|
+
self._results[query] = query_results
|
|
104
129
|
|
|
105
130
|
def get_original_results(self):
|
|
106
131
|
return self._chroma_results
|
|
107
132
|
|
|
108
|
-
def get(self):
|
|
133
|
+
def get(self, *, simplify_single_result: bool = False):
|
|
134
|
+
if simplify_single_result:
|
|
135
|
+
results = list(self._results.values())
|
|
136
|
+
if len(results) == 1:
|
|
137
|
+
return results[0]
|
|
109
138
|
return self._results
|
|
110
139
|
|
|
111
140
|
|
|
@@ -113,55 +142,142 @@ class ChromaEmbeddingFunction(EmbeddingFunction):
|
|
|
113
142
|
def __init__(
|
|
114
143
|
self,
|
|
115
144
|
*,
|
|
116
|
-
|
|
117
|
-
agent: "BaseAgent | None" = None,
|
|
145
|
+
embedding_agent: "BaseAgent",
|
|
118
146
|
):
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
elif agent:
|
|
147
|
+
def embedding_function_by_agent(texts: list[str]) -> "Embeddings":
|
|
148
|
+
return embedding_agent.input(texts).start()
|
|
122
149
|
|
|
123
|
-
|
|
124
|
-
return agent.input(texts).start()
|
|
125
|
-
|
|
126
|
-
self.embedding_function = embedding_function_by_agent
|
|
127
|
-
else:
|
|
128
|
-
raise ValueError(
|
|
129
|
-
f"ChromaEmbeddingFunction() requires at least one definition for 'embedding_function' or 'agent'."
|
|
130
|
-
)
|
|
150
|
+
self.embedding_function = embedding_function_by_agent
|
|
131
151
|
|
|
132
|
-
def __call__(self, documents: "Documents") -> "Embeddings":
|
|
152
|
+
def __call__(self, documents: "Documents | list[str] | str") -> "Embeddings":
|
|
153
|
+
if isinstance(documents, str):
|
|
154
|
+
documents = [documents]
|
|
133
155
|
return self.embedding_function([document for document in documents])
|
|
134
156
|
|
|
135
157
|
|
|
136
158
|
class ChromaCollection:
|
|
159
|
+
|
|
137
160
|
def __init__(
|
|
138
161
|
self,
|
|
139
|
-
conn: "ClientAPI",
|
|
140
162
|
collection_name: str,
|
|
141
163
|
*,
|
|
164
|
+
conn: "ClientAPI | None" = None,
|
|
142
165
|
schema: "Schema | None" = None,
|
|
143
166
|
configuration: "CreateCollectionConfiguration | None" = None,
|
|
144
|
-
metadata: None = None,
|
|
145
|
-
|
|
146
|
-
agent: "BaseAgent | None" = None,
|
|
167
|
+
metadata: dict[str, Any] | None = None,
|
|
168
|
+
embedding_agent: "BaseAgent | None" = None,
|
|
147
169
|
data_loader: "DataLoader[Loadable] | None" = None,
|
|
148
170
|
get_or_create: bool = False,
|
|
171
|
+
hnsw_space: Literal["l2", "cosine", "ip"] = "cosine",
|
|
149
172
|
):
|
|
150
|
-
if
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
173
|
+
if conn is None:
|
|
174
|
+
conn = ChromaDBClient(Settings(anonymized_telemetry=False))
|
|
175
|
+
|
|
176
|
+
if metadata is None:
|
|
177
|
+
metadata = {}
|
|
178
|
+
|
|
179
|
+
metadata["hnsw:space"] = hnsw_space
|
|
180
|
+
|
|
181
|
+
self.embedding_function = (
|
|
182
|
+
ChromaEmbeddingFunction(embedding_agent=embedding_agent) if embedding_agent is not None else None
|
|
183
|
+
)
|
|
156
184
|
|
|
157
185
|
self._collection = conn.create_collection(
|
|
158
186
|
collection_name,
|
|
159
187
|
schema=schema,
|
|
160
188
|
configuration=configuration,
|
|
161
189
|
metadata=metadata,
|
|
162
|
-
embedding_function=embedding_function,
|
|
190
|
+
embedding_function=self.embedding_function,
|
|
163
191
|
data_loader=data_loader,
|
|
164
192
|
get_or_create=get_or_create,
|
|
165
193
|
)
|
|
166
194
|
|
|
167
|
-
def add(
|
|
195
|
+
def add(
|
|
196
|
+
self,
|
|
197
|
+
data: ChromaDataDict | list[ChromaDataDict] | ChromaData,
|
|
198
|
+
*,
|
|
199
|
+
embedding_function: "Callable[[str | list[str]], Embeddings] | None" = None,
|
|
200
|
+
):
|
|
201
|
+
embedding_function = embedding_function or self.embedding_function
|
|
202
|
+
if embedding_function is None:
|
|
203
|
+
raise NotImplementedError(
|
|
204
|
+
f"Embedding function must be assigned either in ChromaCollection initialize or .add() method."
|
|
205
|
+
)
|
|
206
|
+
if not isinstance(data, ChromaData):
|
|
207
|
+
data = ChromaData(data, embedding_function=embedding_function)
|
|
208
|
+
self._collection.add(**data.get_kwargs())
|
|
209
|
+
return self
|
|
210
|
+
|
|
211
|
+
@overload
|
|
212
|
+
def query(
|
|
213
|
+
self,
|
|
214
|
+
query_or_queries: str,
|
|
215
|
+
*,
|
|
216
|
+
embedding_function: "Callable[[str | list[str]], Embeddings] | None" = None,
|
|
217
|
+
top_n: int | None = None,
|
|
218
|
+
where: "Where | None" = None,
|
|
219
|
+
where_document: "WhereDocument | None" = None,
|
|
220
|
+
distance: float | None = None,
|
|
221
|
+
) -> list[dict[str, Any]]: ...
|
|
222
|
+
|
|
223
|
+
@overload
|
|
224
|
+
def query(
|
|
225
|
+
self,
|
|
226
|
+
query_or_queries: list[str],
|
|
227
|
+
*,
|
|
228
|
+
embedding_function: "Callable[[str | list[str]], Embeddings] | None" = None,
|
|
229
|
+
top_n: int | None = None,
|
|
230
|
+
where: "Where | None" = None,
|
|
231
|
+
where_document: "WhereDocument | None" = None,
|
|
232
|
+
distance: float | None = None,
|
|
233
|
+
) -> dict[str, list[dict[str, Any]]]: ...
|
|
234
|
+
|
|
235
|
+
def query(
|
|
236
|
+
self,
|
|
237
|
+
query_or_queries: str | list[str],
|
|
238
|
+
*,
|
|
239
|
+
embedding_function: "Callable[[str | list[str]], Embeddings] | None" = None,
|
|
240
|
+
top_n: int | None = None,
|
|
241
|
+
where: "Where | None" = None,
|
|
242
|
+
where_document: "WhereDocument | None" = None,
|
|
243
|
+
distance: float | None = None,
|
|
244
|
+
):
|
|
245
|
+
embedding_function = embedding_function or self.embedding_function
|
|
246
|
+
if embedding_function is None:
|
|
247
|
+
raise NotImplementedError(
|
|
248
|
+
f"Embedding function must be assigned either in ChromaCollection initialize or .query() method."
|
|
249
|
+
)
|
|
250
|
+
if not isinstance(query_or_queries, list):
|
|
251
|
+
query_or_queries = [query_or_queries]
|
|
252
|
+
return ChromaResults(
|
|
253
|
+
queries=query_or_queries,
|
|
254
|
+
results=self._collection.query(
|
|
255
|
+
query_embeddings=embedding_function(query_or_queries),
|
|
256
|
+
n_results=top_n or 10,
|
|
257
|
+
where=where,
|
|
258
|
+
where_document=where_document,
|
|
259
|
+
),
|
|
260
|
+
distance=distance,
|
|
261
|
+
).get(simplify_single_result=True)
|
|
262
|
+
|
|
263
|
+
def query_embeddings(
|
|
264
|
+
self,
|
|
265
|
+
embeddings_dict: dict[str, "Embedding"],
|
|
266
|
+
*,
|
|
267
|
+
top_n: int | None = None,
|
|
268
|
+
where: "Where | None" = None,
|
|
269
|
+
where_document: "WhereDocument | None" = None,
|
|
270
|
+
distance: float | None = None,
|
|
271
|
+
):
|
|
272
|
+
queries = [query for query in embeddings_dict.keys()]
|
|
273
|
+
embeddings = [embeddings for embeddings in embeddings_dict.values()]
|
|
274
|
+
return ChromaResults(
|
|
275
|
+
queries=queries,
|
|
276
|
+
results=self._collection.query(
|
|
277
|
+
query_embeddings=embeddings,
|
|
278
|
+
n_results=top_n or 10,
|
|
279
|
+
where=where,
|
|
280
|
+
where_document=where_document,
|
|
281
|
+
),
|
|
282
|
+
distance=distance,
|
|
283
|
+
).get(simplify_single_result=True)
|
|
@@ -4,15 +4,15 @@ agently/_default_settings.yaml,sha256=6woqJ2tjg_jl6kwSOwmTMETfVraHidort2smf0Is_q
|
|
|
4
4
|
agently/base.py,sha256=PY-HgIQesv3_oBsU25Fwe96C35C4GgpaFdxLBUwh-AA,4692
|
|
5
5
|
agently/builtins/agent_extensions/AutoFuncExtension.py,sha256=TmwMazwPzb5WXfDqfedY5yZOOMTFIHqaB9Bte29adUc,2433
|
|
6
6
|
agently/builtins/agent_extensions/ChatSessionExtension.py,sha256=Y6mvnsfAY0rykKtfp-tApwJy5O4SS-YEt2-jaWr83uc,12034
|
|
7
|
-
agently/builtins/agent_extensions/ConfigurePromptExtension.py,sha256=
|
|
7
|
+
agently/builtins/agent_extensions/ConfigurePromptExtension.py,sha256=vURsWcy5UnKppBNOAy0ZnY03yMY3QqH7j3ZeixS8VOo,10230
|
|
8
8
|
agently/builtins/agent_extensions/KeyWaiterExtension.py,sha256=Rf8dB8Yt3_9IJifpiE-Rn6lLIXqZjaNp94lnX6Betgw,5555
|
|
9
9
|
agently/builtins/agent_extensions/ToolExtension.py,sha256=S3jjumHiauEQ-m46Zkh-1I9ih02kKoj8sBEU82woz1E,6886
|
|
10
10
|
agently/builtins/agent_extensions/__init__.py,sha256=IxWRQogF8PCVNXeY7D4qhGukEx3JFvfLlUW2x0FbyfA,852
|
|
11
11
|
agently/builtins/hookers/ConsoleHooker.py,sha256=aJdDj_nG8CiwyelA505zvtpzBSwD52nFIkBRDJGgq3Y,8099
|
|
12
12
|
agently/builtins/hookers/PureLoggerHooker.py,sha256=fzN0OfhQzgns4KeCNH-qcdm-BdQT0W2kqEmt3Zp2pYI,1906
|
|
13
13
|
agently/builtins/hookers/SystemMessageHooker.py,sha256=nU5rOzcuXKdaTXWix3jhZ-4QoD4cMQJZo02wNTpZpjI,5396
|
|
14
|
-
agently/builtins/plugins/ModelRequester/OpenAICompatible.py,sha256=
|
|
15
|
-
agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py,sha256=
|
|
14
|
+
agently/builtins/plugins/ModelRequester/OpenAICompatible.py,sha256=xX-iy3qgToD8jIrPsL1NufMb6dlf0SVmX0rPjAkPSQ0,25261
|
|
15
|
+
agently/builtins/plugins/PromptGenerator/AgentlyPromptGenerator.py,sha256=6ME04zMI2fsBeVPZtDG3AynUfY8Ulz4UUDjyp6VJRhA,28624
|
|
16
16
|
agently/builtins/plugins/ResponseParser/AgentlyResponseParser.py,sha256=FEhfsiHB4Bx7HfghnObklLj08j8IVwGh0WEVD6U-G3U,17445
|
|
17
17
|
agently/builtins/plugins/ToolManager/AgentlyToolManager.py,sha256=oaqte5LAryZQMD6vuEbKhe6kOLUyZTRZswC1MDFiYxw,9138
|
|
18
18
|
agently/builtins/plugins/__init__.py,sha256=wj4_U9TTekc2CmjppbXKUREDFRXFX1y0ySOW-CxQuok,801
|
|
@@ -22,7 +22,7 @@ agently/builtins/tools/__init__.py,sha256=pFOWgH2C3xRvgQo3UVdkj4yHjF9nNtmoVHmOZf
|
|
|
22
22
|
agently/core/Agent.py,sha256=HbUqlCWFgtziavN8r-2RFQyrbHMMxKA6y-io-0CY8TA,9022
|
|
23
23
|
agently/core/EventCenter.py,sha256=sknU5w9MpGDQgMOF9c5k4PfM4SNT5X_LrpYte2HaFNM,10861
|
|
24
24
|
agently/core/ExtensionHandlers.py,sha256=88iSAW50bgMshB56cTgKg30eOjZQyXiJY1en4w7afWY,2076
|
|
25
|
-
agently/core/ModelRequest.py,sha256=
|
|
25
|
+
agently/core/ModelRequest.py,sha256=OAsNRKFiSAR_dfAdWO6efgUSQat8rHGfZ-zkiSPVNDc,22943
|
|
26
26
|
agently/core/PluginManager.py,sha256=oUnXbe1ilQTOWwnENxtGtV6wG-yZriCxniqfuxuTFO0,4354
|
|
27
27
|
agently/core/Prompt.py,sha256=8SlqytnAIM_FIWbY2Jx-T7yOs_jqmkz9cux8-2iOCjA,8023
|
|
28
28
|
agently/core/Tool.py,sha256=PNYf_BwVefr8IOqf5asLaVq2fU7hQaFJwJVj3S4fq84,1871
|
|
@@ -37,7 +37,7 @@ agently/core/TriggerFlow/process/ForEachProcess.py,sha256=oBI7KIpnj2tbczt_cTJCNv
|
|
|
37
37
|
agently/core/TriggerFlow/process/MatchCaseProcess.py,sha256=-NpbAlXq054juNkFCsDdWsIBMoHHKV1-cEsgndcd9KY,7888
|
|
38
38
|
agently/core/TriggerFlow/process/__init__.py,sha256=BP5bAr9LRVVD83KFqXeprgTmXA1iCSOSsD509BtoX_E,753
|
|
39
39
|
agently/core/__init__.py,sha256=CPglSpW5oEEmWpCpdvv9wK4myXmVipjuZm5HtMq6Vxo,1214
|
|
40
|
-
agently/integrations/chromadb.py,sha256=
|
|
40
|
+
agently/integrations/chromadb.py,sha256=hLrjwsU_d4SOGRX0bf-55uiA73YarIzRa8ORFnwu3W8,9797
|
|
41
41
|
agently/types/__init__.py,sha256=xb8GMY-ULncO_PY9rfRUsyi12wAQQJx8gAAnoM30uZA,592
|
|
42
42
|
agently/types/data/__init__.py,sha256=qladqSEqcAUW_XzdTDl4cvaraq_DpANy3aZbIPxoygk,1627
|
|
43
43
|
agently/types/data/event.py,sha256=LFQW7MN_QGOis3XV-8K6jNXWsLvT7tYxo4BZbUBCpfI,1790
|
|
@@ -70,7 +70,7 @@ agently/utils/Storage.py,sha256=E7QyNJ9T0yOUafPgdP90La698hgLMSGjhJ7qCEHzxxw,9438
|
|
|
70
70
|
agently/utils/StreamingJSONCompleter.py,sha256=aZ9zuGUTQlP-QKbXHUZCf6EtVuG49MKn8xdhw0VhDEA,4292
|
|
71
71
|
agently/utils/StreamingJSONParser.py,sha256=sPPJOtj5OYvsrukRErcoxRl4yuV1zDuf7pQ_pvw_Zow,21116
|
|
72
72
|
agently/utils/__init__.py,sha256=7MDln5OVkqFEdhhuG8VTdr2q02UWwCj-udndwzWV_iQ,1280
|
|
73
|
-
agently-4.0.6.
|
|
74
|
-
agently-4.0.6.
|
|
75
|
-
agently-4.0.6.
|
|
76
|
-
agently-4.0.6.
|
|
73
|
+
agently-4.0.6.8.dist-info/METADATA,sha256=DRFbHp8XxD7LoxfOy2KvqFfJKqKVU4gbV7nYj0Qp5Cc,7112
|
|
74
|
+
agently-4.0.6.8.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
75
|
+
agently-4.0.6.8.dist-info/licenses/LICENSE,sha256=Y5ZgAdYgMFigPT8dhN18dTLRtBshOSfWhTDRO1t0Cq4,11360
|
|
76
|
+
agently-4.0.6.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|