CoACT initialize (#292)
This commit is contained in:
12
mm_agents/coact/autogen/io/processors/__init__.py
Normal file
12
mm_agents/coact/autogen/io/processors/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from .base import AsyncEventProcessorProtocol, EventProcessorProtocol
|
||||
from .console_event_processor import AsyncConsoleEventProcessor, ConsoleEventProcessor
|
||||
|
||||
__all__ = [
|
||||
"AsyncConsoleEventProcessor",
|
||||
"AsyncEventProcessorProtocol",
|
||||
"ConsoleEventProcessor",
|
||||
"EventProcessorProtocol",
|
||||
]
|
||||
21
mm_agents/coact/autogen/io/processors/base.py
Normal file
21
mm_agents/coact/autogen/io/processors/base.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from typing import TYPE_CHECKING, Protocol
|
||||
|
||||
from ...doc_utils import export_module
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..run_response import AsyncRunResponseProtocol, RunResponseProtocol
|
||||
|
||||
__all__ = ["AsyncEventProcessorProtocol", "EventProcessorProtocol"]
|
||||
|
||||
|
||||
@export_module("autogen.io")
|
||||
class EventProcessorProtocol(Protocol):
|
||||
def process(self, response: "RunResponseProtocol") -> None: ...
|
||||
|
||||
|
||||
@export_module("autogen.io")
|
||||
class AsyncEventProcessorProtocol(Protocol):
|
||||
async def process(self, response: "AsyncRunResponseProtocol") -> None: ...
|
||||
@@ -0,0 +1,56 @@
|
||||
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import getpass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ...doc_utils import export_module
|
||||
from ...events.agent_events import InputRequestEvent
|
||||
from ...events.base_event import BaseEvent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..run_response import AsyncRunResponseProtocol, RunResponseProtocol
|
||||
from .base import AsyncEventProcessorProtocol, EventProcessorProtocol
|
||||
|
||||
|
||||
@export_module("autogen.io")
|
||||
class ConsoleEventProcessor:
|
||||
def process(self, response: "RunResponseProtocol") -> None:
|
||||
for event in response.events:
|
||||
self.process_event(event)
|
||||
|
||||
def process_event(self, event: BaseEvent) -> None:
|
||||
if isinstance(event, InputRequestEvent):
|
||||
prompt = event.content.prompt # type: ignore[attr-defined]
|
||||
if event.content.password: # type: ignore[attr-defined]
|
||||
result = getpass.getpass(prompt if prompt != "" else "Password: ")
|
||||
result = input(prompt)
|
||||
event.content.respond(result) # type: ignore[attr-defined]
|
||||
else:
|
||||
event.print()
|
||||
|
||||
|
||||
@export_module("autogen.io")
|
||||
class AsyncConsoleEventProcessor:
|
||||
async def process(self, response: "AsyncRunResponseProtocol") -> None:
|
||||
async for event in response.events:
|
||||
await self.process_event(event)
|
||||
|
||||
async def process_event(self, event: BaseEvent) -> None:
|
||||
if isinstance(event, InputRequestEvent):
|
||||
prompt = event.content.prompt # type: ignore[attr-defined]
|
||||
if event.content.password: # type: ignore[attr-defined]
|
||||
result = getpass.getpass(prompt if prompt != "" else "Password: ")
|
||||
result = input(prompt)
|
||||
await event.content.respond(result) # type: ignore[attr-defined]
|
||||
else:
|
||||
event.print()
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
||||
def check_type_1(x: ConsoleEventProcessor) -> EventProcessorProtocol:
|
||||
return x
|
||||
|
||||
def check_type_2(x: AsyncConsoleEventProcessor) -> AsyncEventProcessorProtocol:
|
||||
return x
|
||||
Reference in New Issue
Block a user