Chats
Chats exporter.
ChatsExporter ¶
ChatsExporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[WaldiezGroupManager],
context: Optional[ExporterContext] = None,
**kwargs: Any
)
Bases: Exporter[ChatExtras]
Chats exporter with structured extras.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | Optional[WaldiezGroupManager] | The root group manager for managing chat groups, if any. | required |
context | Optional[ExporterContext] | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Source code in waldiez/exporting/chats/exporter.py
create_chats_exporter ¶
create_chats_exporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[
WaldiezGroupManager
] = None,
context: Optional[ExporterContext] = None,
**kwargs: Any
) -> ChatsExporter
Create a chats exporter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | Optional[WaldiezGroupManager] | The root group manager for managing chat groups, if any. | None |
context | Optional[ExporterContext] | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Returns:
Type | Description |
---|---|
ChatsExporter | The created chats exporter. |
Source code in waldiez/exporting/chats/factory.py
exporter ¶
Chats exporter.
ChatsExporter ¶
ChatsExporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[WaldiezGroupManager],
context: Optional[ExporterContext] = None,
**kwargs: Any
)
Bases: Exporter[ChatExtras]
Chats exporter with structured extras.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | Optional[WaldiezGroupManager] | The root group manager for managing chat groups, if any. | required |
context | Optional[ExporterContext] | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Source code in waldiez/exporting/chats/exporter.py
factory ¶
Factory function for creating a ChatsExporter instance.
create_chats_exporter ¶
create_chats_exporter(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[
WaldiezGroupManager
] = None,
context: Optional[ExporterContext] = None,
**kwargs: Any
) -> ChatsExporter
Create a chats exporter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
all_agents | list[WaldiezAgent] | All agents involved in the chats. | required |
agent_names | dict[str, str] | Mapping of agent IDs to their names. | required |
all_chats | list[WaldiezChat] | All chats to be exported. | required |
chat_names | dict[str, str] | Mapping of chat IDs to their names. | required |
main_chats | list[WaldiezAgentConnection] | Main chats that are connections between agents. | required |
root_group_manager | Optional[WaldiezGroupManager] | The root group manager for managing chat groups, if any. | None |
context | Optional[ExporterContext] | Exporter context with dependencies, by default None | None |
**kwargs | Any | Additional keyword arguments for the exporter. | {} |
Returns:
Type | Description |
---|---|
ChatsExporter | The created chats exporter. |
Source code in waldiez/exporting/chats/factory.py
processor ¶
Chats processor.
ChatParams dataclass
¶
Parameters for the chat export processor.
ChatsProcessor ¶
ChatsProcessor(
all_agents: list[WaldiezAgent],
agent_names: dict[str, str],
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
main_chats: list[WaldiezAgentConnection],
root_group_manager: Optional[WaldiezGroupManager],
for_notebook: bool,
is_async: bool,
cache_seed: Optional[int],
serializer: Serializer,
extras: ChatExtras,
)
Processor for chats export.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
extras | ChatExtras | The structured extras for the chats export. | required |
Source code in waldiez/exporting/chats/processor.py
is_group_patterned ¶
is_group_patterned() -> bool
Check if the chats are group patterned.
Returns:
Type | Description |
---|---|
bool | True if the chats are group patterned, False otherwise. |
Source code in waldiez/exporting/chats/processor.py
process ¶
Process the chats export.
utils ¶
Chat utils for exporting chatsper chat type.
common ¶
Common utilities for exporting chats.
get_chat_message_string ¶
get_chat_message_string(
sender: WaldiezAgent,
chat: WaldiezChat,
chat_names: dict[str, str],
) -> tuple[str, Optional[str]]
Get the agent's message as a string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sender | WaldiezAgent | The sender. | required |
chat | WaldiezChat | The chat. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name with all the chats in the flow. | required |
Returns:
Type | Description |
---|---|
tuple[str, Optional[str]] | If the message is a string, the message content and None. If the message is a method, the method name and the method content. If the message is None, 'None' and None. |
Source code in waldiez/exporting/chats/utils/common.py
export_group_chats ¶
export_group_chats(
agent_names: dict[str, str],
manager: WaldiezGroupManager,
intial_chat: str | None,
tabs: int,
is_async: bool,
) -> str
Get the group chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_names | dict[str, str] | The agent names. | required |
manager | WaldiezGroupManager | The group manager agent. | required |
intial_chat | str | None | The initial chat to use if any. | required |
tabs | int | The number of tabs for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The group chat string and the import string. |
Source code in waldiez/exporting/chats/utils/group.py
export_nested_chat_registration ¶
export_nested_chat_registration(
agent: WaldiezAgent,
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
is_async: bool,
) -> str
Get the nested chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
chat_names | dict[str, str] | The chat names. | required |
agent_names | dict[str, str] | The agent names. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
str | The nested chat string. |
Source code in waldiez/exporting/chats/utils/nested.py
export_sequential_chat ¶
export_sequential_chat(
main_chats: list[WaldiezAgentConnection],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
tabs: int,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chats content, when there are more than one chats in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_chats | list[WaldiezAgentConnection] | The main chats. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
serializer | Callable[..., str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The main chats content and additional methods string if any. |
Example
>>> from waldiez.models import (
... WaldiezAgent,
... WaldiezChat,
... WaldiezChatData,
... WaldiezChatMessage,
... )
>>> chat1 = WaldiezChat(
... id="wc-1",
... name="chat1",
... description="A chat between two agents.",
... tags=["chat", "chat1"],
... requirements=[],
... data=WaldiezChatData(
... sender="wa-1",
... recipient="wa-2",
... position=0,
... message=WaldiezChatMessage(
... type="string",
... content="Hello, how are you?",
... ),
... ),
... )
>>> chat2 = WaldiezChat(
... id="wc-2",
... name="chat2",
... description="A chat between two agents.",
... tags=["chat", "chat2"],
... requirements=[],
... data=WaldiezChatData(
... sender="wa-2",
... recipient="wa-1",
... position=1,
... message=WaldiezChatMessage(
... type="string",
... content="I am good, thank you. How about you?",
... ),
... ),
... )
>>> agent_names = {"wa-1": "agent1", "wa-2": "agent2"}
>>> chat_names = {"wc-1": "chat1", "wc-2": "chat2"}
>>> serializer = lambda x: x.replace('"', "\"").replace("\n", "\\n")
>>> export_sequential_chat(
... main_chats=[(chat1, agent1, agent2), (chat2, agent2, agent1)],
... chat_names=chat_names,
... agent_names=agent_names,
... serializer=serializer,
... tabs=0,
... is_async=False,
... )
results = initiate_chats([
{
"sender": agent1,
"recipient": agent2,
"message": "Hello, how are you?",
},
{
"sender": agent2,
"recipient": agent1,
"message": "I am good, thank you. How about you?",
},
])
Source code in waldiez/exporting/chats/utils/sequential.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
export_single_chat ¶
export_single_chat(
sender: WaldiezAgent,
recipient: WaldiezAgent,
chat: WaldiezChat,
agent_names: dict[str, str],
chat_names: dict[str, str],
serializer: Callable[[str], str],
tabs: int,
is_async: bool,
skip_cache: bool,
tab_leng: int = 4,
) -> tuple[str, str]
Get the chat string when there is only one chat in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
chat | WaldiezChat | The chat. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
serializer | Callable[[str], str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
tab_leng | int | The length of the tab string, by default 4. | 4 |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any |
Example
>>> from waldiez.models import WaldiezAgent, WaldiezChat, WaldiezChatData, WaldiezChatMessage
>>> chat = WaldiezChat(
... id="wc-1",
... name="chat1",
... description="A chat between two agents.",
... tags=["chat", "chat1"],
... requirements=[],
... data=WaldiezChatData(
... sender="wa-1",
... recipient="wa-2",
... message=WaldiezChatMessage(
... type="string",
... content="Hello, how are you?",
... ),
... ),
... )
>>> agent_names = {"wa-1": "agent1", "wa-2": "agent2"}
>>> chat_names = {"wc-1": "chat1"}
>>> export_single_chat_string(
... sender=agent1,
... recipient=agent2,
... chat=chat,
... agent_names=agent_names,
... chat_names=chat_names,
... tabs=0,
... )
agent1.initiate_chat(
agent2,
message="Hello, how are you?",
cache=cache,
)
Source code in waldiez/exporting/chats/utils/single.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
get_nested_chat_queue ¶
get_nested_chat_queue(
nested_chat: WaldiezAgentNestedChat,
agent: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
all_chats: list[WaldiezChat],
serializer: Callable[..., str],
) -> tuple[str, list[str]]
Get the nested chat queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_chat | WaldiezAgentNestedChat | The nested chat. | required |
agent | WaldiezAgent | The agent. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
Returns:
Type | Description |
---|---|
tuple[str, list[str]] | The nested chat queue and the methods to include (methods: message string and method name if the message is a method). |
Source code in waldiez/exporting/chats/utils/nested.py
group ¶
Exporting group chat utils.
Using the group patterns (no group manager agent)
export_group_chats ¶
export_group_chats(
agent_names: dict[str, str],
manager: WaldiezGroupManager,
intial_chat: str | None,
tabs: int,
is_async: bool,
) -> str
Get the group chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent_names | dict[str, str] | The agent names. | required |
manager | WaldiezGroupManager | The group manager agent. | required |
intial_chat | str | None | The initial chat to use if any. | required |
tabs | int | The number of tabs for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The group chat string and the import string. |
Source code in waldiez/exporting/chats/utils/group.py
nested ¶
Nested chats exporting.
export_nested_chat_registration ¶
export_nested_chat_registration(
agent: WaldiezAgent,
all_chats: list[WaldiezChat],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
is_async: bool,
) -> str
Get the nested chat string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent | WaldiezAgent | The agent. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
chat_names | dict[str, str] | The chat names. | required |
agent_names | dict[str, str] | The agent names. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
is_async | bool | Whether the chat is asynchronous. | required |
Returns:
Type | Description |
---|---|
str | The nested chat string. |
Source code in waldiez/exporting/chats/utils/nested.py
get_chat_nested_string ¶
get_chat_nested_string(
chat: WaldiezChat,
is_reply: bool,
chat_names: dict[str, str],
) -> tuple[str, Optional[str]]
Get the nested chat message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat | WaldiezChat | The chat. | required |
is_reply | bool | Whether to use the nested chat's reply message or not. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name.. | required |
Returns:
Type | Description |
---|---|
tuple[str, Optional[str]] | If the message is a string, the message content and None. If the message is a method, the method name and the method content. If the message is None, 'None' and None. |
Source code in waldiez/exporting/chats/utils/nested.py
get_nested_chat_message_string ¶
get_nested_chat_message_string(
waldiez_chat: WaldiezChat,
message: WaldiezAgentNestedChatMessage,
agent: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
serializer: Callable[..., str],
) -> tuple[str, Optional[str]]
Get the nested chat message string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
waldiez_chat | WaldiezChat | The chat. | required |
message | WaldiezAgentNestedChatMessage | The message. | required |
agent | WaldiezAgent | The agent. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
serializer | Callable[..., str] | The function to serialize the chat arguments. | required |
Returns:
Type | Description |
---|---|
tuple[str, Optional[str]] | The message string and the method name if the message is a method. |
Source code in waldiez/exporting/chats/utils/nested.py
get_nested_chat_queue ¶
get_nested_chat_queue(
nested_chat: WaldiezAgentNestedChat,
agent: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
all_chats: list[WaldiezChat],
serializer: Callable[..., str],
) -> tuple[str, list[str]]
Get the nested chat queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_chat | WaldiezAgentNestedChat | The nested chat. | required |
agent | WaldiezAgent | The agent. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
all_chats | list[WaldiezChat] | All the chats in the flow. | required |
serializer | Callable[..., str] | The serializer to use to escape quotes in a string. | required |
Returns:
Type | Description |
---|---|
tuple[str, list[str]] | The nested chat queue and the methods to include (methods: message string and method name if the message is a method). |
Source code in waldiez/exporting/chats/utils/nested.py
get_nested_chat_trigger_agent_names ¶
get_nested_chat_trigger_agent_names(
nested_chat: WaldiezAgentNestedChat,
agent_names: dict[str, str],
) -> str
Get the trigger agent names for the nested chat.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_chat | WaldiezAgentNestedChat | The nested chat. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
Returns:
Type | Description |
---|---|
str | The trigger agent names. |
Source code in waldiez/exporting/chats/utils/nested.py
sequential ¶
Utility functions for exporting sequential chats.
export_sequential_chat ¶
export_sequential_chat(
main_chats: list[WaldiezAgentConnection],
chat_names: dict[str, str],
agent_names: dict[str, str],
serializer: Callable[..., str],
tabs: int,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chats content, when there are more than one chats in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_chats | list[WaldiezAgentConnection] | The main chats. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
serializer | Callable[..., str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The main chats content and additional methods string if any. |
Example
>>> from waldiez.models import (
... WaldiezAgent,
... WaldiezChat,
... WaldiezChatData,
... WaldiezChatMessage,
... )
>>> chat1 = WaldiezChat(
... id="wc-1",
... name="chat1",
... description="A chat between two agents.",
... tags=["chat", "chat1"],
... requirements=[],
... data=WaldiezChatData(
... sender="wa-1",
... recipient="wa-2",
... position=0,
... message=WaldiezChatMessage(
... type="string",
... content="Hello, how are you?",
... ),
... ),
... )
>>> chat2 = WaldiezChat(
... id="wc-2",
... name="chat2",
... description="A chat between two agents.",
... tags=["chat", "chat2"],
... requirements=[],
... data=WaldiezChatData(
... sender="wa-2",
... recipient="wa-1",
... position=1,
... message=WaldiezChatMessage(
... type="string",
... content="I am good, thank you. How about you?",
... ),
... ),
... )
>>> agent_names = {"wa-1": "agent1", "wa-2": "agent2"}
>>> chat_names = {"wc-1": "chat1", "wc-2": "chat2"}
>>> serializer = lambda x: x.replace('"', "\"").replace("\n", "\\n")
>>> export_sequential_chat(
... main_chats=[(chat1, agent1, agent2), (chat2, agent2, agent1)],
... chat_names=chat_names,
... agent_names=agent_names,
... serializer=serializer,
... tabs=0,
... is_async=False,
... )
results = initiate_chats([
{
"sender": agent1,
"recipient": agent2,
"message": "Hello, how are you?",
},
{
"sender": agent2,
"recipient": agent1,
"message": "I am good, thank you. How about you?",
},
])
Source code in waldiez/exporting/chats/utils/sequential.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
single ¶
Utilities for exporting a single chat in a flow.
export_single_chat ¶
export_single_chat(
sender: WaldiezAgent,
recipient: WaldiezAgent,
chat: WaldiezChat,
agent_names: dict[str, str],
chat_names: dict[str, str],
serializer: Callable[[str], str],
tabs: int,
is_async: bool,
skip_cache: bool,
tab_leng: int = 4,
) -> tuple[str, str]
Get the chat string when there is only one chat in the flow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
chat | WaldiezChat | The chat. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
serializer | Callable[[str], str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
tab_leng | int | The length of the tab string, by default 4. | 4 |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any |
Example
>>> from waldiez.models import WaldiezAgent, WaldiezChat, WaldiezChatData, WaldiezChatMessage
>>> chat = WaldiezChat(
... id="wc-1",
... name="chat1",
... description="A chat between two agents.",
... tags=["chat", "chat1"],
... requirements=[],
... data=WaldiezChatData(
... sender="wa-1",
... recipient="wa-2",
... message=WaldiezChatMessage(
... type="string",
... content="Hello, how are you?",
... ),
... ),
... )
>>> agent_names = {"wa-1": "agent1", "wa-2": "agent2"}
>>> chat_names = {"wc-1": "chat1"}
>>> export_single_chat_string(
... sender=agent1,
... recipient=agent2,
... chat=chat,
... agent_names=agent_names,
... chat_names=chat_names,
... tabs=0,
... )
agent1.initiate_chat(
agent2,
message="Hello, how are you?",
cache=cache,
)
Source code in waldiez/exporting/chats/utils/single.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
get_chat_message ¶
get_chat_message(
tab: str,
chat: WaldiezChat,
chat_names: dict[str, str],
sender: WaldiezAgent,
sender_name: str,
) -> tuple[str, str]
Get the chat message string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tab | str | The tab string. | required |
chat | WaldiezChat | The chat. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
sender | WaldiezAgent | The sender. | required |
sender_name | str | The sender name. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The message argument and additional methods string if any. |
Source code in waldiez/exporting/chats/utils/single.py
get_empty_simple_chat_string ¶
get_empty_simple_chat_string(
chat: WaldiezChat,
sender: WaldiezAgent,
recipient: WaldiezAgent,
agent_names: dict[str, str],
tab: str,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chat string when there are no chat arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat | WaldiezChat | The chat. | required |
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
tab | str | The tab string. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any |
Source code in waldiez/exporting/chats/utils/single.py
get_simple_chat_string ¶
get_simple_chat_string(
chat: WaldiezChat,
sender: WaldiezAgent,
recipient: WaldiezAgent,
agent_names: dict[str, str],
chat_names: dict[str, str],
chat_args: dict[str, Any],
serializer: Callable[..., str],
tabs: int,
is_async: bool,
skip_cache: bool,
) -> tuple[str, str]
Get the chat string when there are chat arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chat | WaldiezChat | The chat. | required |
sender | WaldiezAgent | The sender. | required |
recipient | WaldiezAgent | The recipient. | required |
agent_names | dict[str, str] | A mapping of agent id to agent name. | required |
chat_names | dict[str, str] | A mapping of chat id to chat name. | required |
chat_args | dict[str, Any] | The chat arguments. | required |
serializer | Callable[[str], str] | The serializer function to escape quotes in a string. | required |
tabs | int | The number of tabs to use for indentation. | required |
is_async | bool | Whether the chat is asynchronous. | required |
skip_cache | bool | Whether to skip the cache argument. | required |
Returns:
Type | Description |
---|---|
tuple[str, str] | The chat string and additional methods string if any. |