Das Programm läuft nur einmal nach der Verwendung der Schleife
Posted: 02 Mar 2025, 14:30
Code: Select all
def data_input():
# It gets the data that the llm need and the user wants to ask question related to this data
def chat_with_data(data):
messages = [
{
"role": "system",
"content": "You are given some data and you have to analyze the data correctly if the user asks for any output then give the output as per the data and user's question otherwise don't give answer."
},
{
"role": "user",
"content": data
}
]
try:
while True:
user_input = input("Enter your message: ")
if user_input.lower() == 'exit':
print("Exiting the chat")
break
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)