This is what you will build. It is a teacher, not a search engine — because you tell it what job to do. นี่คือสิ่งที่คุณจะสร้าง มันเป็นครู ไม่ใช่เครื่องค้นหา เพราะคุณเป็นคนบอกมันว่าต้องทำหน้าที่อะไร 这就是你要做的东西。它是一个老师,不是搜索引擎 —— 因为是你告诉它要做什么工作。
🇬🇧 English
Most AI programs send your words to a big company. This one does not. The AI sits on your machine.
We build it in small steps. After almost every step you can run it and see something new.
The best part comes in step 4. You will give the AI a job, and you will not write one line of Python to do it.
You need Python first. If you do not have it, do Start Python before this page.
🇹🇭 ไทย
โปรแกรม AI ส่วนใหญ่ส่งคำพูดของคุณไปให้บริษัทใหญ่ ๆ อันนี้ไม่ส่ง ตัว AI อยู่ในเครื่องของคุณ
เราจะสร้างทีละขั้นเล็ก ๆ หลังจบเกือบทุกขั้น คุณสั่งรันแล้วจะเห็นอะไรใหม่ ๆ
ส่วนที่สนุกที่สุดอยู่ขั้นที่ 4 คุณจะให้งานกับ AI โดยไม่ต้องเขียนโค้ด Python เพิ่มแม้แต่บรรทัดเดียว
คุณต้องมี Python ก่อน ถ้ายังไม่มี ให้ทำ เริ่มต้น Python ก่อนหน้านี้
🇨🇳 中文
大部分 AI 程序会把你说的话送到大公司去。这个不会。AI 就在你自己的电脑里。
我们一小步一小步地做。几乎每一步做完,你都可以运行一下,看到新的东西。
最好玩的是第 4 步。你会给 AI 一份工作,而且一行 Python 都不用加。
你需要先装好 Python。还没装的话,先做开始学 Python。
0 Get ready · เตรียมตัว · 做好准备
🇬🇧 English
You need three things: Ollama, one AI model, and two Python libraries.
Ollama runs the AI on your machine. Get it from ollama.com. It works on Mac, Windows and Linux.
The model is the brain. It is a big download, about 5 GB. Be patient, and use good wifi.
LlamaIndex is the Python library that talks to Ollama for us.
🇹🇭 ไทย
คุณต้องมีสามอย่าง คือ Ollama โมเดล AI หนึ่งตัว และไลบรารี Python สองตัว
Ollama ทำหน้าที่รัน AI ในเครื่องคุณ โหลดได้ที่ ollama.com ใช้ได้ทั้ง Mac Windows และ Linux
โมเดลคือสมองของมัน ไฟล์ใหญ่ประมาณ 5 GB ใจเย็น ๆ และควรใช้ wifi ที่ดี
LlamaIndex คือไลบรารี Python ที่คุยกับ Ollama ให้เรา
🇨🇳 中文
你需要三样东西:Ollama、一个 AI 模型,还有两个 Python 库。
Ollama 负责在你的电脑上跑 AI。到 ollama.com 下载。Mac、Windows、Linux 都能用。
模型就是它的大脑。文件很大,大约 5 GB。耐心一点,用好一点的 wifi。
LlamaIndex 是帮我们和 Ollama 说话的 Python 库。
ollama pull qwen3 # the brain. About 5 GB.
pip3 install llama-index llama-index-llms-ollama
mkdir ~/Documents/Code/tutor
cd ~/Documents/Code/tutor
ollama list. You should see qwen3 in the list.
พิมพ์ ollama list คุณควรเห็น qwen3 อยู่ในรายการ
输入 ollama list,你应该会看到 qwen3 在列表里。
1 Is anyone home? · มีใครอยู่ไหม · 有人在家吗
🇬🇧 English
First we make sure Python can find the AI. Ask it one small question.
This is slow the first time. Ollama must wake the model up and put it in memory. Wait. It gets faster.
🇹🇭 ไทย
ก่อนอื่นเราต้องแน่ใจว่า Python หา AI เจอ ลองถามคำถามสั้น ๆ หนึ่งข้อ
ครั้งแรกจะช้า เพราะ Ollama ต้องปลุกโมเดลขึ้นมาใส่หน่วยความจำ รอหน่อย แล้วครั้งต่อไปจะเร็วขึ้น
🇨🇳 中文
先确认 Python 能找到 AI。问它一个小问题。
第一次会很慢,因为 Ollama 要把模型叫醒、装进内存。等一下,后面就快了。
from llama_index.llms.ollama import Ollama
llm = Ollama(model="qwen3", request_timeout=180.0)
print(llm.complete("Say hello in five words."))
python3 ask.py. The AI on your own machine says hello.
python3 ask.py ตัว AI ในเครื่องคุณเองจะทักทายกลับมา
python3 ask.py。你自己电脑里的 AI 会跟你打招呼。
2 It types as it thinks · พิมพ์ไปคิดไป · 边想边打字
🇬🇧 English
Waiting for the whole answer feels slow and dead. Real chat programs show the words as they arrive.
That is called streaming. We ask for the answer in small pieces, and print each piece at once.
flush=True matters. Without it, Python holds the words and you see nothing until the end.
end="" stops Python putting a new line after every piece.
🇹🇭 ไทย
การรอคำตอบทั้งก้อนรู้สึกช้าและเหมือนเครื่องค้าง โปรแกรมแชทจริง ๆ จะแสดงคำทีละคำตอนที่มันมาถึง
เรียกว่า streaming เราขอคำตอบเป็นชิ้นเล็ก ๆ แล้วพิมพ์ออกทันทีทีละชิ้น
flush=True สำคัญมาก ถ้าไม่มี Python จะเก็บคำไว้ คุณจะไม่เห็นอะไรเลยจนจบ
end="" ทำให้ Python ไม่ขึ้นบรรทัดใหม่หลังทุกชิ้น
🇨🇳 中文
等一整个答案出来,感觉很慢,像死机了。真正的聊天程序会一边收到字一边显示。
这叫 streaming(流式)。我们把答案一小块一小块地要过来,每收到一块就马上打出来。
flush=True 很重要。没有它,Python 会把字先存着,你要等到最后才看到东西。
end="" 让 Python 不要每一块后面都换行。
from llama_index.core.llms import ChatMessage
from llama_index.llms.ollama import Ollama
llm = Ollama(model="qwen3", request_timeout=180.0)
question = "Why is the sky blue? Answer in three short sentences."
for chunk in llm.stream_chat([ChatMessage(role="user", content=question)]):
print(chunk.delta or "", end="", flush=True)
print()
3 Thai on Windows breaks it · ภาษาไทยบน Windows ทำมันพัง · Windows 上打泰文会崩
🇬🇧 English
Try asking a question in Thai. On Windows the program may stop with an angry red error:
'charmap' codec can't encode characters
This is not your fault. The Windows terminal uses an old letter set. It has no Thai letters in it.
One line fixes it. Put it near the top, under your imports.
🇹🇭 ไทย
ลองถามเป็นภาษาไทยดู บน Windows โปรแกรมอาจหยุดพร้อม error สีแดง
'charmap' codec can't encode characters
ไม่ใช่ความผิดของคุณ เพราะ terminal ของ Windows ใช้ชุดตัวอักษรเก่า ซึ่งไม่มีตัวอักษรไทยอยู่
แก้ได้ด้วยบรรทัดเดียว ใส่ไว้ด้านบน ใต้ import
🇨🇳 中文
试着用泰文问一个问题。在 Windows 上程序可能会停下来,报一个红色的错:
'charmap' codec can't encode characters
这不是你的错。Windows 终端用的是一套很老的字符集,里面没有泰文字母。
一行就能修好。放在最上面,import 下面。
import sys
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
4 Give the AI a job — the Modelfile · ให้งานกับ AI ด้วย Modelfile · 给 AI 一份工作:Modelfile
🇬🇧 English
Right now the AI will talk about anything. We want a teacher. So we give it a job.
The job does not go in your Python file. It goes in a Modelfile.
A Modelfile is a small text file that Ollama reads when it builds a model. It has no file ending. The name is just Modelfile.
FROM says which brain to start with. SYSTEM says what job to do.
Then you build your own model from it. After that it is a real model, like any other.
🇹🇭 ไทย
ตอนนี้ AI จะคุยเรื่องอะไรก็ได้ แต่เราอยากได้ครู เราจึงต้องให้งานกับมัน
งานนี้ไม่อยู่ในไฟล์ Python ของคุณ แต่อยู่ในไฟล์ชื่อ Modelfile
Modelfile คือไฟล์ข้อความเล็ก ๆ ที่ Ollama อ่านตอนสร้างโมเดล ไม่มีนามสกุล ชื่อคือ Modelfile เฉย ๆ
FROM บอกว่าจะเริ่มจากสมองตัวไหน SYSTEM บอกว่าให้ทำงานอะไร
จากนั้นคุณสร้างโมเดลของคุณเองจากมัน แล้วมันก็จะเป็นโมเดลจริง ๆ เหมือนตัวอื่น
🇨🇳 中文
现在这个 AI 什么都聊。但我们要的是老师。所以我们给它一份工作。
这份工作不写在你的 Python 文件里,而是写在一个叫 Modelfile 的文件里。
Modelfile 是 Ollama 建模型时会读的一个小文本文件。它没有扩展名,名字就叫 Modelfile。
FROM 说从哪个大脑开始。SYSTEM 说要做什么工作。
然后你用它建出自己的模型。建好以后,它就跟别的模型一样了。
FROM qwen3
SYSTEM """
You are Kru Fah, an English tutor in Chiang Mai, Thailand.
Your students are Thai teenagers. Their English is not strong yet.
- Use short sentences. Aim for 15 words or fewer.
- Give a real example before you give a rule.
"""
ollama create krueng-tutor -f Modelfile
llm = Ollama(model="krueng-tutor", request_timeout=180.0)
5 Change the job, not the code · แก้ที่งาน ไม่ใช่ที่โค้ด · 改工作,不改代码
🇬🇧 English
Now grow the SYSTEM block. Tell the teacher exactly how to fix a mistake.
Then build again and run again. You will not touch ask.py at all.
Every time you change the Modelfile, you must build again. If nothing changed, you forgot to build. Everyone forgets. Twice.
Watch the first three lines. We found a real bug: when a student asked a question, the teacher still answered like it was fixing a mistake. Rules must say when not to do a thing, too.
🇹🇭 ไทย
ทีนี้ลองขยายส่วน SYSTEM บอกครูให้ชัดว่าต้องแก้ประโยคผิดยังไง
แล้วสร้างใหม่ รันใหม่ คุณจะไม่แตะ ask.py เลยแม้แต่นิดเดียว
ทุกครั้งที่แก้ Modelfile ต้องสั่งสร้างใหม่ ถ้าไม่มีอะไรเปลี่ยน แปลว่าคุณลืมสร้าง ทุกคนลืม และลืมสองรอบ
ดูสามบรรทัดแรกให้ดี เราเจอบั๊กจริง ๆ คือเวลานักเรียนถามคำถาม ครูก็ยังตอบแบบกำลังแก้ประโยคผิดอยู่ กฎที่ดีต้องบอกด้วยว่าเมื่อไหร่ไม่ต้องทำ
🇨🇳 中文
现在把 SYSTEM 写长一点。告诉这位老师,改错句子要怎么改。
然后重新建、重新跑。你完全不用碰 ask.py。
每次改了 Modelfile,都要重新建一次。如果什么都没变,就是你忘了建。每个人都会忘,而且会忘两次。
注意前三行。我们遇到过一个真实的 bug:学生只是问了个问题,老师却当成在改错句子。好的规则也要说清楚什么时候不要做。
A student may just ASK A QUESTION. Then simply answer the question.
Do not write "Correct:". Do not write an arrow like (go -> went).
Those are only for fixing a sentence, and a question is not a mistake.
ONLY when the student writes an English sentence that has a mistake in it:
- Write the correct sentence first, on its own line.
- Then write one short line naming what changed, like this: (go -> went)
- Then write one short line saying why, in simple English.
- Be warm. Never say the student is wrong or bad.
- Write plain text. This is a terminal, not a web page.
ollama create krueng-tutor -f Modelfile # build it again!
python3 ask.py
I go to Bangkok yesterday. You should get the fixed sentence, then (go -> went).
ลองป้อน I go to Bangkok yesterday. คุณควรได้ประโยคที่แก้แล้ว ตามด้วย (go -> went)
给它 I go to Bangkok yesterday.,你应该看到改好的句子,然后是 (go -> went)。
🇬🇧 English
One rule did not work. We asked it three times, in three ways, not to use markdown stars. It used them anyway: **like this**.
So we stopped asking. We take the stars out in our own code instead. One line, and it works every single time.
This is worth remembering. A rule you can enforce in code beats a rule you have to hope for. Ask the AI for the things only it can do. Do the simple, certain things yourself.
🇹🇭 ไทย
มีกฎข้อหนึ่งที่ไม่ได้ผล เราขอสามครั้ง สามแบบ ว่าอย่าใช้ดอกจันแบบ markdown มันก็ยังใช้อยู่ดี คือ **แบบนี้**
เราเลยเลิกขอ แล้วมาตัดดอกจันออกในโค้ดของเราเอง บรรทัดเดียว และได้ผลทุกครั้ง
จำไว้ให้ดี กฎที่บังคับได้ด้วยโค้ด ดีกว่ากฎที่ได้แค่หวัง ขอจาก AI เฉพาะสิ่งที่มีแต่มันทำได้ ส่วนเรื่องง่าย ๆ ที่แน่นอน จงทำเอง
🇨🇳 中文
有一条规则没有生效。我们用三种说法说了三次,叫它不要用 markdown 星号。它还是用:**像这样**
所以我们不再请求了,直接在自己的代码里把星号去掉。一行,每次都管用。
这一点值得记住:能用代码强制的规则,比只能希望它听话的规则好。只把只有 AI 能做的事交给它;简单、确定的事,自己做。
piece = (chunk.delta or "").replace("*", "")
6 Ask the same thing five times · ถามคำถามเดิมห้าครั้ง · 同一个问题问五次
🇬🇧 English
Ask the AI the same question five times. The answers will not be the same.
The AI picks its next word from a list of likely words. Temperature decides how brave that choice is.
High temperature means more surprising words. That is nice for a poem. It is bad for a teacher.
We tested this. At 0.6 the teacher sometimes broke its own rules. At 0 it never did, and the same question gave exactly the same answer every time.
A teacher should be boring. Set it to zero.
🇹🇭 ไทย
ลองถามคำถามเดิมห้าครั้ง คำตอบจะไม่เหมือนกัน
AI เลือกคำถัดไปจากรายการคำที่น่าจะใช่ ค่า temperature เป็นตัวบอกว่าจะเลือกกล้าแค่ไหน
ค่าสูงแปลว่าได้คำที่เซอร์ไพรส์มากขึ้น ดีสำหรับบทกวี แต่ไม่ดีสำหรับครู
เราทดสอบมาแล้ว ที่ 0.6 ครูบางครั้งทำผิดกฎของตัวเอง ที่ 0 ไม่ผิดเลย และคำถามเดิมให้คำตอบเดิมเป๊ะทุกครั้ง
ครูควรจะน่าเบื่อ ตั้งเป็นศูนย์ไปเลย
🇨🇳 中文
把同一个问题问五次。答案不会一样。
AI 从一堆可能的词里挑下一个词。temperature(温度)决定它挑得多大胆。
温度高就会出现更让人意外的词。写诗很好,当老师就不好了。
我们测过:在 0.6 时,这位老师有时会违反自己的规则;在 0 时一次都没有,而且同样的问题每次的答案一模一样。
老师应该无聊一点。设成零。
PARAMETER temperature 0 # always pick the most likely word
PARAMETER num_ctx 4096 # how much talk it can hold in mind
7 A small brain gets it wrong · สมองเล็กตอบผิด · 小脑袋会答错
🇬🇧 English
This is the most important step on the page, and it is not about code.
We asked four AI models one easy question: Why do we add s to verbs?
Three of them got it wrong. Look at the table. Each one was wrong in a different way.
When every model is wrong in the same way, something is broken. When they are all wrong in different ways, they are guessing.
So test your teacher before you trust it. Ask it ten things you already know. A small brain is fast and free, but it will teach your friends things that are not true.
🇹🇭 ไทย
นี่คือขั้นที่สำคัญที่สุดในหน้านี้ และไม่เกี่ยวกับโค้ดเลย
เราถามโมเดล AI สี่ตัวด้วยคำถามง่าย ๆ ข้อเดียว ทำไมต้องเติม s ท้ายคำกริยา
สามตัวตอบผิด ดูตารางข้างล่าง แต่ละตัวผิดคนละแบบ
ถ้าทุกตัวผิดเหมือนกัน แปลว่ามีอะไรพัง แต่ถ้าผิดคนละแบบ แปลว่ามันกำลังเดา
ฉะนั้นต้องทดสอบครูของคุณก่อนจะเชื่อ ลองถามสิบเรื่องที่คุณรู้คำตอบอยู่แล้ว สมองเล็กนั้นเร็วและฟรี แต่มันจะสอนเพื่อนคุณในสิ่งที่ไม่จริง
🇨🇳 中文
这是整页最重要的一步,而且跟代码无关。
我们问了四个 AI 模型同一个简单问题:动词后面为什么要加 s?
三个答错了。看下面的表。每一个都错得不一样。
如果所有模型错得一模一样,那是有东西坏了。如果各错各的,那说明它们在猜。
所以,在相信你的老师之前先考它。问十个你已经知道答案的问题。小脑袋又快又免费,但它会教你的朋友一些不真实的东西。
| Model | Its answer | Right? |
|---|---|---|
llama3.2 (3B) | "It marks plural." | ✗ |
hermes3:8b | "It means more than one person or thing." | ✗ |
qwen3, thinking off | "It shows a habit, something that happens often." | ✗ |
qwen3, room to answer | "When the subject is he, she or it. He runs, not He run." | ✓ |
FROM qwen3 to FROM llama3.2, build, and ask the same question. Same Modelfile, different brain, worse teacher.
เปลี่ยน FROM qwen3 เป็น FROM llama3.2 สร้างใหม่ แล้วถามคำถามเดิม Modelfile เดิม แต่คนละสมอง ได้ครูที่แย่กว่า
把 FROM qwen3 改成 FROM llama3.2,重新建,再问同一个问题。同一个 Modelfile,换个大脑,老师就变差了。
8 It remembers the talk · มันจำบทสนทนาได้ · 它记得聊过什么
🇬🇧 English
Right now every question is the first question. The AI forgets you at once.
The fix is simple, and it may surprise you. The AI has no memory. We send the whole conversation again every time.
So we keep a list. Your words go in the list. Its answer goes in the list too.
🇹🇭 ไทย
ตอนนี้ทุกคำถามคือคำถามแรกเสมอ AI ลืมคุณทันที
วิธีแก้ง่ายมาก และอาจทำให้คุณแปลกใจ AI ไม่มีความจำ เราส่งบทสนทนาทั้งหมดกลับไปใหม่ทุกครั้ง
เราจึงเก็บเป็นลิสต์ คำพูดของคุณใส่ลงลิสต์ คำตอบของมันก็ใส่ลงลิสต์ด้วย
🇨🇳 中文
现在每个问题都是第一个问题。AI 马上就把你忘了。
解决办法很简单,可能会让你惊讶:AI 根本没有记忆。我们每次都把整段对话重新发一遍。
所以我们留一个列表。你说的话放进列表,它的回答也放进列表。
history = []
while True:
question = input("you > ").strip()
if not question:
continue
history.append(ChatMessage(role="user", content=question))
print("kru > ", end="", flush=True)
answer = ""
for chunk in llm.stream_chat(history):
piece = chunk.delta or ""
print(piece, end="", flush=True)
answer += piece
print("\n")
history.append(ChatMessage(role="assistant", content=answer))
My name is Ploy. Then ask What is my name? Now it knows. Press Ctrl+C to stop.
พิมพ์ My name is Ploy. แล้วถาม What is my name? ตอนนี้มันรู้แล้ว กด Ctrl+C เพื่อหยุด
先说 My name is Ploy.,再问 What is my name?。现在它知道了。按 Ctrl+C 停止。
9 Ask from the command line · ถามจากบรรทัดคำสั่ง · 从命令行提问
🇬🇧 English
Editing the file every time you want to ask something is slow. Let the program take orders.
argparse comes free with Python. It reads the words you type after the file name.
🇹🇭 ไทย
การแก้ไฟล์ทุกครั้งที่อยากถามอะไรนั้นช้า ให้โปรแกรมรับคำสั่งเองดีกว่า
argparse มีมากับ Python อยู่แล้ว มันอ่านคำที่คุณพิมพ์ต่อท้ายชื่อไฟล์
🇨🇳 中文
每次想问点什么都要改文件,太慢了。让程序自己接受命令。
argparse 是 Python 自带的。它会读你在文件名后面打的字。
import argparse
parser = argparse.ArgumentParser(description="Talk to your own local AI.")
parser.add_argument("question", nargs="*", help="what to ask")
parser.add_argument("--chat", action="store_true", help="keep talking")
parser.add_argument("--model", default="krueng-tutor")
parser.add_argument("--host", default="http://localhost:11434")
args = parser.parse_args()
python3 ask.py "She don't like coffee."
python3 ask.py --chat
10 When it breaks · ตอนที่มันพัง · 出问题的时候
🇬🇧 English
Three things go wrong. A long red error helps nobody. Say what happened, and what to do.
This is a kindness to the next person who runs your program. Often that person is you, next month.
🇹🇭 ไทย
มีสามอย่างที่มักพัง ข้อความ error สีแดงยาว ๆ ไม่ช่วยใครเลย บอกไปเลยว่าเกิดอะไรขึ้น และต้องทำอะไร
นี่คือความใจดีต่อคนที่จะมารันโปรแกรมของคุณต่อ ซึ่งบ่อยครั้งคนนั้นก็คือตัวคุณเองในเดือนหน้า
🇨🇳 中文
会出三种问题。一长串红色报错帮不了任何人。直接说清楚发生了什么,该怎么办。
这是对下一个运行你程序的人的善意。而那个人常常就是下个月的你自己。
except Exception as problem:
text = str(problem).lower()
if "connect" in text or "refused" in text:
print("Cannot reach Ollama. Is it running? Try: ollama list")
elif "not found" in text:
print("No model called that. Try: ollama create krueng-tutor -f Modelfile")
else:
print("Something went wrong: %s" % problem)
11 Use a bigger machine · ใช้เครื่องที่ใหญ่กว่า · 用更大的机器
🇬🇧 English
Your laptop is slow with big brains. Maybe your school has a strong computer. You can use that one instead.
Ollama only listens to its own machine at first. On the strong computer, tell it to listen to the whole room:
Then point your program at it. Same code. Same Modelfile. Bigger brain.
Your words still stay inside the school. Nothing goes to a company.
🇹🇭 ไทย
โน้ตบุ๊กของคุณช้าเมื่อเจอสมองใหญ่ ๆ บางทีโรงเรียนอาจมีเครื่องแรง ๆ คุณใช้เครื่องนั้นแทนได้
ตอนแรก Ollama จะฟังแค่เครื่องตัวเอง ที่เครื่องแรง ให้สั่งมันฟังทั้งห้อง
แล้วชี้โปรแกรมของคุณไปที่เครื่องนั้น โค้ดเดิม Modelfile เดิม แต่สมองใหญ่ขึ้น
คำพูดของคุณยังอยู่ในโรงเรียน ไม่มีอะไรออกไปหาบริษัทไหน
🇨🇳 中文
大脑袋跑在你的笔记本上会很慢。也许学校有一台很强的电脑,你可以改用那一台。
Ollama 一开始只听自己这台机器的。在那台强电脑上,让它听整个房间:
然后把你的程序指过去。同样的代码,同样的 Modelfile,更大的脑袋。
你的话依然留在学校里,不会送到任何公司去。
# on the strong computer:
OLLAMA_HOST=0.0.0.0 ollama serve
# on your laptop:
python3 ask.py --host http://192.168.1.42:11434 "What is the past perfect?"
12 The whole thing · ทั้งหมดรวมกัน · 完整的东西
🇬🇧 English
Here are the two finished files. Download them and compare with your own.
Put them in the same folder. Build the model once, then run the program.
🇹🇭 ไทย
นี่คือไฟล์ที่เสร็จแล้วสองไฟล์ ดาวน์โหลดไปเทียบกับของคุณเองได้
วางไว้ในโฟลเดอร์เดียวกัน สร้างโมเดลหนึ่งครั้ง แล้วสั่งรันโปรแกรม
🇨🇳 中文
这是两个做完的文件。下载下来,和你自己写的对照一下。
放在同一个文件夹里。先建一次模型,然后运行程序。
cd ~/Documents/Code/tutor
ollama create krueng-tutor -f Modelfile
python3 ask.py --chat
13 Now change it · ลองแก้ดู · 现在动手改它
🇬🇧 English
Almost everything interesting here happens in the Modelfile, not in Python.
That is the lesson: the code stays the same, the job makes the difference.
🇹🇭 ไทย
เรื่องน่าสนใจเกือบทั้งหมดเกิดใน Modelfile ไม่ใช่ใน Python
นี่แหละคือบทเรียน โค้ดยังเหมือนเดิม แต่งานที่ให้ไปทำให้ทุกอย่างต่างกัน
🇨🇳 中文
这里几乎所有好玩的事情都发生在 Modelfile 里,不在 Python 里。
这就是这一课的重点:代码没有变,是工作造成了差别。
| Try this | How | Level |
|---|---|---|
| Make a maths teacher | Rewrite the SYSTEM block. Change nothing else. Build again. | easy |
| Make it stricter about length | Change 15 words to 8 words in SYSTEM. | easy |
| Make it wild again | PARAMETER temperature 1.2. Ask the same thing five times. | easy |
| Give it a name your class picks | One word in SYSTEM, then ollama create your-name -f Modelfile. | easy |
| Save every talk to a file | Write history out as JSON when the program stops. | harder |
| Test it like we did | Write a loop that asks 10 questions you know, and prints each answer. | harder |