| 13 | |
| 14 | |
| 15 | class SimpleChatIO(ChatIO): |
| 16 | def prompt_for_input(self, role) -> str: |
| 17 | return input(f"{role}: ") |
| 18 | |
| 19 | def prompt_for_output(self, role: str): |
| 20 | print(f"{role}: ", end="", flush=True) |
| 21 | |
| 22 | def stream_output(self, output_stream): |
| 23 | pre = 0 |
| 24 | for outputs in output_stream: |
| 25 | outputs = outputs.strip() |
| 26 | outputs = outputs.split(" ") |
| 27 | now = len(outputs) - 1 |
| 28 | if now > pre: |
| 29 | print(" ".join(outputs[pre:now]), end=" ", flush=True) |
| 30 | pre = now |
| 31 | print(" ".join(outputs[pre:]), flush=True) |
| 32 | return " ".join(outputs) |
| 33 | |
| 34 | |
| 35 | class RichChatIO(ChatIO): |