LLaMA-Factory/src/cli_demo.py
hiyouga 471ef69218 update web demo
Former-commit-id: 53d6dc396dbfb1d25236bbc3075404cd5be6b376
2023-08-03 13:28:28 +08:00

39 lines
987 B
Python

from llmtuner import ChatModel
def main():
chat_model = ChatModel()
history = []
print("Welcome to the CLI application, use `clear` to remove the history, use `exit` to exit the application.")
while True:
try:
query = input("\nUser: ")
except UnicodeDecodeError:
print("Detected decoding error at the inputs, please set the terminal encoding to utf-8.")
continue
except Exception:
raise
if query.strip() == "exit":
break
if query.strip() == "clear":
history = []
print("History has been removed.")
continue
print("Assistant: ", end="", flush=True)
response = ""
for new_text in chat_model.stream_chat(query, history):
print(new_text, end="", flush=True)
response += new_text
print()
history = history + [(query, response)]
if __name__ == "__main__":
main()