| 238 | """Return output.""" |
| 239 | |
| 240 | class SimpleChatIO(ChatIO): |
| 241 | def prompt_for_input(self, role) -> str: |
| 242 | return input(f"{role}: ") |
| 243 | |
| 244 | def prompt_for_output(self, role: str): |
| 245 | print(f"{role}: ", end="", flush=True) |
| 246 | |
| 247 | def stream_output(self, output_stream): |
| 248 | pre = 0 |
| 249 | for outputs in output_stream: |
| 250 | output_text = outputs["text"] |
| 251 | output_text = output_text.strip().split(" ") |
| 252 | now = len(output_text) - 1 |
| 253 | if now > pre: |
| 254 | print(" ".join(output_text[pre:now]), end=" ", flush=True) |
| 255 | pre = now |
| 256 | print(" ".join(output_text[pre:]), flush=True) |
| 257 | return " ".join(output_text) |
| 258 | |
| 259 | def return_output(self, output_stream): |
| 260 | pre = 0 |
| 261 | for outputs in output_stream: |
| 262 | output_text = outputs["text"] |
| 263 | output_text = output_text.strip().split(" ") |
| 264 | now = len(output_text) - 1 |
| 265 | if now > pre: |
| 266 | pre = now |
| 267 | return " ".join(output_text) |