waldiez 0.3.12__py3-none-any.whl → 0.4.1__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/_version.py +1 -1
- waldiez/cli.py +1 -3
- waldiez/exporting/agent/agent_exporter.py +5 -1
- waldiez/exporting/agent/utils/captain_agent.py +9 -12
- waldiez/exporting/agent/utils/swarm_agent.py +12 -7
- waldiez/exporting/base/utils/comments.py +1 -0
- waldiez/exporting/chats/utils/swarm.py +1 -1
- waldiez/exporting/flow/flow_exporter.py +3 -1
- waldiez/exporting/flow/utils/__init__.py +3 -6
- waldiez/exporting/flow/utils/flow_content.py +38 -0
- waldiez/exporting/flow/utils/importing_utils.py +64 -30
- waldiez/exporting/flow/utils/logging_utils.py +25 -4
- waldiez/exporting/skills/skills_exporter.py +13 -6
- waldiez/exporting/skills/utils.py +92 -6
- waldiez/models/agents/agent/__init__.py +2 -1
- waldiez/models/agents/agent/agent.py +5 -8
- waldiez/models/agents/agent/agent_type.py +11 -0
- waldiez/models/agents/captain_agent/captain_agent.py +1 -1
- waldiez/models/agents/group_manager/speakers.py +3 -0
- waldiez/models/agents/rag_user/retrieve_config.py +3 -0
- waldiez/models/agents/reasoning/reasoning_agent_reason_config.py +1 -0
- waldiez/models/agents/swarm_agent/after_work.py +13 -11
- waldiez/models/agents/swarm_agent/on_condition.py +3 -2
- waldiez/models/agents/swarm_agent/on_condition_available.py +1 -0
- waldiez/models/agents/swarm_agent/swarm_agent_data.py +3 -3
- waldiez/models/agents/swarm_agent/update_system_message.py +1 -0
- waldiez/models/chat/chat_message.py +1 -0
- waldiez/models/chat/chat_summary.py +1 -0
- waldiez/models/common/__init__.py +2 -0
- waldiez/models/common/method_utils.py +98 -0
- waldiez/models/model/__init__.py +2 -1
- waldiez/models/model/extra_requirements.py +2 -0
- waldiez/models/model/model.py +25 -6
- waldiez/models/model/model_data.py +1 -0
- waldiez/models/skill/__init__.py +4 -0
- waldiez/models/skill/extra_requirements.py +39 -0
- waldiez/models/skill/skill.py +157 -13
- waldiez/models/skill/skill_data.py +14 -0
- waldiez/models/skill/skill_type.py +8 -0
- waldiez/models/waldiez.py +36 -6
- waldiez/runner.py +19 -7
- waldiez/running/environment.py +30 -1
- waldiez/running/running.py +0 -6
- waldiez/utils/pysqlite3_checker.py +18 -5
- {waldiez-0.3.12.dist-info → waldiez-0.4.1.dist-info}/METADATA +25 -22
- {waldiez-0.3.12.dist-info → waldiez-0.4.1.dist-info}/RECORD +50 -47
- {waldiez-0.3.12.dist-info → waldiez-0.4.1.dist-info}/WHEEL +0 -0
- {waldiez-0.3.12.dist-info → waldiez-0.4.1.dist-info}/entry_points.txt +0 -0
- {waldiez-0.3.12.dist-info → waldiez-0.4.1.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.3.12.dist-info → waldiez-0.4.1.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Base agent class to be inherited by all other agents."""
|
|
4
4
|
|
|
5
|
-
from .agent import WaldiezAgent
|
|
5
|
+
from .agent import WaldiezAgent
|
|
6
6
|
from .agent_data import WaldiezAgentData
|
|
7
|
+
from .agent_type import WaldiezAgentType
|
|
7
8
|
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
8
9
|
from .linked_skill import WaldiezAgentLinkedSkill
|
|
9
10
|
from .nested_chat import WaldiezAgentNestedChat, WaldiezAgentNestedChatMessage
|
|
@@ -9,12 +9,9 @@ from typing_extensions import Annotated, Literal
|
|
|
9
9
|
|
|
10
10
|
from ...common import WaldiezBase, now
|
|
11
11
|
from .agent_data import WaldiezAgentData
|
|
12
|
+
from .agent_type import WaldiezAgentType
|
|
12
13
|
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
13
14
|
|
|
14
|
-
WaldiezAgentType = Literal[
|
|
15
|
-
"user", "assistant", "manager", "rag_user", "swarm", "reasoning", "captain"
|
|
16
|
-
]
|
|
17
|
-
|
|
18
15
|
|
|
19
16
|
class WaldiezAgent(WaldiezBase):
|
|
20
17
|
"""Waldiez Agent.
|
|
@@ -171,11 +168,11 @@ class WaldiezAgent(WaldiezBase):
|
|
|
171
168
|
elif agent_class == "SwarmAgent":
|
|
172
169
|
imports.add(
|
|
173
170
|
"from autogen import "
|
|
174
|
-
"
|
|
175
|
-
"
|
|
176
|
-
"
|
|
171
|
+
"register_hand_off, "
|
|
172
|
+
"AfterWork, "
|
|
173
|
+
"OnCondition, "
|
|
174
|
+
"UpdateSystemMessage, "
|
|
177
175
|
"AfterWorkOption, "
|
|
178
|
-
"SwarmAgent, "
|
|
179
176
|
"SwarmResult"
|
|
180
177
|
)
|
|
181
178
|
elif agent_class == "ReasoningAgent":
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez Agent types."""
|
|
4
|
+
|
|
5
|
+
from typing_extensions import Literal
|
|
6
|
+
|
|
7
|
+
# pylint: disable=line-too-long
|
|
8
|
+
# fmt: off
|
|
9
|
+
WaldiezAgentType = Literal["user", "assistant", "manager", "rag_user", "swarm", "reasoning", "captain"] # noqa: E501
|
|
10
|
+
"""Possible types of a Waldiez Agent: user, assistant, manager, rag_user, swarm, reasoning, captain.""" # noqa: E501
|
|
11
|
+
# fmt: on
|
|
@@ -16,8 +16,11 @@ WaldiezGroupManagerSpeakersSelectionMethod = Literal[
|
|
|
16
16
|
"round_robin",
|
|
17
17
|
"custom",
|
|
18
18
|
]
|
|
19
|
+
"""Possible methods for the speaker selection."""
|
|
19
20
|
WaldiezGroupManagerSpeakersSelectionMode = Literal["repeat", "transition"]
|
|
21
|
+
"""Possible selection modes: repeat, transition."""
|
|
20
22
|
WaldiezGroupManagerSpeakersTransitionsType = Literal["allowed", "disallowed"]
|
|
23
|
+
"""Possible transitions types: allowed, disallowed."""
|
|
21
24
|
|
|
22
25
|
CUSTOM_SPEAKER_SELECTION = "custom_speaker_selection"
|
|
23
26
|
CUSTOM_SPEAKER_SELECTION_ARGS = ["last_speaker", "groupchat"]
|
|
@@ -13,8 +13,11 @@ from ...common import WaldiezBase, check_function, generate_function
|
|
|
13
13
|
from .vector_db_config import WaldiezRagUserVectorDbConfig
|
|
14
14
|
|
|
15
15
|
WaldiezRagUserTask = Literal["code", "qa", "default"]
|
|
16
|
+
"""Possible tasks for the retrieve chat."""
|
|
16
17
|
WaldiezRagUserVectorDb = Literal["chroma", "pgvector", "mongodb", "qdrant"]
|
|
18
|
+
"""Possible vector dbs for the retrieve chat."""
|
|
17
19
|
WaldiezRagUserChunkMode = Literal["multi_lines", "one_line"]
|
|
20
|
+
"""Possible chunk modes for the retrieve chat."""
|
|
18
21
|
WaldiezRagUserModels: Dict[WaldiezRagUserVectorDb, str] = {
|
|
19
22
|
"chroma": "all-MiniLM-L6-v2",
|
|
20
23
|
"mongodb": "all-MiniLM-L6-v2",
|
|
@@ -17,16 +17,18 @@ from typing_extensions import Annotated, Literal, Self
|
|
|
17
17
|
from ...common import WaldiezBase, check_function, generate_function
|
|
18
18
|
|
|
19
19
|
WaldiezSwarmAfterWorkRecipientType = Literal["agent", "option", "callable"]
|
|
20
|
+
"""The possible AfterWork recipient types."""
|
|
20
21
|
WaldiezSwarmAfterWorkOption = Literal[
|
|
21
22
|
"TERMINATE", "REVERT_TO_USER", "STAY", "SWARM_MANAGER"
|
|
22
23
|
]
|
|
24
|
+
"""The possible AfterWork options."""
|
|
23
25
|
|
|
24
26
|
|
|
25
27
|
CUSTOM_AFTER_WORK = "custom_after_work"
|
|
26
28
|
CUSTOM_AFTER_WORK_ARGS = ["last_speaker", "messages", "groupchat"]
|
|
27
29
|
CUSTOM_AFTER_WORK_TYPES = (
|
|
28
|
-
["
|
|
29
|
-
"Union[AfterWorkOption,
|
|
30
|
+
["ConversableAgent", "List[Dict[str, Any]]", "GroupChat"],
|
|
31
|
+
"Union[AfterWorkOption, ConversableAgent, str]",
|
|
30
32
|
)
|
|
31
33
|
|
|
32
34
|
|
|
@@ -45,15 +47,15 @@ class WaldiezSwarmAfterWork(WaldiezBase):
|
|
|
45
47
|
recipient_type : WaldiezSwarmAfterWorkRecipientType
|
|
46
48
|
The type of recipient.
|
|
47
49
|
Can be 'agent', 'option', or 'callable'.
|
|
48
|
-
If 'agent', the recipient is a
|
|
50
|
+
If 'agent', the recipient is a Swarm Agent.
|
|
49
51
|
If 'option', the recipient is an AfterWorkOption :
|
|
50
52
|
('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER').
|
|
51
53
|
If 'callable', it should have the signature:
|
|
52
54
|
def custom_after_work(
|
|
53
|
-
last_speaker:
|
|
55
|
+
last_speaker: ConversableAgent,
|
|
54
56
|
messages: List[dict],
|
|
55
57
|
groupchat: GroupChat,
|
|
56
|
-
) -> Union[AfterWorkOption,
|
|
58
|
+
) -> Union[AfterWorkOption, ConversableAgent, str]:
|
|
57
59
|
|
|
58
60
|
"""
|
|
59
61
|
|
|
@@ -79,15 +81,15 @@ class WaldiezSwarmAfterWork(WaldiezBase):
|
|
|
79
81
|
description=(
|
|
80
82
|
"The type of recipient. "
|
|
81
83
|
"Can be 'agent', 'option', or 'callable'. "
|
|
82
|
-
"If 'agent', the recipient is a
|
|
84
|
+
"If 'agent', the recipient is a Swarm Agent. "
|
|
83
85
|
"If 'option', the recipient is an AfterWorkOption :"
|
|
84
86
|
" ('TERMINATE', 'REVERT_TO_USER', 'STAY', 'SWARM_MANAGER'). "
|
|
85
87
|
"If 'callable', it should have the signature: "
|
|
86
88
|
"def custom_after_work("
|
|
87
|
-
" last_speaker:
|
|
89
|
+
" last_speaker: ConversableAgent,"
|
|
88
90
|
" messages: List[Dict[str, Any]],"
|
|
89
91
|
" groupchat: GroupChat,"
|
|
90
|
-
") -> Union[AfterWorkOption,
|
|
92
|
+
") -> Union[AfterWorkOption, ConversableAgent, str]:"
|
|
91
93
|
),
|
|
92
94
|
),
|
|
93
95
|
]
|
|
@@ -117,13 +119,13 @@ class WaldiezSwarmAfterWork(WaldiezBase):
|
|
|
117
119
|
The recipient string and the function content if applicable.
|
|
118
120
|
"""
|
|
119
121
|
if self.recipient_type == "option":
|
|
120
|
-
return f"
|
|
122
|
+
return f"AfterWork(AfterWorkOption.{self.recipient})", ""
|
|
121
123
|
if self.recipient_type == "agent":
|
|
122
124
|
# the the recipient is passed as the agent name
|
|
123
125
|
# (and not its id), care should be taken to ensure
|
|
124
126
|
# the all the agents in the flow have unique names
|
|
125
127
|
agent_instance = agent_names.get(self.recipient, self.recipient)
|
|
126
|
-
return f"
|
|
128
|
+
return f"AfterWork({agent_instance})", ""
|
|
127
129
|
|
|
128
130
|
function_name = CUSTOM_AFTER_WORK
|
|
129
131
|
if name_prefix:
|
|
@@ -131,7 +133,7 @@ class WaldiezSwarmAfterWork(WaldiezBase):
|
|
|
131
133
|
if name_suffix:
|
|
132
134
|
function_name = f"{function_name}_{name_suffix}"
|
|
133
135
|
return (
|
|
134
|
-
f"
|
|
136
|
+
f"AfterWork({function_name})",
|
|
135
137
|
generate_function(
|
|
136
138
|
function_name=function_name,
|
|
137
139
|
function_args=CUSTOM_AFTER_WORK_ARGS,
|
|
@@ -12,6 +12,7 @@ from .on_condition_available import WaldiezSwarmOnConditionAvailable
|
|
|
12
12
|
from .on_condition_target import WaldiezSwarmOnConditionTarget
|
|
13
13
|
|
|
14
14
|
WaldiezSwarmOnConditionTargetType = Literal["agent", "nested_chat"]
|
|
15
|
+
"""Possible types for the target of the OnCondition."""
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
class WaldiezSwarmOnCondition(WaldiezBase):
|
|
@@ -30,7 +31,7 @@ class WaldiezSwarmOnCondition(WaldiezBase):
|
|
|
30
31
|
The condition for transitioning to the target agent
|
|
31
32
|
|
|
32
33
|
available: str, optional
|
|
33
|
-
Optional condition to determine if this
|
|
34
|
+
Optional condition to determine if this OnCondition is available.
|
|
34
35
|
Can be a Callable or a string. If a string, it will look up the
|
|
35
36
|
value of the context variable with that name, which should be a bool.
|
|
36
37
|
|
|
@@ -73,7 +74,7 @@ class WaldiezSwarmOnCondition(WaldiezBase):
|
|
|
73
74
|
default_factory=WaldiezSwarmOnConditionAvailable,
|
|
74
75
|
title="Available",
|
|
75
76
|
description=(
|
|
76
|
-
"Optional condition to determine if this
|
|
77
|
+
"Optional condition to determine if this OnCondition "
|
|
77
78
|
"is available."
|
|
78
79
|
),
|
|
79
80
|
),
|
|
@@ -12,6 +12,7 @@ from ...common import WaldiezBase, check_function, generate_function
|
|
|
12
12
|
WaldiezSwarmOnConditionAvailableCheckType = Literal[
|
|
13
13
|
"string", "callable", "none"
|
|
14
14
|
]
|
|
15
|
+
"""Possible types for the `available` check."""
|
|
15
16
|
|
|
16
17
|
CUSTOM_ON_CONDITION_AVAILABLE = "custom_on_condition_available"
|
|
17
18
|
CUSTOM_ON_CONDITION_AVAILABLE_ARGS = ["agent", "message"]
|
|
@@ -29,7 +29,7 @@ class WaldiezSwarmAgentData(WaldiezAgentData):
|
|
|
29
29
|
A list of functions (skill ids) to register with the agent.
|
|
30
30
|
|
|
31
31
|
update_agent_state_before_reply : List[str]
|
|
32
|
-
A list of functions, including `
|
|
32
|
+
A list of functions, including `UpdateSystemMessage`,
|
|
33
33
|
called to update the agent's state before it replies. Each function
|
|
34
34
|
is called when the agent is selected and before it speaks.
|
|
35
35
|
|
|
@@ -67,10 +67,10 @@ class WaldiezSwarmAgentData(WaldiezAgentData):
|
|
|
67
67
|
title="Update Agent State Before Reply",
|
|
68
68
|
alias="updateAgentStateBeforeReply",
|
|
69
69
|
description=(
|
|
70
|
-
"A list of functions, including
|
|
70
|
+
"A list of functions, including UpdateSystemMessage,"
|
|
71
71
|
"called to update the agent's state before it replies. "
|
|
72
72
|
" Each function is called when the agent is selected "
|
|
73
|
-
"and before it speaks. If not an
|
|
73
|
+
"and before it speaks. If not an UpdateSystemMessage, "
|
|
74
74
|
"it should be a skill id."
|
|
75
75
|
),
|
|
76
76
|
default_factory=list,
|
|
@@ -10,6 +10,7 @@ from typing_extensions import Annotated, Literal, Self
|
|
|
10
10
|
from ...common import WaldiezBase, check_function, generate_function
|
|
11
11
|
|
|
12
12
|
WaldiezSwarmUpdateFunctionType = Literal["string", "callable"]
|
|
13
|
+
"""Possible types for the update function."""
|
|
13
14
|
|
|
14
15
|
CUSTOM_UPDATE_SYSTEM_MESSAGE = "custom_update_system_message"
|
|
15
16
|
CUSTOM_UPDATE_SYSTEM_MESSAGE_ARGS = ["agent", "messages"]
|
|
@@ -12,6 +12,7 @@ from ..common import WaldiezBase, check_function, update_dict
|
|
|
12
12
|
WaldiezChatMessageType = Literal[
|
|
13
13
|
"string", "method", "rag_message_generator", "none"
|
|
14
14
|
]
|
|
15
|
+
"""Possible types for the message."""
|
|
15
16
|
|
|
16
17
|
CALLABLE_MESSAGE = "callable_message"
|
|
17
18
|
CALLABLE_MESSAGE_ARGS = ["sender", "recipient", "context"]
|
|
@@ -8,6 +8,7 @@ from .date_utils import now
|
|
|
8
8
|
from .dict_utils import update_dict
|
|
9
9
|
from .method_utils import (
|
|
10
10
|
check_function,
|
|
11
|
+
gather_code_imports,
|
|
11
12
|
generate_function,
|
|
12
13
|
get_function,
|
|
13
14
|
parse_code_string,
|
|
@@ -17,6 +18,7 @@ __all__ = [
|
|
|
17
18
|
"WaldiezBase",
|
|
18
19
|
"now",
|
|
19
20
|
"check_function",
|
|
21
|
+
"gather_code_imports",
|
|
20
22
|
"get_autogen_version",
|
|
21
23
|
"get_function",
|
|
22
24
|
"generate_function",
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
"""Function related utilities."""
|
|
4
4
|
|
|
5
5
|
import ast
|
|
6
|
+
import importlib.util
|
|
7
|
+
import sys
|
|
8
|
+
import sysconfig
|
|
9
|
+
from pathlib import Path
|
|
6
10
|
from typing import List, Optional, Tuple
|
|
7
11
|
|
|
8
12
|
import parso
|
|
@@ -12,6 +16,35 @@ import parso.tree
|
|
|
12
16
|
MAX_VAR_NAME_LENGTH = 64
|
|
13
17
|
|
|
14
18
|
|
|
19
|
+
def is_standard_library(module_name: str) -> bool:
|
|
20
|
+
"""Check if the module is part of the standard library.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
module_name : str
|
|
25
|
+
The module name.
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
bool
|
|
30
|
+
True if the module is part of the standard library.
|
|
31
|
+
"""
|
|
32
|
+
if module_name in sys.builtin_module_names:
|
|
33
|
+
return True
|
|
34
|
+
try:
|
|
35
|
+
spec = importlib.util.find_spec(module_name)
|
|
36
|
+
except BaseException: # pylint: disable=broad-except
|
|
37
|
+
return False
|
|
38
|
+
if spec is None or not spec.origin:
|
|
39
|
+
return False
|
|
40
|
+
if "site-packages" in spec.origin:
|
|
41
|
+
return False
|
|
42
|
+
if spec.origin.startswith(sys.prefix) or spec.origin == "frozen":
|
|
43
|
+
return True
|
|
44
|
+
stdlib_path = str(Path(sysconfig.get_path("stdlib")).resolve())
|
|
45
|
+
return spec.origin.startswith(stdlib_path)
|
|
46
|
+
|
|
47
|
+
|
|
15
48
|
def parse_code_string(
|
|
16
49
|
code_string: str,
|
|
17
50
|
) -> Tuple[Optional[str], Optional[ast.Module]]:
|
|
@@ -38,6 +71,71 @@ def parse_code_string(
|
|
|
38
71
|
return None, tree
|
|
39
72
|
|
|
40
73
|
|
|
74
|
+
def gather_code_imports(
|
|
75
|
+
code_string: str,
|
|
76
|
+
is_interop: bool,
|
|
77
|
+
) -> Tuple[List[str], List[str]]:
|
|
78
|
+
"""Gather the imports from the code string.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
code_string : str
|
|
83
|
+
The code string.
|
|
84
|
+
is_interop : bool
|
|
85
|
+
If True, make sure the interoperability import is present.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
Tuple[List[str], List[str]]
|
|
90
|
+
The standard library imports and the third party imports.
|
|
91
|
+
"""
|
|
92
|
+
standard_lib_imports: List[str] = []
|
|
93
|
+
third_party_imports: List[str] = []
|
|
94
|
+
tree = parso.parse(code_string) # type: ignore
|
|
95
|
+
for node in tree.iter_imports():
|
|
96
|
+
if node.type == "import_name":
|
|
97
|
+
full_import_statement = node.get_code().strip()
|
|
98
|
+
module_name = (
|
|
99
|
+
node.get_code().replace("import", "").strip().split(" ")[0]
|
|
100
|
+
)
|
|
101
|
+
if not module_name:
|
|
102
|
+
continue
|
|
103
|
+
if is_standard_library(module_name):
|
|
104
|
+
standard_lib_imports.append(full_import_statement)
|
|
105
|
+
else:
|
|
106
|
+
third_party_imports.append(full_import_statement)
|
|
107
|
+
elif node.type == "import_from":
|
|
108
|
+
full_import_statement = node.get_code().strip()
|
|
109
|
+
module_name = (
|
|
110
|
+
node.get_code().replace("from", "").strip().split(" ")[0]
|
|
111
|
+
)
|
|
112
|
+
if not module_name:
|
|
113
|
+
continue
|
|
114
|
+
if is_standard_library(module_name):
|
|
115
|
+
standard_lib_imports.append(full_import_statement)
|
|
116
|
+
else:
|
|
117
|
+
third_party_imports.append(full_import_statement)
|
|
118
|
+
if is_interop and (
|
|
119
|
+
"from autogen.interop import Interoperability"
|
|
120
|
+
not in third_party_imports
|
|
121
|
+
):
|
|
122
|
+
third_party_imports.append(
|
|
123
|
+
"from autogen.interop import Interoperability"
|
|
124
|
+
)
|
|
125
|
+
# sorted_standard_lib_imports = # first import x, then from a import b
|
|
126
|
+
sorted_standard_lib_imports = sorted(
|
|
127
|
+
[stmt for stmt in standard_lib_imports if stmt.startswith("import ")]
|
|
128
|
+
) + sorted(
|
|
129
|
+
[stmt for stmt in standard_lib_imports if stmt.startswith("from ")]
|
|
130
|
+
)
|
|
131
|
+
sorted_third_party_imports = sorted(
|
|
132
|
+
[stmt for stmt in third_party_imports if stmt.startswith("import ")]
|
|
133
|
+
) + sorted(
|
|
134
|
+
[stmt for stmt in third_party_imports if stmt.startswith("from ")]
|
|
135
|
+
)
|
|
136
|
+
return sorted_standard_lib_imports, sorted_third_party_imports
|
|
137
|
+
|
|
138
|
+
|
|
41
139
|
def check_function(
|
|
42
140
|
code_string: str,
|
|
43
141
|
function_name: str,
|
waldiez/models/model/__init__.py
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
"""Waldiez model."""
|
|
4
4
|
|
|
5
5
|
from .extra_requirements import get_models_extra_requirements
|
|
6
|
-
from .model import DEFAULT_BASE_URLS, WaldiezModel
|
|
6
|
+
from .model import DEFAULT_BASE_URLS, MODEL_NEEDS_BASE_URL, WaldiezModel
|
|
7
7
|
from .model_data import WaldiezModelAPIType, WaldiezModelData, WaldiezModelPrice
|
|
8
8
|
|
|
9
9
|
__all__ = [
|
|
10
10
|
"get_models_extra_requirements",
|
|
11
11
|
"DEFAULT_BASE_URLS",
|
|
12
|
+
"MODEL_NEEDS_BASE_URL",
|
|
12
13
|
"WaldiezModel",
|
|
13
14
|
"WaldiezModelData",
|
|
14
15
|
"WaldiezModelPrice",
|
|
@@ -36,6 +36,8 @@ def get_models_extra_requirements(
|
|
|
36
36
|
"bedrock", # we might add this later
|
|
37
37
|
]
|
|
38
38
|
for model in models:
|
|
39
|
+
for requirement in model.requirements:
|
|
40
|
+
model_requirements.add(requirement)
|
|
39
41
|
if model.data.api_type == "google":
|
|
40
42
|
model_requirements.add(f"pyautogen[gemini]=={autogen_version}")
|
|
41
43
|
continue
|
waldiez/models/model/model.py
CHANGED
|
@@ -23,6 +23,22 @@ DEFAULT_BASE_URLS: Dict[WaldiezModelAPIType, str] = {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
|
|
26
|
+
# we can omit the base_url for these models
|
|
27
|
+
MODEL_NEEDS_BASE_URL: Dict[WaldiezModelAPIType, bool] = {
|
|
28
|
+
"openai": False,
|
|
29
|
+
"azure": False,
|
|
30
|
+
"google": False,
|
|
31
|
+
"anthropic": False,
|
|
32
|
+
"cohere": False,
|
|
33
|
+
"other": False, # falls back to openai
|
|
34
|
+
"deepseek": True,
|
|
35
|
+
"mistral": True,
|
|
36
|
+
"groq": True,
|
|
37
|
+
"together": True,
|
|
38
|
+
"nim": True,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
26
42
|
class WaldiezModel(WaldiezBase):
|
|
27
43
|
"""Waldiez Model class.
|
|
28
44
|
|
|
@@ -225,10 +241,13 @@ def set_default_base_url(
|
|
|
225
241
|
Dict[str, Any]
|
|
226
242
|
The llm config dictionary with the default base url set.
|
|
227
243
|
"""
|
|
228
|
-
|
|
229
|
-
return llm_config
|
|
244
|
+
dict_copy = llm_config.copy()
|
|
230
245
|
if "base_url" not in llm_config or not llm_config["base_url"]:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
246
|
+
if MODEL_NEEDS_BASE_URL.get(api_type, True):
|
|
247
|
+
dict_copy["base_url"] = DEFAULT_BASE_URLS.get(api_type, "")
|
|
248
|
+
if (
|
|
249
|
+
not llm_config.get("base_url", "")
|
|
250
|
+
and MODEL_NEEDS_BASE_URL.get(api_type, True) is False
|
|
251
|
+
):
|
|
252
|
+
dict_copy.pop("base_url", None)
|
|
253
|
+
return dict_copy
|
waldiez/models/skill/__init__.py
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Waldiez Skill related models."""
|
|
4
4
|
|
|
5
|
+
from .extra_requirements import get_skills_extra_requirements
|
|
5
6
|
from .skill import SHARED_SKILL_NAME, WaldiezSkill
|
|
6
7
|
from .skill_data import WaldiezSkillData
|
|
8
|
+
from .skill_type import WaldiezSkillType
|
|
7
9
|
|
|
8
10
|
__all__ = [
|
|
9
11
|
"SHARED_SKILL_NAME",
|
|
10
12
|
"WaldiezSkill",
|
|
11
13
|
"WaldiezSkillData",
|
|
14
|
+
"WaldiezSkillType",
|
|
15
|
+
"get_skills_extra_requirements",
|
|
12
16
|
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez skill extra requirements."""
|
|
4
|
+
|
|
5
|
+
from typing import Iterator, Set
|
|
6
|
+
|
|
7
|
+
from .skill import WaldiezSkill
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_skills_extra_requirements(
|
|
11
|
+
skills: Iterator[WaldiezSkill],
|
|
12
|
+
autogen_version: str,
|
|
13
|
+
) -> Set[str]:
|
|
14
|
+
"""Get the skills extra requirements.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
skills : List[WaldiezSkill]
|
|
19
|
+
The skills.
|
|
20
|
+
autogen_version : str
|
|
21
|
+
The ag2 version.
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
List[str]
|
|
25
|
+
The skills extra requirements.
|
|
26
|
+
"""
|
|
27
|
+
skill_requirements: Set[str] = set()
|
|
28
|
+
for skill in skills:
|
|
29
|
+
if skill.skill_type == "langchain":
|
|
30
|
+
skill_requirements.add(
|
|
31
|
+
f"pyautogen[interop-langchain]=={autogen_version}"
|
|
32
|
+
)
|
|
33
|
+
if skill.skill_type == "crewai":
|
|
34
|
+
skill_requirements.add(
|
|
35
|
+
f"pyautogen[interop-crewai]=={autogen_version}"
|
|
36
|
+
)
|
|
37
|
+
for requirement in skill.requirements:
|
|
38
|
+
skill_requirements.add(requirement)
|
|
39
|
+
return skill_requirements
|