Initial commit
This commit is contained in:
35
goodmorning.py
Normal file
35
goodmorning.py
Normal file
@@ -0,0 +1,35 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user