waldiez 0.3.11__py3-none-any.whl → 0.3.12__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/exporting/agent/agent_exporter.py +22 -15
- waldiez/exporting/agent/utils/__init__.py +2 -4
- waldiez/exporting/agent/utils/captain_agent.py +254 -0
- waldiez/exporting/flow/flow_exporter.py +3 -6
- waldiez/exporting/flow/utils/def_main.py +5 -4
- waldiez/models/__init__.py +6 -0
- waldiez/models/agents/__init__.py +14 -0
- waldiez/models/agents/agent/agent.py +71 -8
- waldiez/models/agents/agents.py +11 -1
- waldiez/models/agents/captain_agent/__init__.py +15 -0
- waldiez/models/agents/captain_agent/captain_agent.py +45 -0
- waldiez/models/agents/captain_agent/captain_agent_data.py +62 -0
- waldiez/models/agents/captain_agent/captain_agent_lib_entry.py +38 -0
- waldiez/models/agents/extra_requirements.py +88 -0
- waldiez/models/common/__init__.py +2 -0
- waldiez/models/common/ag2_version.py +30 -0
- waldiez/models/common/base.py +1 -1
- waldiez/models/common/date_utils.py +2 -0
- waldiez/models/common/dict_utils.py +2 -0
- waldiez/models/flow/__init__.py +2 -0
- waldiez/models/flow/utils.py +61 -1
- waldiez/models/model/__init__.py +2 -0
- waldiez/models/model/extra_requirements.py +55 -0
- waldiez/models/model/model.py +5 -2
- waldiez/models/model/model_data.py +2 -1
- waldiez/models/waldiez.py +16 -75
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/METADATA +27 -18
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/RECORD +33 -27
- waldiez/exporting/agent/utils/agent_class_name.py +0 -36
- waldiez/exporting/agent/utils/agent_imports.py +0 -55
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/WHEEL +0 -0
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/entry_points.txt +0 -0
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/licenses/LICENSE +0 -0
- {waldiez-0.3.11.dist-info → waldiez-0.3.12.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez captain agent model."""
|
|
4
|
+
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
from pydantic import Field
|
|
8
|
+
from typing_extensions import Annotated
|
|
9
|
+
|
|
10
|
+
from ..agent import WaldiezAgent
|
|
11
|
+
from .captain_agent_data import WaldiezCaptainAgentData
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WaldiezCaptainAgent(WaldiezAgent):
|
|
15
|
+
"""Captain agent.
|
|
16
|
+
|
|
17
|
+
A `WaldiezAgent` with agent_type `captain` and
|
|
18
|
+
captain agent's related config for the agent.
|
|
19
|
+
Also see `WaldiezAgent`, `WaldiezCaptainData`, `WaldiezAgentData`
|
|
20
|
+
|
|
21
|
+
Attributes
|
|
22
|
+
----------
|
|
23
|
+
agent_type : Literal["captain"]
|
|
24
|
+
The agent type: 'captain' for a captain agent
|
|
25
|
+
data : WaldiezCaptainData
|
|
26
|
+
The captain agent's data.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
agent_type: Annotated[
|
|
30
|
+
Literal["captain"],
|
|
31
|
+
Field(
|
|
32
|
+
"captain",
|
|
33
|
+
title="Agent type",
|
|
34
|
+
description="The agent type: 'captain' for a captain agent",
|
|
35
|
+
alias="agentType",
|
|
36
|
+
),
|
|
37
|
+
]
|
|
38
|
+
data: Annotated[
|
|
39
|
+
WaldiezCaptainAgentData,
|
|
40
|
+
Field(
|
|
41
|
+
title="Data",
|
|
42
|
+
description="The captain agent's data",
|
|
43
|
+
default_factory=WaldiezCaptainAgentData,
|
|
44
|
+
),
|
|
45
|
+
]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez captain agent data."""
|
|
4
|
+
|
|
5
|
+
from typing import List, Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import Field
|
|
8
|
+
from typing_extensions import Annotated, Literal
|
|
9
|
+
|
|
10
|
+
from ..agent import WaldiezAgentData
|
|
11
|
+
from .captain_agent_lib_entry import WaldiezCaptainAgentLibEntry
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WaldiezCaptainAgentData(WaldiezAgentData):
|
|
15
|
+
"""Captain agent data class.
|
|
16
|
+
|
|
17
|
+
The data for a captain agent.
|
|
18
|
+
Extends `WaldiezAgentData`.
|
|
19
|
+
Extra attributes:
|
|
20
|
+
- `agent_lib`: Optional list of agent lib entries
|
|
21
|
+
- `tool_lib`:
|
|
22
|
+
- `max_round`: The maximum number of rounds in a group chat
|
|
23
|
+
- `max_turns`: The maximum number of turns for a chat
|
|
24
|
+
See the parent's docs (`WaldiezAgentData`) for the rest of the properties.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
agent_lib: Annotated[
|
|
28
|
+
List[WaldiezCaptainAgentLibEntry],
|
|
29
|
+
Field(
|
|
30
|
+
default_factory=list,
|
|
31
|
+
title="Agent lib",
|
|
32
|
+
description="The agent lib",
|
|
33
|
+
alias="agentLib",
|
|
34
|
+
),
|
|
35
|
+
] = []
|
|
36
|
+
tool_lib: Annotated[
|
|
37
|
+
Optional[Literal["default"]],
|
|
38
|
+
Field(
|
|
39
|
+
None,
|
|
40
|
+
title="Tool lib",
|
|
41
|
+
description="Whether to use the default tool lib",
|
|
42
|
+
alias="toolLib",
|
|
43
|
+
),
|
|
44
|
+
] = None
|
|
45
|
+
max_round: Annotated[
|
|
46
|
+
int,
|
|
47
|
+
Field(
|
|
48
|
+
10,
|
|
49
|
+
title="Max round",
|
|
50
|
+
description="The maximum number of rounds in a group chat",
|
|
51
|
+
alias="maxRound",
|
|
52
|
+
),
|
|
53
|
+
] = 10
|
|
54
|
+
max_turns: Annotated[
|
|
55
|
+
int,
|
|
56
|
+
Field(
|
|
57
|
+
5,
|
|
58
|
+
title="Max turns",
|
|
59
|
+
description="The maximum number of turns for a chat",
|
|
60
|
+
alias="maxTurns",
|
|
61
|
+
),
|
|
62
|
+
] = 5
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez captain agent lib entry."""
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from typing_extensions import Annotated
|
|
7
|
+
|
|
8
|
+
from ...common import WaldiezBase
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WaldiezCaptainAgentLibEntry(WaldiezBase):
|
|
12
|
+
"""Captain agent lib entry."""
|
|
13
|
+
|
|
14
|
+
name: Annotated[
|
|
15
|
+
str,
|
|
16
|
+
Field(
|
|
17
|
+
...,
|
|
18
|
+
title="Name",
|
|
19
|
+
description="The name of the agent",
|
|
20
|
+
),
|
|
21
|
+
]
|
|
22
|
+
description: Annotated[
|
|
23
|
+
str,
|
|
24
|
+
Field(
|
|
25
|
+
...,
|
|
26
|
+
title="Description",
|
|
27
|
+
description="The description of the agent",
|
|
28
|
+
),
|
|
29
|
+
]
|
|
30
|
+
system_message: Annotated[
|
|
31
|
+
str,
|
|
32
|
+
Field(
|
|
33
|
+
...,
|
|
34
|
+
title="System message",
|
|
35
|
+
description="The system message",
|
|
36
|
+
alias="systemMessage",
|
|
37
|
+
),
|
|
38
|
+
]
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Extra requirements for agents."""
|
|
4
|
+
|
|
5
|
+
# pylint: disable=line-too-long
|
|
6
|
+
import platform
|
|
7
|
+
from typing import Iterator, List, Set
|
|
8
|
+
|
|
9
|
+
from .agent import WaldiezAgent
|
|
10
|
+
from .rag_user import WaldiezRagUser
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_retrievechat_extra_requirements(
|
|
14
|
+
agents: Iterator[WaldiezAgent],
|
|
15
|
+
) -> Set[str]:
|
|
16
|
+
"""Get the retrievechat extra requirements.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
agents : List[WaldiezAgent]
|
|
21
|
+
The flow agents.
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
Set[str]
|
|
26
|
+
The retrievechat extra requirements.
|
|
27
|
+
"""
|
|
28
|
+
# https://github.com/ag2ai/ag2/blob/main/pyproject.toml
|
|
29
|
+
# with chromadb relaxed
|
|
30
|
+
# to avoid conflicts with other extras and (later) allow py3.13
|
|
31
|
+
rag_requirements: Set[str] = {
|
|
32
|
+
"protobuf==4.25.3",
|
|
33
|
+
"chromadb>=0.5.23",
|
|
34
|
+
"sentence_transformers",
|
|
35
|
+
"pypdf",
|
|
36
|
+
"ipython",
|
|
37
|
+
"beautifulsoup4",
|
|
38
|
+
"markdownify",
|
|
39
|
+
}
|
|
40
|
+
for agent in agents:
|
|
41
|
+
if agent.agent_type == "rag_user" and isinstance(agent, WaldiezRagUser):
|
|
42
|
+
# if not chroma, get the relevant db requirements
|
|
43
|
+
db_type = agent.data.retrieve_config.vector_db
|
|
44
|
+
if db_type == "pgvector":
|
|
45
|
+
rag_requirements.update(
|
|
46
|
+
[
|
|
47
|
+
"pgvector>=0.2.5",
|
|
48
|
+
"psycopg[binary]>=3.2.4",
|
|
49
|
+
]
|
|
50
|
+
)
|
|
51
|
+
elif db_type == "mongodb":
|
|
52
|
+
rag_requirements.add("pymongo>=4.11")
|
|
53
|
+
elif db_type == "qdrant":
|
|
54
|
+
rag_requirements.update(["qdrant_client[fastembed]"])
|
|
55
|
+
return rag_requirements
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_captain_agent_extra_requirements() -> List[str]:
|
|
59
|
+
"""Get the captain agent extra requirements.
|
|
60
|
+
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
List[str]
|
|
64
|
+
The captain agent extra requirements.
|
|
65
|
+
"""
|
|
66
|
+
# https://github.com/ag2ai/ag2/blob/main/autogen/agentchat/contrib/captainagent/tools/requirements.txt # noqa: E501
|
|
67
|
+
tool_requirements = [
|
|
68
|
+
"markdownify",
|
|
69
|
+
"arxiv",
|
|
70
|
+
"pymupdf",
|
|
71
|
+
"wikipedia-api",
|
|
72
|
+
"easyocr",
|
|
73
|
+
"python-pptx",
|
|
74
|
+
"openai-whisper",
|
|
75
|
+
"pandas",
|
|
76
|
+
"scipy",
|
|
77
|
+
# "sentence-transformers", also in agent_requirements
|
|
78
|
+
]
|
|
79
|
+
agent_requirements = [
|
|
80
|
+
"chromadb",
|
|
81
|
+
"sentence-transformers",
|
|
82
|
+
"huggingface-hub",
|
|
83
|
+
]
|
|
84
|
+
if platform.system() == "Linux":
|
|
85
|
+
agent_requirements.append("pysqlite3-binary")
|
|
86
|
+
# on windows and OSX, installing pysqlite3-binary seem to fail in some cases
|
|
87
|
+
# we can handle/install if needed in waldiez.utils.pysqlite3_checker
|
|
88
|
+
return tool_requirements + agent_requirements
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Common utils for all models."""
|
|
4
4
|
|
|
5
|
+
from .ag2_version import get_autogen_version
|
|
5
6
|
from .base import WaldiezBase
|
|
6
7
|
from .date_utils import now
|
|
7
8
|
from .dict_utils import update_dict
|
|
@@ -16,6 +17,7 @@ __all__ = [
|
|
|
16
17
|
"WaldiezBase",
|
|
17
18
|
"now",
|
|
18
19
|
"check_function",
|
|
20
|
+
"get_autogen_version",
|
|
19
21
|
"get_function",
|
|
20
22
|
"generate_function",
|
|
21
23
|
"parse_code_string",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Get the autogen version."""
|
|
4
|
+
|
|
5
|
+
import warnings
|
|
6
|
+
from functools import cache
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@cache
|
|
10
|
+
def get_autogen_version() -> str:
|
|
11
|
+
"""Get the autogen version.
|
|
12
|
+
|
|
13
|
+
Returns
|
|
14
|
+
-------
|
|
15
|
+
str
|
|
16
|
+
The autogen version.
|
|
17
|
+
|
|
18
|
+
Raises
|
|
19
|
+
------
|
|
20
|
+
ValueError
|
|
21
|
+
If pyautogen is not installed.
|
|
22
|
+
"""
|
|
23
|
+
# pylint: disable=import-outside-toplevel
|
|
24
|
+
with warnings.catch_warnings():
|
|
25
|
+
warnings.simplefilter("ignore")
|
|
26
|
+
try:
|
|
27
|
+
from autogen.version import __version__ as ag2 # type: ignore
|
|
28
|
+
except ImportError as error: # pragma: no cover
|
|
29
|
+
raise ValueError("pyautogen is not installed.") from error
|
|
30
|
+
return ag2
|
waldiez/models/common/base.py
CHANGED
waldiez/models/flow/__init__.py
CHANGED
waldiez/models/flow/utils.py
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import uuid
|
|
6
6
|
from datetime import datetime, timezone
|
|
7
|
-
from typing import List
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
8
|
|
|
9
9
|
from ..agents import (
|
|
10
10
|
WaldiezAgent,
|
|
@@ -170,3 +170,63 @@ def merge_nested_chat_messages(
|
|
|
170
170
|
chat_ids_added.append(chat.id)
|
|
171
171
|
nested_chat.messages.sort(key=lambda x: chat_ids_added.index(x.id))
|
|
172
172
|
return [nested_chat]
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def get_flow_data(
|
|
176
|
+
data: Dict[str, Any],
|
|
177
|
+
flow_id: Optional[str] = None,
|
|
178
|
+
name: Optional[str] = None,
|
|
179
|
+
description: Optional[str] = None,
|
|
180
|
+
tags: Optional[List[str]] = None,
|
|
181
|
+
requirements: Optional[List[str]] = None,
|
|
182
|
+
) -> Dict[str, Any]:
|
|
183
|
+
"""Get the flow from the passed data dict.
|
|
184
|
+
|
|
185
|
+
Parameters
|
|
186
|
+
----------
|
|
187
|
+
data : Dict[str, Any]
|
|
188
|
+
The data dict.
|
|
189
|
+
flow_id : Optional[str], optional
|
|
190
|
+
The flow ID, by default None.
|
|
191
|
+
name : Optional[str], optional
|
|
192
|
+
The flow name, by default None.
|
|
193
|
+
description : Optional[str], optional
|
|
194
|
+
The flow description, by default None.
|
|
195
|
+
tags : Optional[List[str]], optional
|
|
196
|
+
The flow tags, by default None.
|
|
197
|
+
requirements : Optional[List[str]], optional
|
|
198
|
+
The flow requirements, by default None.
|
|
199
|
+
|
|
200
|
+
Returns
|
|
201
|
+
-------
|
|
202
|
+
Dict[str, Any]
|
|
203
|
+
The flow data.
|
|
204
|
+
|
|
205
|
+
Raises
|
|
206
|
+
------
|
|
207
|
+
ValueError
|
|
208
|
+
If the flow type is not "flow".
|
|
209
|
+
"""
|
|
210
|
+
item_type = data.get("type", "flow")
|
|
211
|
+
if item_type != "flow":
|
|
212
|
+
# empty flow (from exported model/skill ?)
|
|
213
|
+
raise ValueError(f"Invalid flow type: {item_type}")
|
|
214
|
+
from_args = {
|
|
215
|
+
"id": flow_id,
|
|
216
|
+
"name": name,
|
|
217
|
+
"description": description,
|
|
218
|
+
"tags": tags,
|
|
219
|
+
"requirements": requirements,
|
|
220
|
+
}
|
|
221
|
+
for key, value in from_args.items():
|
|
222
|
+
if value:
|
|
223
|
+
data[key] = value
|
|
224
|
+
if "name" not in data:
|
|
225
|
+
data["name"] = "Waldiez Flow"
|
|
226
|
+
if "description" not in data:
|
|
227
|
+
data["description"] = "Waldiez Flow description"
|
|
228
|
+
if "tags" not in data:
|
|
229
|
+
data["tags"] = []
|
|
230
|
+
if "requirements" not in data:
|
|
231
|
+
data["requirements"] = []
|
|
232
|
+
return data
|
waldiez/models/model/__init__.py
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
3
|
"""Waldiez model."""
|
|
4
4
|
|
|
5
|
+
from .extra_requirements import get_models_extra_requirements
|
|
5
6
|
from .model import DEFAULT_BASE_URLS, WaldiezModel
|
|
6
7
|
from .model_data import WaldiezModelAPIType, WaldiezModelData, WaldiezModelPrice
|
|
7
8
|
|
|
8
9
|
__all__ = [
|
|
10
|
+
"get_models_extra_requirements",
|
|
9
11
|
"DEFAULT_BASE_URLS",
|
|
10
12
|
"WaldiezModel",
|
|
11
13
|
"WaldiezModelData",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0.
|
|
2
|
+
# Copyright (c) 2024 - 2025 Waldiez and contributors.
|
|
3
|
+
"""Waldiez model extra requirements."""
|
|
4
|
+
|
|
5
|
+
from typing import Iterator, Set
|
|
6
|
+
|
|
7
|
+
from .model import WaldiezModel
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def get_models_extra_requirements(
|
|
11
|
+
models: Iterator[WaldiezModel], autogen_version: str
|
|
12
|
+
) -> Set[str]:
|
|
13
|
+
"""Get the models extra requirements.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
models : List[WaldiezModel]
|
|
18
|
+
The models.
|
|
19
|
+
autogen_version : str
|
|
20
|
+
The autogen version.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
List[str]
|
|
25
|
+
The models extra requirements.
|
|
26
|
+
"""
|
|
27
|
+
model_requirements: Set[str] = set()
|
|
28
|
+
# ref: https://github.com/ag2ai/ag2/blob/main/pyproject.toml
|
|
29
|
+
models_with_additional_requirements = [
|
|
30
|
+
"together",
|
|
31
|
+
"gemini",
|
|
32
|
+
"mistral",
|
|
33
|
+
"groq",
|
|
34
|
+
"anthropic",
|
|
35
|
+
"cohere",
|
|
36
|
+
"bedrock", # we might add this later
|
|
37
|
+
]
|
|
38
|
+
for model in models:
|
|
39
|
+
if model.data.api_type == "google":
|
|
40
|
+
model_requirements.add(f"pyautogen[gemini]=={autogen_version}")
|
|
41
|
+
continue
|
|
42
|
+
if model.data.api_type in models_with_additional_requirements:
|
|
43
|
+
model_requirements.add(
|
|
44
|
+
f"pyautogen[{model.data.api_type}]=={autogen_version}"
|
|
45
|
+
)
|
|
46
|
+
return model_requirements
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# for bedrock, there are some additional params needed
|
|
50
|
+
# (both here and on the ui part):
|
|
51
|
+
# aws_region (mandatory)
|
|
52
|
+
# aws_access_key (or environment variable: AWS_ACCESS_KEY)
|
|
53
|
+
# aws_secret_key (or environment variable: AWS_SECRET_KEY)
|
|
54
|
+
# aws_session_token (or environment variable: AWS_SESSION_TOKEN)
|
|
55
|
+
# aws_profile_name
|
waldiez/models/model/model.py
CHANGED
|
@@ -19,6 +19,7 @@ DEFAULT_BASE_URLS: Dict[WaldiezModelAPIType, str] = {
|
|
|
19
19
|
"groq": "https://api.groq.com/openai/v1",
|
|
20
20
|
"together": "https://api.together.xyz/v1",
|
|
21
21
|
"nim": "https://integrate.api.nvidia.com/v1",
|
|
22
|
+
"cohere": "https://api.cohere.com",
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
|
|
@@ -63,7 +64,7 @@ class WaldiezModel(WaldiezBase):
|
|
|
63
64
|
description: Annotated[
|
|
64
65
|
str,
|
|
65
66
|
Field(
|
|
66
|
-
|
|
67
|
+
"Model's Description",
|
|
67
68
|
title="Description",
|
|
68
69
|
description="The description of the model.",
|
|
69
70
|
),
|
|
@@ -118,6 +119,7 @@ class WaldiezModel(WaldiezBase):
|
|
|
118
119
|
- groq: 'GROQ_API_KEY',
|
|
119
120
|
- together: 'TOGETHER_API_KEY',
|
|
120
121
|
- nim: 'NIM_API_KEY',
|
|
122
|
+
- cohere: 'COHERE_API_KEY',
|
|
121
123
|
- other: 'OPENAI_API_KEY'
|
|
122
124
|
"""
|
|
123
125
|
env_key = "OPENAI_API_KEY"
|
|
@@ -142,6 +144,7 @@ class WaldiezModel(WaldiezBase):
|
|
|
142
144
|
- groq: 'GROQ_API_KEY',
|
|
143
145
|
- together: 'TOGETHER_API_KEY',
|
|
144
146
|
- nim: 'NIM_API_KEY',
|
|
147
|
+
- cohere: 'COHERE_API_KEY',
|
|
145
148
|
- other: 'OPENAI_API_KEY'
|
|
146
149
|
"""
|
|
147
150
|
if self.data.api_key and self.data.api_key != "REPLACE_ME":
|
|
@@ -222,7 +225,7 @@ def set_default_base_url(
|
|
|
222
225
|
Dict[str, Any]
|
|
223
226
|
The llm config dictionary with the default base url set.
|
|
224
227
|
"""
|
|
225
|
-
if api_type in ("openai", "other", "azure"):
|
|
228
|
+
if api_type in ("openai", "other", "azure", "cohere"):
|
|
226
229
|
return llm_config
|
|
227
230
|
if "base_url" not in llm_config or not llm_config["base_url"]:
|
|
228
231
|
dict_copy = llm_config.copy()
|
|
@@ -20,6 +20,7 @@ WaldiezModelAPIType = Literal[
|
|
|
20
20
|
"groq",
|
|
21
21
|
"together",
|
|
22
22
|
"nim",
|
|
23
|
+
"cohere",
|
|
23
24
|
"other",
|
|
24
25
|
]
|
|
25
26
|
|
|
@@ -53,7 +54,7 @@ class WaldiezModelData(WaldiezBase):
|
|
|
53
54
|
The base url of the model, by default None.
|
|
54
55
|
api_key : Optional[str]
|
|
55
56
|
The api key to use with the model, by default None.
|
|
56
|
-
api_type :
|
|
57
|
+
api_type : WaldiezModelAPIType
|
|
57
58
|
The api type of the model.
|
|
58
59
|
api_version : Optional[str]
|
|
59
60
|
The api version of the model, by default None.
|
waldiez/models/waldiez.py
CHANGED
|
@@ -8,16 +8,18 @@ definitions and their optional additional skills to be used.
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import json
|
|
11
|
-
import warnings
|
|
12
11
|
from dataclasses import dataclass
|
|
13
|
-
from functools import cache
|
|
14
12
|
from pathlib import Path
|
|
15
13
|
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
|
|
16
14
|
|
|
17
|
-
from .agents import
|
|
15
|
+
from .agents import (
|
|
16
|
+
WaldiezAgent,
|
|
17
|
+
get_retrievechat_extra_requirements,
|
|
18
|
+
)
|
|
18
19
|
from .chat import WaldiezChat
|
|
19
|
-
from .
|
|
20
|
-
from .
|
|
20
|
+
from .common import get_autogen_version
|
|
21
|
+
from .flow import WaldiezFlow, get_flow_data
|
|
22
|
+
from .model import WaldiezModel, get_models_extra_requirements
|
|
21
23
|
from .skill import WaldiezSkill
|
|
22
24
|
|
|
23
25
|
|
|
@@ -62,7 +64,7 @@ class Waldiez:
|
|
|
62
64
|
Waldiez
|
|
63
65
|
The Waldiez.
|
|
64
66
|
"""
|
|
65
|
-
flow =
|
|
67
|
+
flow = get_flow_data(
|
|
66
68
|
data,
|
|
67
69
|
flow_id=flow_id,
|
|
68
70
|
name=name,
|
|
@@ -224,8 +226,9 @@ class Waldiez:
|
|
|
224
226
|
@property
|
|
225
227
|
def requirements(self) -> List[str]:
|
|
226
228
|
"""Get the flow requirements."""
|
|
227
|
-
autogen_version =
|
|
229
|
+
autogen_version = get_autogen_version()
|
|
228
230
|
requirements_list = filter(
|
|
231
|
+
# we use the fixed "pyautogen=={autogen_version}" below
|
|
229
232
|
lambda requirement: not (
|
|
230
233
|
requirement.startswith("pyautogen")
|
|
231
234
|
or requirement.startswith("ag2")
|
|
@@ -234,30 +237,15 @@ class Waldiez:
|
|
|
234
237
|
self.flow.requirements,
|
|
235
238
|
)
|
|
236
239
|
requirements = set(requirements_list)
|
|
240
|
+
requirements.add(f"pyautogen=={autogen_version}")
|
|
237
241
|
if self.has_rag_agents:
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
requirements.add(f"pyautogen=={autogen_version}")
|
|
242
|
+
rag_extras = get_retrievechat_extra_requirements(self.agents)
|
|
243
|
+
requirements.update(rag_extras)
|
|
241
244
|
if self.has_multimodal_agents:
|
|
242
245
|
requirements.add(f"pyautogen[lmm]=={autogen_version}")
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
"gemini",
|
|
247
|
-
"mistral",
|
|
248
|
-
"groq",
|
|
249
|
-
"anthropic",
|
|
250
|
-
"cohere",
|
|
251
|
-
"bedrock",
|
|
252
|
-
]
|
|
253
|
-
for model in self.models:
|
|
254
|
-
if model.data.api_type == "google":
|
|
255
|
-
requirements.add(f"pyautogen[gemini]=={autogen_version}")
|
|
256
|
-
continue
|
|
257
|
-
if model.data.api_type in models_with_additional_requirements:
|
|
258
|
-
requirements.add(
|
|
259
|
-
f"pyautogen[{model.data.api_type}]=={autogen_version}"
|
|
260
|
-
)
|
|
246
|
+
requirements.update(
|
|
247
|
+
get_models_extra_requirements(self.models, autogen_version)
|
|
248
|
+
)
|
|
261
249
|
return sorted(list(requirements))
|
|
262
250
|
|
|
263
251
|
def get_flow_env_vars(self) -> List[Tuple[str, str]]:
|
|
@@ -307,50 +295,3 @@ class Waldiez:
|
|
|
307
295
|
The swarm agents and the user agent.
|
|
308
296
|
"""
|
|
309
297
|
return self.flow.get_swarm_chat_members(initial_agent)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
def _get_flow(
|
|
313
|
-
data: Dict[str, Any],
|
|
314
|
-
flow_id: Optional[str] = None,
|
|
315
|
-
name: Optional[str] = None,
|
|
316
|
-
description: Optional[str] = None,
|
|
317
|
-
tags: Optional[List[str]] = None,
|
|
318
|
-
requirements: Optional[List[str]] = None,
|
|
319
|
-
) -> Dict[str, Any]:
|
|
320
|
-
"""Get the flow."""
|
|
321
|
-
item_type = data.get("type", "flow")
|
|
322
|
-
if item_type != "flow":
|
|
323
|
-
# empty flow (from exported model/skill ?)
|
|
324
|
-
raise ValueError(f"Invalid flow type: {item_type}")
|
|
325
|
-
from_args = {
|
|
326
|
-
"id": flow_id,
|
|
327
|
-
"name": name,
|
|
328
|
-
"description": description,
|
|
329
|
-
"tags": tags,
|
|
330
|
-
"requirements": requirements,
|
|
331
|
-
}
|
|
332
|
-
for key, value in from_args.items():
|
|
333
|
-
if value:
|
|
334
|
-
data[key] = value
|
|
335
|
-
if "name" not in data:
|
|
336
|
-
data["name"] = "Waldiez Flow"
|
|
337
|
-
if "description" not in data:
|
|
338
|
-
data["description"] = "Waldiez Flow description"
|
|
339
|
-
if "tags" not in data:
|
|
340
|
-
data["tags"] = []
|
|
341
|
-
if "requirements" not in data:
|
|
342
|
-
data["requirements"] = []
|
|
343
|
-
return data
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
@cache
|
|
347
|
-
def _get_autogen_version() -> str:
|
|
348
|
-
"""Get the autogen version."""
|
|
349
|
-
# pylint: disable=import-outside-toplevel
|
|
350
|
-
with warnings.catch_warnings():
|
|
351
|
-
warnings.simplefilter("ignore")
|
|
352
|
-
try:
|
|
353
|
-
from autogen.version import __version__ as ag2 # type: ignore
|
|
354
|
-
except ImportError as error: # pragma: no cover
|
|
355
|
-
raise ValueError("pyautogen is not installed.") from error
|
|
356
|
-
return ag2
|