waldiez 0.2.1__py3-none-any.whl → 0.3.0__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 waldiez might be problematic. Click here for more details.
- waldiez/__init__.py +2 -0
- waldiez/__main__.py +2 -0
- waldiez/_version.py +3 -1
- waldiez/cli.py +13 -3
- waldiez/cli_extras.py +25 -27
- waldiez/conflict_checker.py +4 -3
- waldiez/exporter.py +28 -105
- waldiez/exporting/__init__.py +8 -9
- waldiez/exporting/agent/__init__.py +7 -0
- waldiez/exporting/agent/agent_exporter.py +279 -0
- waldiez/exporting/agent/utils/__init__.py +23 -0
- waldiez/exporting/agent/utils/agent_class_name.py +34 -0
- waldiez/exporting/agent/utils/agent_imports.py +50 -0
- waldiez/exporting/{agents → agent/utils}/code_execution.py +9 -11
- waldiez/exporting/{agents → agent/utils}/group_manager.py +47 -35
- waldiez/exporting/{agents → agent/utils}/rag_user/__init__.py +2 -0
- waldiez/exporting/{agents → agent/utils}/rag_user/chroma_utils.py +22 -17
- waldiez/exporting/{agents → agent/utils}/rag_user/mongo_utils.py +14 -10
- waldiez/exporting/{agents → agent/utils}/rag_user/pgvector_utils.py +12 -8
- waldiez/exporting/{agents → agent/utils}/rag_user/qdrant_utils.py +11 -8
- waldiez/exporting/{agents → agent/utils}/rag_user/rag_user.py +78 -55
- waldiez/exporting/{agents → agent/utils}/rag_user/vector_db.py +10 -8
- waldiez/exporting/agent/utils/swarm_agent.py +463 -0
- waldiez/exporting/{agents → agent/utils}/teachability.py +10 -6
- waldiez/exporting/{agents → agent/utils}/termination_message.py +7 -8
- waldiez/exporting/base/__init__.py +25 -0
- waldiez/exporting/base/agent_position.py +75 -0
- waldiez/exporting/base/base_exporter.py +118 -0
- waldiez/exporting/base/export_position.py +48 -0
- waldiez/exporting/base/import_position.py +23 -0
- waldiez/exporting/base/mixin.py +134 -0
- waldiez/exporting/base/utils/__init__.py +18 -0
- waldiez/exporting/{utils → base/utils}/comments.py +12 -55
- waldiez/exporting/{utils → base/utils}/naming.py +14 -4
- waldiez/exporting/base/utils/path_check.py +68 -0
- waldiez/exporting/{utils/object_string.py → base/utils/to_string.py} +21 -20
- waldiez/exporting/chats/__init__.py +5 -12
- waldiez/exporting/chats/chats_exporter.py +240 -0
- waldiez/exporting/chats/utils/__init__.py +15 -0
- waldiez/exporting/chats/utils/common.py +81 -0
- waldiez/exporting/chats/{nested.py → utils/nested.py} +125 -86
- waldiez/exporting/chats/utils/sequential.py +244 -0
- waldiez/exporting/chats/utils/single_chat.py +313 -0
- waldiez/exporting/chats/utils/swarm.py +207 -0
- waldiez/exporting/flow/__init__.py +5 -3
- waldiez/exporting/flow/flow_exporter.py +503 -0
- waldiez/exporting/flow/utils/__init__.py +47 -0
- waldiez/exporting/flow/utils/agent_utils.py +204 -0
- waldiez/exporting/flow/utils/chat_utils.py +71 -0
- waldiez/exporting/flow/utils/def_main.py +62 -0
- waldiez/exporting/flow/utils/flow_content.py +112 -0
- waldiez/exporting/flow/utils/flow_names.py +115 -0
- waldiez/exporting/flow/utils/importing_utils.py +179 -0
- waldiez/exporting/{utils → flow/utils}/logging_utils.py +34 -31
- waldiez/exporting/models/__init__.py +7 -242
- waldiez/exporting/models/models_exporter.py +192 -0
- waldiez/exporting/models/utils.py +166 -0
- waldiez/exporting/skills/__init__.py +7 -161
- waldiez/exporting/skills/skills_exporter.py +169 -0
- waldiez/exporting/skills/utils.py +281 -0
- waldiez/models/__init__.py +25 -7
- waldiez/models/agents/__init__.py +70 -0
- waldiez/models/agents/agent/__init__.py +11 -1
- waldiez/models/agents/agent/agent.py +9 -4
- waldiez/models/agents/agent/agent_data.py +3 -1
- waldiez/models/agents/agent/code_execution.py +2 -0
- waldiez/models/agents/agent/linked_skill.py +2 -0
- waldiez/models/agents/agent/nested_chat.py +2 -0
- waldiez/models/agents/agent/teachability.py +2 -0
- waldiez/models/agents/agent/termination_message.py +49 -13
- waldiez/models/agents/agents.py +15 -3
- waldiez/models/agents/assistant/__init__.py +2 -0
- waldiez/models/agents/assistant/assistant.py +2 -0
- waldiez/models/agents/assistant/assistant_data.py +2 -0
- waldiez/models/agents/group_manager/__init__.py +9 -1
- waldiez/models/agents/group_manager/group_manager.py +2 -0
- waldiez/models/agents/group_manager/group_manager_data.py +2 -0
- waldiez/models/agents/group_manager/speakers.py +49 -13
- waldiez/models/agents/rag_user/__init__.py +21 -4
- waldiez/models/agents/rag_user/rag_user.py +3 -1
- waldiez/models/agents/rag_user/rag_user_data.py +2 -0
- waldiez/models/agents/rag_user/retrieve_config.py +268 -17
- waldiez/models/agents/rag_user/vector_db_config.py +5 -3
- waldiez/models/agents/swarm_agent/__init__.py +49 -0
- waldiez/models/agents/swarm_agent/after_work.py +178 -0
- waldiez/models/agents/swarm_agent/on_condition.py +103 -0
- waldiez/models/agents/swarm_agent/on_condition_available.py +140 -0
- waldiez/models/agents/swarm_agent/on_condition_target.py +40 -0
- waldiez/models/agents/swarm_agent/swarm_agent.py +107 -0
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +125 -0
- waldiez/models/agents/swarm_agent/update_system_message.py +144 -0
- waldiez/models/agents/user_proxy/__init__.py +2 -0
- waldiez/models/agents/user_proxy/user_proxy.py +2 -0
- waldiez/models/agents/user_proxy/user_proxy_data.py +2 -0
- waldiez/models/chat/__init__.py +21 -3
- waldiez/models/chat/chat.py +241 -7
- waldiez/models/chat/chat_data.py +192 -48
- waldiez/models/chat/chat_message.py +153 -144
- waldiez/models/chat/chat_nested.py +33 -53
- waldiez/models/chat/chat_summary.py +2 -0
- waldiez/models/common/__init__.py +6 -6
- waldiez/models/common/base.py +4 -1
- waldiez/models/common/method_utils.py +163 -83
- waldiez/models/flow/__init__.py +2 -0
- waldiez/models/flow/flow.py +176 -40
- waldiez/models/flow/flow_data.py +63 -2
- waldiez/models/flow/utils.py +172 -0
- waldiez/models/model/__init__.py +2 -0
- waldiez/models/model/model.py +25 -6
- waldiez/models/model/model_data.py +3 -1
- waldiez/models/skill/__init__.py +4 -1
- waldiez/models/skill/skill.py +30 -2
- waldiez/models/skill/skill_data.py +2 -0
- waldiez/models/waldiez.py +28 -4
- waldiez/runner.py +142 -228
- waldiez/running/__init__.py +33 -0
- waldiez/running/environment.py +83 -0
- waldiez/running/gen_seq_diagram.py +185 -0
- waldiez/running/running.py +300 -0
- {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/METADATA +36 -30
- waldiez-0.3.0.dist-info/RECORD +125 -0
- waldiez-0.3.0.dist-info/licenses/LICENSE +201 -0
- waldiez/exporting/agents/__init__.py +0 -5
- waldiez/exporting/agents/agent.py +0 -236
- waldiez/exporting/agents/agent_skills.py +0 -67
- waldiez/exporting/agents/llm_config.py +0 -53
- waldiez/exporting/chats/chats.py +0 -46
- waldiez/exporting/chats/helpers.py +0 -420
- waldiez/exporting/flow/def_main.py +0 -32
- waldiez/exporting/flow/flow.py +0 -189
- waldiez/exporting/utils/__init__.py +0 -36
- waldiez/exporting/utils/importing.py +0 -265
- waldiez/exporting/utils/method_utils.py +0 -35
- waldiez/exporting/utils/path_check.py +0 -51
- waldiez-0.2.1.dist-info/RECORD +0 -92
- waldiez-0.2.1.dist-info/licenses/LICENSE +0 -21
- {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/WHEEL +0 -0
- {waldiez-0.2.1.dist-info → waldiez-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Get chroma db related imports and content."""
|
|
2
4
|
|
|
3
5
|
from pathlib import Path
|
|
@@ -22,19 +24,21 @@ def _get_chroma_client_string(agent: WaldiezRagUser) -> Tuple[str, str]:
|
|
|
22
24
|
The 'client' and what to import.
|
|
23
25
|
"""
|
|
24
26
|
# TODO: also check `connection_url` (chroma in client-server mode)
|
|
25
|
-
to_import = "chromadb"
|
|
27
|
+
to_import = "import chromadb"
|
|
26
28
|
client_str = "chromadb."
|
|
27
29
|
if (
|
|
28
30
|
agent.retrieve_config.db_config.use_local_storage
|
|
29
31
|
and agent.retrieve_config.db_config.local_storage_path is not None
|
|
30
32
|
):
|
|
31
|
-
# on windows, we get:
|
|
33
|
+
# on windows, we might get:
|
|
32
34
|
# SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes
|
|
33
35
|
# in position 2-3: truncated \UXXXXXXXX escape
|
|
34
36
|
local_path = Path(agent.retrieve_config.db_config.local_storage_path)
|
|
35
37
|
client_str += (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
"PersistentClient(\n"
|
|
39
|
+
f' path=r"{local_path}",' + "\n"
|
|
40
|
+
" settings=Settings(anonymized_telemetry=False),\n"
|
|
41
|
+
")"
|
|
38
42
|
)
|
|
39
43
|
else:
|
|
40
44
|
client_str += "Client(Settings(anonymized_telemetry=False))"
|
|
@@ -60,7 +64,7 @@ def _get_chroma_embedding_function_string(
|
|
|
60
64
|
"""
|
|
61
65
|
to_import = ""
|
|
62
66
|
embedding_function_arg = ""
|
|
63
|
-
|
|
67
|
+
embedding_function_content = ""
|
|
64
68
|
vector_db_model = agent.retrieve_config.db_config.model
|
|
65
69
|
if not agent.retrieve_config.use_custom_embedding:
|
|
66
70
|
to_import = (
|
|
@@ -70,13 +74,13 @@ def _get_chroma_embedding_function_string(
|
|
|
70
74
|
embedding_function_arg = "SentenceTransformerEmbeddingFunction("
|
|
71
75
|
embedding_function_arg += f'model_name="{vector_db_model}")'
|
|
72
76
|
else:
|
|
73
|
-
embedding_function_arg =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
embedding_function_content, embedding_function_arg = (
|
|
78
|
+
agent.retrieve_config.get_custom_embedding_function(
|
|
79
|
+
name_suffix=agent_name
|
|
80
|
+
)
|
|
77
81
|
)
|
|
78
|
-
|
|
79
|
-
return embedding_function_arg, to_import,
|
|
82
|
+
embedding_function_content = "\n" + embedding_function_content
|
|
83
|
+
return embedding_function_arg, to_import, embedding_function_content
|
|
80
84
|
|
|
81
85
|
|
|
82
86
|
def get_chroma_db_args(
|
|
@@ -108,8 +112,8 @@ def get_chroma_db_args(
|
|
|
108
112
|
if to_import_embedding:
|
|
109
113
|
to_import.add(to_import_embedding)
|
|
110
114
|
kwarg_string = (
|
|
111
|
-
f" client={agent_name}_client
|
|
112
|
-
f" embedding_function={embedding_function_arg}
|
|
115
|
+
f" client={agent_name}_client," + "\n"
|
|
116
|
+
f" embedding_function={embedding_function_arg}," + "\n"
|
|
113
117
|
)
|
|
114
118
|
# The RAG example:
|
|
115
119
|
# https://ag2ai.github.io/ag2/docs/notebooks/agentchat_groupchat_RAG/
|
|
@@ -118,21 +122,22 @@ def get_chroma_db_args(
|
|
|
118
122
|
# https://github.com/microsoft/autogen/issues/3551#issuecomment-2366930994
|
|
119
123
|
# manually initializing the collection before running the flow,
|
|
120
124
|
# might be a workaround.
|
|
121
|
-
content_before = f"{agent_name}_client = {client_str}\n"
|
|
125
|
+
content_before = f"{agent_name}_client = {client_str}" + "\n"
|
|
122
126
|
collection_name = agent.retrieve_config.collection_name
|
|
123
127
|
get_or_create = agent.retrieve_config.get_or_create
|
|
124
128
|
if collection_name:
|
|
125
129
|
if get_or_create:
|
|
126
130
|
content_before += (
|
|
127
131
|
f"{agent_name}_client.get_or_create_collection("
|
|
128
|
-
f'"{collection_name}")\n
|
|
132
|
+
f'"{collection_name}")' + "\n"
|
|
129
133
|
)
|
|
130
134
|
else:
|
|
131
135
|
content_before += (
|
|
132
136
|
"try:\n"
|
|
133
|
-
f' {agent_name}_client.get_collection("{collection_name}")
|
|
137
|
+
f' {agent_name}_client.get_collection("{collection_name}")'
|
|
138
|
+
+ "\n"
|
|
134
139
|
"except ValueError:\n"
|
|
135
140
|
f" {agent_name}_client.create_collection("
|
|
136
|
-
f'"{collection_name}")\n
|
|
141
|
+
f'"{collection_name}")' + "\n"
|
|
137
142
|
)
|
|
138
143
|
return kwarg_string, to_import, embedding_function_body, content_before
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Get mongodb related content and imports."""
|
|
2
4
|
|
|
3
5
|
from typing import Set, Tuple
|
|
@@ -24,7 +26,7 @@ def _get_mongodb_embedding_function_string(
|
|
|
24
26
|
"""
|
|
25
27
|
to_import = ""
|
|
26
28
|
embedding_function_arg = ""
|
|
27
|
-
|
|
29
|
+
embedding_function_content = ""
|
|
28
30
|
if not agent.retrieve_config.use_custom_embedding:
|
|
29
31
|
to_import = "from sentence_transformers import SentenceTransformer"
|
|
30
32
|
embedding_function_arg = (
|
|
@@ -33,12 +35,13 @@ def _get_mongodb_embedding_function_string(
|
|
|
33
35
|
").encode"
|
|
34
36
|
)
|
|
35
37
|
else:
|
|
36
|
-
embedding_function_arg =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
embedding_function_content, embedding_function_arg = (
|
|
39
|
+
agent.retrieve_config.get_custom_embedding_function(
|
|
40
|
+
name_suffix=agent_name
|
|
41
|
+
)
|
|
40
42
|
)
|
|
41
|
-
|
|
43
|
+
embedding_function_content = "\n" + embedding_function_content
|
|
44
|
+
return embedding_function_arg, to_import, embedding_function_content
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
def get_mongodb_db_args(
|
|
@@ -67,17 +70,18 @@ def get_mongodb_db_args(
|
|
|
67
70
|
tab = " " * 12
|
|
68
71
|
db_config = agent.retrieve_config.db_config
|
|
69
72
|
kwarg_string = (
|
|
70
|
-
f'{tab}connection_string="{db_config.connection_url}"
|
|
71
|
-
f"{tab}embedding_function={embedding_function_arg}
|
|
73
|
+
f'{tab}connection_string="{db_config.connection_url}",' + "\n"
|
|
74
|
+
f"{tab}embedding_function={embedding_function_arg}," + "\n"
|
|
72
75
|
)
|
|
73
76
|
wait_until_document_ready = db_config.wait_until_document_ready
|
|
74
77
|
wait_until_index_ready = db_config.wait_until_index_ready
|
|
75
78
|
if wait_until_document_ready is not None:
|
|
76
79
|
kwarg_string += (
|
|
77
|
-
f"{tab}wait_until_document_ready={wait_until_document_ready}
|
|
80
|
+
f"{tab}wait_until_document_ready={wait_until_document_ready},"
|
|
81
|
+
+ "\n"
|
|
78
82
|
)
|
|
79
83
|
if wait_until_index_ready is not None:
|
|
80
84
|
kwarg_string += (
|
|
81
|
-
f"{tab}wait_until_index_ready={wait_until_index_ready}
|
|
85
|
+
f"{tab}wait_until_index_ready={wait_until_index_ready}," + "\n"
|
|
82
86
|
)
|
|
83
87
|
return kwarg_string, to_import, embedding_function_body
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Get pgvector related content and imports."""
|
|
2
4
|
|
|
3
5
|
from typing import Set, Tuple
|
|
@@ -18,7 +20,7 @@ def _get_pgvector_client_string(agent: WaldiezRagUser) -> Tuple[str, str]:
|
|
|
18
20
|
Tuple[str, str]
|
|
19
21
|
The 'client' and what to import.
|
|
20
22
|
"""
|
|
21
|
-
to_import = "psycopg"
|
|
23
|
+
to_import = "import psycopg"
|
|
22
24
|
client_str = "psycopg."
|
|
23
25
|
connection_url = agent.retrieve_config.db_config.connection_url
|
|
24
26
|
client_str += f'connect("{connection_url}")'
|
|
@@ -44,20 +46,22 @@ def _get_pgvector_embedding_function_string(
|
|
|
44
46
|
"""
|
|
45
47
|
to_import = ""
|
|
46
48
|
embedding_function_arg = ""
|
|
47
|
-
|
|
49
|
+
embedding_function_content = ""
|
|
48
50
|
if agent.retrieve_config.use_custom_embedding:
|
|
49
51
|
embedding_function_arg = f"custom_embedding_function_{agent_name}"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
embedding_function_content, embedding_function_arg = (
|
|
53
|
+
agent.retrieve_config.get_custom_embedding_function(
|
|
54
|
+
name_suffix=agent_name
|
|
55
|
+
)
|
|
53
56
|
)
|
|
57
|
+
embedding_function_content = "\n" + embedding_function_content
|
|
54
58
|
else:
|
|
55
59
|
to_import = "from sentence_transformers import SentenceTransformer"
|
|
56
60
|
embedding_function_arg = "SentenceTransformer("
|
|
57
61
|
embedding_function_arg += (
|
|
58
62
|
f'"{agent.retrieve_config.db_config.model}").encode'
|
|
59
63
|
)
|
|
60
|
-
return embedding_function_arg, to_import,
|
|
64
|
+
return embedding_function_arg, to_import, embedding_function_content
|
|
61
65
|
|
|
62
66
|
|
|
63
67
|
def get_pgvector_db_args(
|
|
@@ -87,7 +91,7 @@ def get_pgvector_db_args(
|
|
|
87
91
|
else {to_import_client}
|
|
88
92
|
)
|
|
89
93
|
kwarg_str = (
|
|
90
|
-
f" client={client_str}
|
|
91
|
-
f" embedding_function={embedding_function_arg}
|
|
94
|
+
f" client={client_str}," + "\n"
|
|
95
|
+
f" embedding_function={embedding_function_arg}," + "\n"
|
|
92
96
|
)
|
|
93
97
|
return kwarg_str, to_import, embedding_function_body
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""Get qdrant db related imports and content."""
|
|
2
4
|
|
|
3
5
|
from pathlib import Path
|
|
@@ -61,7 +63,7 @@ def _get_qdrant_embedding_function_string(
|
|
|
61
63
|
"""
|
|
62
64
|
to_import = ""
|
|
63
65
|
embedding_function_arg = ""
|
|
64
|
-
|
|
66
|
+
embedding_function_content = ""
|
|
65
67
|
vector_db_model = agent.retrieve_config.db_config.model
|
|
66
68
|
if not agent.retrieve_config.use_custom_embedding:
|
|
67
69
|
to_import = (
|
|
@@ -71,12 +73,13 @@ def _get_qdrant_embedding_function_string(
|
|
|
71
73
|
embedding_function_arg = "FastEmbedEmbeddingFunction("
|
|
72
74
|
embedding_function_arg += f'model_name="{vector_db_model}")'
|
|
73
75
|
else:
|
|
74
|
-
embedding_function_arg =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
embedding_function_content, embedding_function_arg = (
|
|
77
|
+
agent.retrieve_config.get_custom_embedding_function(
|
|
78
|
+
name_suffix=agent_name
|
|
79
|
+
)
|
|
78
80
|
)
|
|
79
|
-
|
|
81
|
+
embedding_function_content = "\n" + embedding_function_content
|
|
82
|
+
return embedding_function_arg, to_import, embedding_function_content
|
|
80
83
|
|
|
81
84
|
|
|
82
85
|
def get_qdrant_db_args(
|
|
@@ -106,7 +109,7 @@ def get_qdrant_db_args(
|
|
|
106
109
|
else {to_import_client}
|
|
107
110
|
)
|
|
108
111
|
kwarg_string = (
|
|
109
|
-
f" client={client_str}
|
|
110
|
-
f" embedding_function={embedding_function_arg}
|
|
112
|
+
f" client={client_str}," + "\n"
|
|
113
|
+
f" embedding_function={embedding_function_arg}," + "\n"
|
|
111
114
|
)
|
|
112
115
|
return kwarg_string, to_import, embedding_function_body
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
1
3
|
"""RAG User related exporting utils."""
|
|
2
4
|
|
|
3
|
-
from typing import Dict, List, Set, Tuple, Union
|
|
5
|
+
from typing import Callable, Dict, List, Set, Tuple, Union
|
|
4
6
|
|
|
5
7
|
from waldiez.models import (
|
|
6
8
|
WaldiezAgent,
|
|
@@ -9,14 +11,63 @@ from waldiez.models import (
|
|
|
9
11
|
WaldiezRagUserRetrieveConfig,
|
|
10
12
|
)
|
|
11
13
|
|
|
12
|
-
from ...utils import get_object_string, get_path_string
|
|
13
14
|
from .vector_db import get_rag_user_vector_db_string
|
|
14
15
|
|
|
15
16
|
|
|
17
|
+
def get_rag_user_extras(
|
|
18
|
+
agent: WaldiezAgent,
|
|
19
|
+
agent_name: str,
|
|
20
|
+
model_names: Dict[str, str],
|
|
21
|
+
path_resolver: Callable[[str], str],
|
|
22
|
+
serializer: Callable[..., str],
|
|
23
|
+
) -> Tuple[str, str, Set[str]]:
|
|
24
|
+
"""Get the RAG user extra argument, imports and content before the agent.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
agent : WaldiezAgent
|
|
29
|
+
The agent.
|
|
30
|
+
agent_name : str
|
|
31
|
+
The agent's name.
|
|
32
|
+
model_names : Dict[str, str]
|
|
33
|
+
A mapping from model id to model name.
|
|
34
|
+
path_resolver : Callable[[str], str]
|
|
35
|
+
The path resolver function.
|
|
36
|
+
serializer : Callable[..., str]
|
|
37
|
+
The serializer function.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
Tuple[str, str, Set[str]]
|
|
42
|
+
The content before the agent, the retrieve arg and the db imports.
|
|
43
|
+
"""
|
|
44
|
+
before_agent_string = ""
|
|
45
|
+
retrieve_arg = ""
|
|
46
|
+
db_imports: Set[str] = set()
|
|
47
|
+
if agent.agent_type == "rag_user" and isinstance(agent, WaldiezRagUser):
|
|
48
|
+
rag_content_before_agent, retrieve_arg, db_imports = (
|
|
49
|
+
get_rag_user_retrieve_config_str(
|
|
50
|
+
agent=agent,
|
|
51
|
+
agent_name=agent_name,
|
|
52
|
+
model_names=model_names,
|
|
53
|
+
path_resolver=path_resolver,
|
|
54
|
+
serializer=serializer,
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
if retrieve_arg:
|
|
58
|
+
retrieve_arg = "\n" + f" retrieve_config={retrieve_arg},"
|
|
59
|
+
if rag_content_before_agent:
|
|
60
|
+
before_agent_string += rag_content_before_agent
|
|
61
|
+
return before_agent_string, retrieve_arg, db_imports
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# pylint: disable=too-many-locals
|
|
16
65
|
def get_rag_user_retrieve_config_str(
|
|
17
66
|
agent: WaldiezRagUser,
|
|
18
67
|
agent_name: str,
|
|
19
68
|
model_names: Dict[str, str],
|
|
69
|
+
path_resolver: Callable[[str], str],
|
|
70
|
+
serializer: Callable[..., str],
|
|
20
71
|
) -> Tuple[str, str, Set[str]]:
|
|
21
72
|
"""Get the RAG user retrieve config string.
|
|
22
73
|
|
|
@@ -28,6 +79,10 @@ def get_rag_user_retrieve_config_str(
|
|
|
28
79
|
The agent's name.
|
|
29
80
|
model_names : Dict[str, str]
|
|
30
81
|
A mapping from model id to model name.
|
|
82
|
+
path_resolver : Callable[[str], str]
|
|
83
|
+
The path resolver function.
|
|
84
|
+
serializer : Callable[..., str]
|
|
85
|
+
The serializer function.
|
|
31
86
|
Returns
|
|
32
87
|
-------
|
|
33
88
|
Tuple[str, str, Set[str]]
|
|
@@ -43,32 +98,34 @@ def get_rag_user_retrieve_config_str(
|
|
|
43
98
|
agent_name=agent_name,
|
|
44
99
|
)
|
|
45
100
|
imports.update(db_imports)
|
|
46
|
-
args_dict = _get_args_dict(
|
|
101
|
+
args_dict = _get_args_dict(
|
|
102
|
+
agent, retrieve_config, model_names, path_resolver
|
|
103
|
+
)
|
|
47
104
|
if retrieve_config.use_custom_token_count:
|
|
48
|
-
token_count_arg_name =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"\n\n"
|
|
105
|
+
function_content, token_count_arg_name = (
|
|
106
|
+
retrieve_config.get_custom_token_count_function(
|
|
107
|
+
name_suffix=agent_name
|
|
108
|
+
)
|
|
53
109
|
)
|
|
110
|
+
before_the_args += "\n" + function_content + "\n"
|
|
54
111
|
args_dict["custom_token_count_function"] = token_count_arg_name
|
|
55
112
|
if retrieve_config.use_custom_text_split:
|
|
56
|
-
text_split_arg_name =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"\n\n"
|
|
113
|
+
function_content, text_split_arg_name = (
|
|
114
|
+
retrieve_config.get_custom_text_split_function(
|
|
115
|
+
name_suffix=agent_name
|
|
116
|
+
)
|
|
61
117
|
)
|
|
118
|
+
before_the_args += "\n" + function_content + "\n"
|
|
62
119
|
args_dict["custom_text_split_function"] = text_split_arg_name
|
|
63
120
|
# docs_path = args_dict.pop("docs_path", [])
|
|
64
|
-
args_content =
|
|
121
|
+
args_content = serializer(args_dict)
|
|
65
122
|
# get the last line (where the dict ends)
|
|
66
123
|
args_parts = args_content.split("\n")
|
|
67
124
|
before_vector_db = args_parts[:-1]
|
|
68
125
|
closing_arg = args_parts[-1]
|
|
69
126
|
args_content = "\n".join(before_vector_db)
|
|
70
127
|
# add the vector_db arg
|
|
71
|
-
args_content += f'
|
|
128
|
+
args_content += ",\n" + f' "vector_db": {vector_db_arg},' + "\n"
|
|
72
129
|
# we should not need to include the client, but let's do it
|
|
73
130
|
# to avoid later issues (with telemetry or other client settings)
|
|
74
131
|
# https://github.com/ag2ai/ag2/blob/main/autogen/agentchat/\
|
|
@@ -77,48 +134,11 @@ def get_rag_user_retrieve_config_str(
|
|
|
77
134
|
f"{agent_name}_client" in before_the_args
|
|
78
135
|
and agent.retrieve_config.vector_db == "chroma"
|
|
79
136
|
):
|
|
80
|
-
args_content += f' "client": {agent_name}_client
|
|
137
|
+
args_content += f' "client": {agent_name}_client,' + "\n"
|
|
81
138
|
args_content += closing_arg
|
|
82
139
|
return before_the_args, args_content, imports
|
|
83
140
|
|
|
84
141
|
|
|
85
|
-
def get_rag_user_extras(
|
|
86
|
-
agent: WaldiezAgent,
|
|
87
|
-
agent_name: str,
|
|
88
|
-
model_names: Dict[str, str],
|
|
89
|
-
) -> Tuple[str, str, Set[str]]:
|
|
90
|
-
"""Get the RAG user extra argument, imports and content before the agent.
|
|
91
|
-
|
|
92
|
-
Parameters
|
|
93
|
-
----------
|
|
94
|
-
agent : WaldiezAgent
|
|
95
|
-
The agent.
|
|
96
|
-
agent_name : str
|
|
97
|
-
The agent's name.
|
|
98
|
-
model_names : Dict[str, str]
|
|
99
|
-
A mapping from model id to model name.
|
|
100
|
-
|
|
101
|
-
Returns
|
|
102
|
-
-------
|
|
103
|
-
Tuple[str, str, Set[str]]
|
|
104
|
-
The content before the agent, the retrieve arg and the db imports.
|
|
105
|
-
"""
|
|
106
|
-
before_agent_string = ""
|
|
107
|
-
retrieve_arg = ""
|
|
108
|
-
db_imports: Set[str] = set()
|
|
109
|
-
if agent.agent_type == "rag_user" and isinstance(agent, WaldiezRagUser):
|
|
110
|
-
rag_content_before_agent, retrieve_arg, db_imports = (
|
|
111
|
-
get_rag_user_retrieve_config_str(
|
|
112
|
-
agent=agent, agent_name=agent_name, model_names=model_names
|
|
113
|
-
)
|
|
114
|
-
)
|
|
115
|
-
if retrieve_arg:
|
|
116
|
-
retrieve_arg = f"\n retrieve_config={retrieve_arg},"
|
|
117
|
-
if rag_content_before_agent:
|
|
118
|
-
before_agent_string += rag_content_before_agent
|
|
119
|
-
return before_agent_string, retrieve_arg, db_imports
|
|
120
|
-
|
|
121
|
-
|
|
122
142
|
def _get_model_arg(
|
|
123
143
|
agent: WaldiezRagUser,
|
|
124
144
|
retrieve_config: WaldiezRagUserRetrieveConfig,
|
|
@@ -141,6 +161,7 @@ def _get_args_dict(
|
|
|
141
161
|
agent: WaldiezRagUser,
|
|
142
162
|
retrieve_config: WaldiezRagUserRetrieveConfig,
|
|
143
163
|
model_names: Dict[str, str],
|
|
164
|
+
path_resolver: Callable[[str], str],
|
|
144
165
|
) -> Dict[str, Union[str, List[str]]]:
|
|
145
166
|
model_arg = _get_model_arg(agent, retrieve_config, model_names)
|
|
146
167
|
args_dict: Dict[str, Union[str, List[str]]] = {
|
|
@@ -160,12 +181,14 @@ def _get_args_dict(
|
|
|
160
181
|
args_dict[arg] = getattr(retrieve_config, arg)
|
|
161
182
|
docs_path: Union[str, List[str]] = []
|
|
162
183
|
if retrieve_config.docs_path:
|
|
163
|
-
|
|
184
|
+
doc_paths = (
|
|
164
185
|
retrieve_config.docs_path
|
|
165
186
|
if isinstance(retrieve_config.docs_path, list)
|
|
166
187
|
else [retrieve_config.docs_path]
|
|
167
188
|
)
|
|
168
|
-
docs_path = [
|
|
189
|
+
docs_path = [
|
|
190
|
+
item for item in [path_resolver(path) for path in doc_paths] if item
|
|
191
|
+
]
|
|
169
192
|
args_dict["docs_path"] = docs_path
|
|
170
193
|
if docs_path:
|
|
171
194
|
args_dict["docs_path"] = docs_path
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
# flake8: noqa E501
|
|
4
4
|
# pylint: disable=line-too-long
|
|
5
|
+
"""Vector DB exporting utils for RAG user agents."""
|
|
6
|
+
|
|
5
7
|
from typing import Any, Set, Tuple
|
|
6
8
|
|
|
7
9
|
from waldiez.models import WaldiezRagUser
|
|
@@ -31,15 +33,15 @@ def _get_metadata_arg(
|
|
|
31
33
|
if agent.retrieve_config.db_config.metadata:
|
|
32
34
|
tab = " "
|
|
33
35
|
indent = tab * 3
|
|
34
|
-
metadata_arg += f"{indent}metadata={{\n"
|
|
36
|
+
metadata_arg += f"{indent}metadata={{" + "\n"
|
|
35
37
|
for key, value in agent.retrieve_config.db_config.metadata.items():
|
|
36
38
|
value_string: Any = f'"{value}"'
|
|
37
39
|
if str(value).isdigit():
|
|
38
40
|
value_string = int(value)
|
|
39
41
|
elif str(value).replace(".", "").isdigit():
|
|
40
42
|
value_string = float(value)
|
|
41
|
-
metadata_arg += f'{indent} "{key}": {value_string}
|
|
42
|
-
metadata_arg += f"{indent}}}
|
|
43
|
+
metadata_arg += f'{indent} "{key}": {value_string},' + "\n"
|
|
44
|
+
metadata_arg += f"{indent}}}," + "\n"
|
|
43
45
|
return metadata_arg
|
|
44
46
|
|
|
45
47
|
|
|
@@ -109,12 +111,12 @@ def get_rag_user_vector_db_string(
|
|
|
109
111
|
agent, agent_name
|
|
110
112
|
)
|
|
111
113
|
if content_before:
|
|
112
|
-
before +=
|
|
114
|
+
before += "\n" + f"{content_before}"
|
|
113
115
|
if ef_body:
|
|
114
|
-
before +=
|
|
116
|
+
before += "\n" + f"{ef_body}" + "\n"
|
|
115
117
|
if db_imports:
|
|
116
118
|
imports.update(db_imports)
|
|
117
119
|
kwarg_string += _get_metadata_arg(agent)
|
|
118
|
-
vdb_arg = f"{vdb_class}(\n"
|
|
120
|
+
vdb_arg = f"{vdb_class}(" + "\n"
|
|
119
121
|
vdb_arg += kwarg_string + " )"
|
|
120
122
|
return before, vdb_arg, imports
|