Page 1 of 1

Das Programm läuft nur einmal nach der Verwendung der Schleife

Posted: 02 Mar 2025, 14:30
by Anonymous

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)
Die LLM folgt der Anweisung und enthält eine lange Zusammenfassung der Daten und das Programm endet, aber das Programm sollte in einer Schleife ausgeführt werden, bis der Benutzer Beenden .>