IOStream - AG2

IOStream

autogen.io.IOStream

Bases: InputStream, OutputStream, Protocol

A protocol for input/output streams.

print

print(*objects, sep=' ', end='\n', flush=False)

Print data to the output stream.

    Args:
        objects (any): The data to print.
        sep (str, optional): The separator between objects. Defaults to " ".
        end (str, optional): The end of the output. Defaults to "\n".
        flush (bool, optional): Whether to flush the output. Defaults to False.

Source code in autogen/io/base.py

<br>24<br>25<br>26<br>27<br>28<br>29<br>30<br>31<br>32<br>33<br> <br>def print(self, *objects: Any, sep: str = " ", end: str = "\n", flush: bool = False) -> None:<br> """Print data to the output stream.<br> Args:<br> objects (any): The data to print.<br> sep (str, optional): The separator between objects. Defaults to " ".<br> end (str, optional): The end of the output. Defaults to "\n".<br> flush (bool, optional): Whether to flush the output. Defaults to False.<br> """<br> ... # pragma: no cover<br>

send

send(message)

Send data to the output stream.

PARAMETER DESCRIPTION
message BaseMessage from autogen.messages.base_message
TYPE:BaseMessage

Source code in autogen/io/base.py

<br>35<br>36<br>37<br>38<br>39<br>40<br>41<br> <br>def send(self, message: BaseMessage) -> None:<br> """Send data to the output stream.<br> Args:<br> message (BaseMessage): BaseMessage from autogen.messages.base_message<br> """<br> ...<br>

input

input(prompt='', *, password=False)

Read a line from the input stream.

PARAMETER DESCRIPTION
prompt The prompt to display. Defaults to "".
TYPE:strDEFAULT:''
password Whether to read a password. Defaults to False.
TYPE:boolDEFAULT:False
RETURNS DESCRIPTION
str The line read from the input stream.
TYPE:str

Source code in autogen/io/base.py

<br>47<br>48<br>49<br>50<br>51<br>52<br>53<br>54<br>55<br>56<br>57<br>58<br> <br>def input(self, prompt: str = "", *, password: bool = False) -> str:<br> """Read a line from the input stream.<br> Args:<br> prompt (str, optional): The prompt to display. Defaults to "".<br> password (bool, optional): Whether to read a password. Defaults to False.<br> Returns:<br> str: The line read from the input stream.<br> """<br> ... # pragma: no cover<br>

set_global_default staticmethod

set_global_default(stream)

Set the default input/output stream.

PARAMETER DESCRIPTION
stream The input/output stream to set as the default.
TYPE:IOStream

Source code in autogen/io/base.py

<br>71<br>72<br>73<br>74<br>75<br>76<br>77<br>78<br> <br>@staticmethod<br>def set_global_default(stream: "IOStream") -> None:<br> """Set the default input/output stream.<br> Args:<br> stream (IOStream): The input/output stream to set as the default.<br> """<br> IOStream._global_default = stream<br>

get_global_default staticmethod

get_global_default()

Get the default input/output stream.

RETURNS DESCRIPTION
IOStream The default input/output stream.
TYPE:IOStream

Source code in autogen/io/base.py

<br>80<br>81<br>82<br>83<br>84<br>85<br>86<br>87<br>88<br>89<br> <br>@staticmethod<br>def get_global_default() -> "IOStream":<br> """Get the default input/output stream.<br> Returns:<br> IOStream: The default input/output stream.<br> """<br> if IOStream._global_default is None:<br> raise RuntimeError("No global default IOStream has been set")<br> return IOStream._global_default<br>

get_default staticmethod

get_default()

Get the default input/output stream.

RETURNS DESCRIPTION
IOStream The default input/output stream.
TYPE:IOStream

Source code in autogen/io/base.py

<br> 91<br> 92<br> 93<br> 94<br> 95<br> 96<br> 97<br> 98<br> 99<br>100<br>101<br>102<br>103<br> <br>@staticmethod<br>def get_default() -> "IOStream":<br> """Get the default input/output stream.<br> Returns:<br> IOStream: The default input/output stream.<br> """<br> iostream = IOStream._default_io_stream.get()<br> if iostream is None:<br> iostream = IOStream.get_global_default()<br> # Set the default IOStream of the current context (thread/cooroutine)<br> IOStream.set_default(iostream)<br> return iostream<br>

set_default staticmethod

set_default(stream)

Set the default input/output stream.

PARAMETER DESCRIPTION
stream The input/output stream to set as the default.
TYPE:IOStream

Source code in autogen/io/base.py

<br>105<br>106<br>107<br>108<br>109<br>110<br>111<br>112<br>113<br>114<br>115<br>116<br>117<br>118<br>119<br>120<br> <br>@staticmethod<br>@contextmanager<br>def set_default(stream: Optional["IOStream"]) -> Iterator[None]:<br> """Set the default input/output stream.<br> Args:<br> stream (IOStream): The input/output stream to set as the default.<br> """<br> global _default_io_stream<br> try:<br> token = IOStream._default_io_stream.set(stream)<br> yield<br> finally:<br> IOStream._default_io_stream.reset(token)<br> return<br>