IOConsole - AG2
IOConsole
autogen.io.IOConsole
Bases: IOStream
A console input/output stream.
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>102<br>103<br>104<br>105<br>106<br>107<br>108<br>109<br> |
<br>@staticmethod<br>def set_global_default(stream: iostream_union) -> 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_union |
Source code in autogen/io/base.py
<br>111<br>112<br>113<br>114<br>115<br>116<br>117<br>118<br>119<br>120<br> |
<br>@staticmethod<br>def get_global_default() -> iostream_union:<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_union |
Source code in autogen/io/base.py
<br>122<br>123<br>124<br>125<br>126<br>127<br>128<br>129<br>130<br>131<br>132<br>133<br>134<br> |
<br>@staticmethod<br>def get_default() -> iostream_union:<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>136<br>137<br>138<br>139<br>140<br>141<br>142<br>143<br>144<br>145<br>146<br>147<br>148<br>149<br>150<br>151<br> |
<br>@staticmethod<br>@contextmanager<br>def set_default(stream: Optional[iostream_union]) -> 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> |
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/console.py
<br>22<br>23<br>24<br>25<br>26<br>27<br>28<br>29<br>30<br>31<br>32<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> print_message = PrintEvent(*objects, sep=sep, end=end)<br> self.send(print_message)<br> |
send
send(message)
Send a message to the output stream.
| PARAMETER | DESCRIPTION |
|---|---|
message |
The message to send. TYPE: Any |
Source code in autogen/io/console.py
<br>35<br>36<br>37<br>38<br>39<br>40<br>41<br> |
<br>def send(self, message: BaseEvent) -> None:<br> """Send a message to the output stream.<br> Args:<br> message (Any): The message to send.<br> """<br> message.print()<br> |
input
input(prompt='', *, password=False)
Read a line from the input stream.
| PARAMETER | DESCRIPTION |
|---|---|
prompt |
The prompt to display. Defaults to "". TYPE: str DEFAULT: '' |
password |
Whether to read a password. Defaults to False. TYPE: bool DEFAULT: False |
| RETURNS | DESCRIPTION |
|---|---|
str |
The line read from the input stream. TYPE: str |
Source code in autogen/io/console.py
<br>43<br>44<br>45<br>46<br>47<br>48<br>49<br>50<br>51<br>52<br>53<br>54<br>55<br>56<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> if password:<br> return getpass.getpass(prompt if prompt != "" else "Password: ")<br> return input(prompt)<br> |