Files
lab_local_models/goodmorning.py
Chris Proctor acb9585eb6 Initial commit
2026-04-07 22:49:53 -04:00

36 lines
989 B
Python

import ollama
MODEL = "tinyllama"
SYSTEM_PROMPT = """
You are a helpful morning assistant. Help me get ready for school.
"""
def send_message(messages):
"""Sends a conversation to the model, streaming its reply to the screen."""
print("\nAssistant: ", end="", flush=True)
reply = ""
for chunk in ollama.chat(model=MODEL, messages=messages, stream=True):
piece = chunk.message.content
print(piece, end="", flush=True)
reply += piece
print()
return reply
def run():
"""Runs a chat loop, keeping track of the conversation."""
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
print("Good morning! Type 'quit' to exit.")
while True:
user_input = input("\nYou: ")
if user_input.strip().lower() == "quit":
break
messages.append({"role": "user", "content": user_input})
reply = send_message(messages)
messages.append({"role": "assistant", "content": reply})
run()