Skip to content

Instantly share code, notes, and snippets.

@clutterstack
Last active December 5, 2025 21:27
Show Gist options
  • Select an option

  • Save clutterstack/9946f3729b0040222130354392294001 to your computer and use it in GitHub Desktop.

Select an option

Save clutterstack/9946f3729b0040222130354392294001 to your computer and use it in GitHub Desktop.
Minimal chat CLI for local ollama-hosted models
#!/usr/bin/env python3
import readline # Readline gives the input prompt some basic editing and history facilities
import ollama # The Ollama Python SDK
#MODEL = "phi4-mini"
MODEL = "qwen3:0.6b"
messages = [{"role": "system", "content": ""}] # empty system prompt
def process(user_input):
messages.append({"role": "user", "content": user_input}) # add input to messages
resp = ollama.chat(model=MODEL, messages=messages) # send context (messages) to the model and get a response back
msg = resp.get("message", {}) # pull out the message part of the response
content = msg.get("content", "") # from the message pull out the content string
messages.append({"role":"assistant","content":content}) # tack the response content onto the context list for next round
return content # return the response content for printing
# Loop.
def main():
while True:
try:
line = input("> ").strip()
print(process(line))
print()
except KeyboardInterrupt:
print()
break
if __name__ == "__main__":
main()

Here's a minimal Python chat interface for a model served locally by Ollama.

It's based on this general recipe:

  • wait for the user to input a prompt
  • add a message to chat history containing the user input
  • send any system prompt (or none) + full chat history to the model (via API)
  • add the completion from the model to chat history
  • repeat

Used with Qwen3:0.6b, without a system prompt:

❯ python chat.py
> What's a lagomorph
<think>
Okay, the user is asking about what a lagomorph is. First, I need to recall what I know about lagomorphs. They're a group of mammals, right? Like the lizards and some rodents. Wait, but I remember that lizards and rodents are considered part of the order Lagomorpha, but some sources say they are separate. Let me check my notes.

Oh, right! The lagomorphs are a group of mammals that include the lizards and some rodents. But wait, I think some sources mention that they are actually lizards and some rodents. Wait, no, that can't be. Let me think again. The lagomorphs are the order that includes lizards and some rodents. So the user is probably confusing this with other orders. They might be referring to a specific group, but I need to make sure.

Wait, but I think the correct classification is that lagomorphs are a group of mammals, which includes lizards and some rodents. So the answer should state that they are a group of mammals, specifically lizards and some rodents, and explain their characteristics. Also, mention that they are part of the order Lagomorpha. Need to be precise here.
</think>

A **lagomorph** is a group of mammals, specifically the order **Lagomorpha**. This includes both **lizards** and some **rodents**. These organisms are characterized by their **long, coiled bodies** and **exoskeleton** (not fully enclosed in a shell), which allows them to have a **range of body sizes** from small, terrestrial lizards to larger, more mobile rodents. They are known for their **long, webbed feet** and **adapted for movement** in various environments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment