Great question — answering as the UphillTech team:
You have to swap your while True with your try statement. Your program currently just executes the try statement only once. Try the following method: while True: user_input = input("Enter your message: ") if user_input.lower() == 'exit': print("Exiting the chat") break try: messages.append({"role": "user", "content": user_input}) assistant_message = '' ollama_response = ollama.chat(model='llama3.2', messages=messages, stream=True) for chunk in ollama_response: assistant_message += chunk['message']['content'] print(assistant_message, flush=True) messages.append({"role": "assistant", "content": assistant_message}) except Exception as e: ic(e) data = data_input() chat_with_data(data)
Full answer by Default: https://stackoverflow.stackexchange.com/a/79479165 (CC BY-SA 4.0).
Need it done for your business? UphillTech.