MCPcopy
hub / github.com/lm-sys/FastChat / SimpleChatIO

Class SimpleChatIO

fastchat/serve/cli.py:40–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40class SimpleChatIO(ChatIO):
41 def __init__(self, multiline: bool = False):
42 self._multiline = multiline
43
44 def prompt_for_input(self, role) -> str:
45 if not self._multiline:
46 return input(f"{role}: ")
47
48 prompt_data = []
49 line = input(f"{role} [ctrl-d/z on empty line to end]: ")
50 while True:
51 prompt_data.append(line.strip())
52 try:
53 line = input()
54 except EOFError as e:
55 break
56 return "\n".join(prompt_data)
57
58 def prompt_for_output(self, role: str):
59 print(f"{role}: ", end="", flush=True)
60
61 def stream_output(self, output_stream):
62 pre = 0
63 for outputs in output_stream:
64 output_text = outputs["text"]
65 output_text = output_text.strip().split(" ")
66 now = len(output_text) - 1
67 if now > pre:
68 print(" ".join(output_text[pre:now]), end=" ", flush=True)
69 pre = now
70 print(" ".join(output_text[pre:]), flush=True)
71 return " ".join(output_text)
72
73 def print_output(self, text: str):
74 print(text)
75
76
77class RichChatIO(ChatIO):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…