The Art of Prompt Engineering for Typhoon
Effective prompting is key to getting the best results from Typhoon models. This comprehensive guide provides best practices and techniques specifically optimized for Typhoon’s Thai language capabilities.
Basic Prompting Guidelines
For optimal results with Typhoon models, follow these fundamental practices:
- Put instructions in the first turn: Place all instructions at the beginning of your conversation for better comprehension and more consistent results.
- Be clear and concise: Your prompt should be easy to understand while providing sufficient context. Avoid unnecessary jargon or overly technical terms.
- Prefer single-turn conversations: Although multi-turn conversations are supported, Typhoon generally performs best in single-turn exchanges.
- Start fresh for new topics: Use a new chat session for unrelated questions rather than continuing in the same thread.
- Use English for instructions, Thai for context: Provide system instructions in English while including Thai context/documents as needed.
- Utilize few-shot examples: When possible, demonstrate what you want with examples rather than just describing it.
Be Clear and Concise
Example:
❌ "Elucidate the variegated methodologies inherent in sustainable agricultural practices in Thailand's northeastern region."
✅ "Explain the different sustainable farming methods used in northeastern Thailand."
Use Specific Examples
Providing concrete examples helps the model understand your expectations better.
Example:
❌ "Write a Thai folk tale."
✅ "Write a Thai folk tale about a clever rabbit who outsmarts a crocodile to cross a river. Include elements of traditional Thai storytelling such as moral lessons and natural settings."
System Messages vs. User Messages
System messages help set the behavior of the model more effectively than including the same instructions in user messages:
# Effective: Using system message for instructionsmessages = [ {"role": "system", "content": "You are a Thai language tutor. Always respond in Thai and correct any grammatical mistakes in the user's Thai."}, {"role": "user", "content": "สวัสดีครับ ผมอยากเรียน ภาษาไทย"}]
# Less effective: Putting instructions in user messagemessages = [ {"role": "user", "content": "You are a Thai language tutor. Always respond in Thai and correct any grammatical mistakes. Here's my message: สวัสดีครับ ผมอยากเรียน ภาษาไทย"}]
Structuring Effective Prompts
Use Formatting for Clarity
Use markdown formatting to make your prompts more readable:
แปลข้อความต่อไปนี้จากภาษาไทยเป็นภาษาอังกฤษ:
**ข้อความต้นฉบับ**:การท่องเที่ยวแห่งประเทศไทยได้ประกาศแผนการส่งเสริมการท่องเที่ยวในปี 2567 โดยมุ่งเน้นการท่องเที่ยวเชิงวัฒนธรรมและความยั่งยืน
**คำแนะนำเพิ่มเติม**:- รักษาน้ำเสียงทางการ- คงความหมายทั้งหมดไว้- ใช้คำศัพท์ด้านการท่องเที่ยวที่เหมาะสม
Provide Examples (Few-Shot Prompting)
Showing examples helps the model understand the format and style you want:
แปลประโยคต่อไปนี้จากภาษาอังกฤษเป็นภาษาไทยในรูปแบบทางการ:
ตัวอย่าง 1:อังกฤษ: "The meeting will be held on Monday."ไทย: "การประชุมจะจัดขึ้นในวันจันทร์"
ตัวอย่าง 2:อังกฤษ: "Please submit your report by Friday."ไทย: "กรุณาส่งรายงานของท่านภายในวันศุกร์"
ประโยคที่ต้องการแปล:"The committee has decided to postpone the annual conference until further notice."
Structure Examples Wisely
Add one or two examples when the model isn’t following your instructions, but don’t overdo it.
Example:
"Translate the following English sentences to formal Thai.
Example:English: I would like to schedule a meeting with you next week.Thai: ผมขอนัดประชุมกับคุณในสัปดาห์หน้า
Now translate: The committee has decided to postpone the event until further notice."
Limit Few-Shot Examples
Modern LLMs often perform better with clear instructions than with many examples. If needed, use no more than 5 few-shot examples.
Task-Specific Prompting Strategies
Translation
For translation tasks, specify the tone, context, and any specialized vocabulary:
แปลข้อความต่อไปนี้จากภาษาไทยเป็นภาษาอังกฤษ โดยใช้สำนวนทางธุรกิจที่เป็นทางการ:
"บริษัทของเรามีความยินดีที่จะแจ้งให้ทราบว่าเราได้ขยายการดำเนินงานไปยังตลาดใหม่ในภูมิภาคเอเชียตะวันออกเฉียงใต้ ซึ่งจะช่วยเพิ่มโอกาสทางธุรกิจและการเติบโตในอนาคต"
Content Creation
Be specific about length, style, format, and audience:
เขียนบทความการท่องเที่ยวเกี่ยวกับเชียงใหม่ โดยมีรายละเอียดดังนี้:
- ความยาวประมาณ 3 ย่อหน้า- กลุ่มเป้าหมายคือนักท่องเที่ยวต่างชาติที่สนใจวัฒนธรรมท้องถิ่น- เน้นสถานที่ที่ไม่เป็นที่รู้จักแต่มีคุณค่าทางวัฒนธรรม- ใช้ภาษาที่กระตุ้นความสนใจและสร้างแรงบันดาลใจ- แนะนำช่วงเวลาที่เหมาะสมในการเยี่ยมชม
Summarization
Specify the length, key points to include, and the desired format:
สรุปบทความต่อไปนี้เกี่ยวกับผลกระทบของการเปลี่ยนแปลงสภาพภูมิอากาศในประเทศไทย:
- สรุปให้กระชับไม่เกิน 3 ประโยค- เน้นผลกระทบหลักและมาตรการรับมือที่เสนอ- รักษาข้อมูลทางสถิติที่สำคัญ
[บทความ...]
Code Generation and Explanation
Provide context about the programming environment and specific requirements:
เขียนโค้ด Python สำหรับเว็บแอปพลิเคชันอย่างง่ายที่ใช้ภาษาไทยในการแสดงผล โดยมีคุณสมบัติดังนี้:
- ใช้ Flask เป็นเฟรมเวิร์ค- มีหน้าหลักที่แสดงข้อความทักทายภาษาไทย- มีฟอร์มสำหรับกรอกชื่อและข้อความ- เมื่อส่งฟอร์ม ให้แสดงข้อความตอบกลับเป็นภาษาไทย- รองรับการแสดงผลอักขระภาษาไทยอย่างถูกต้อง
อธิบายโค้ดแต่ละส่วนเป็นภาษาไทยอย่างละเอียด
Advanced Prompting Techniques
Vary Your Prompts for Creative Responses
Different approaches to prompting can yield more diverse and creative outputs.
Example:
Prompt 1: "Write a poem about Bangkok in the rainy season."Prompt 2: "Imagine you're a street vendor in Bangkok during monsoon season. Describe what you see, hear, and feel."Prompt 3: "ฝนตกในกรุงเทพฯ ทำให้คุณรู้สึกอย่างไร? เขียนบทกวีสั้นๆ เกี่ยวกับความรู้สึกนี้"
Try and Refine
Start with a simple prompt, then iteratively add constraints or information to get closer to your desired result.
Example:
Initial prompt: "Summarize Thailand's economic outlook."Refined prompt: "Summarize Thailand's economic outlook for 2025, focusing on tourism recovery and technology sectors."Further refined: "Summarize Thailand's economic outlook for 2025, focusing on tourism recovery and technology sectors. Include key statistics and present in 5 bullet points."
Chain-of-Thought Prompting
Encourage the model to work through problems step by step:
โจทย์คณิตศาสตร์: หากร้านค้าขายเสื้อยืดในราคา 350 บาท ลดราคา 15% แล้วยังเก็บภาษีมูลค่าเพิ่ม 7% ลูกค้าจะต้องจ่ายเงินทั้งหมดเท่าไร
แก้โจทย์นี้ทีละขั้นตอน อธิบายแต่ละขั้นตอนอย่างละเอียด และแสดงวิธีการคำนวณที่ชัดเจน
Role-Based Prompting
Assign a specific role to the model to get responses in a particular style:
คุณเป็นนักภาษาศาสตร์ที่เชี่ยวชาญด้านภาษาไทยโบราณ โปรดอธิบายความแตกต่างระหว่างภาษาไทยสมัยสุโขทัยและภาษาไทยปัจจุบัน พร้อมยกตัวอย่างประโยคและคำศัพท์ที่เปลี่ยนแปลงไป
Format Specification
Clearly specify the expected output format:
วิเคราะห์ข้อความรีวิวร้านอาหารต่อไปนี้และให้ผลลัพธ์ในรูปแบบ JSON ที่มีฟิลด์ดังนี้:- sentiment: "positive", "neutral", หรือ "negative"- key_positives: [จุดเด่นของร้าน เป็น array]- key_negatives: [จุดที่ควรปรับปรุง เป็น array]- overall_score: คะแนนจาก 1-10
ข้อความรีวิว: "ร้านนี้อาหารรสชาติดีมาก โดยเฉพาะต้มยำกุ้ง แต่บริการค่อนข้างช้า และราคาสูงกว่าร้านอื่นในละแวกเดียวกัน บรรยากาศร้านตกแต่งสวย ที่จอดรถสะดวก"
Be Direct About Outputs
If you only want JSON, say so explicitly. This prevents the model from showing its reasoning process.
Example:
"Convert this Thai restaurant information to JSON format. Return ONLY valid JSON without any explanations or additional text:
ชื่อร้าน: บ้านสวนที่อยู่: สุขุมวิท 55เวลาเปิด: 11:00 - 22:00ประเภทอาหาร: อาหารไทย, อาหารอีสาน"
Avoid Overly Complex Prompts
Complexity can reduce model performance rather than improve it.
Example:
❌ "Analyze the multifaceted interplay between Thailand's political landscape, economic determinants, sociocultural factors, and geographical considerations to synthesize a comprehensive evaluation of potential investment opportunities in the eastern economic corridor while factoring in historical precedents, regulatory frameworks, and future projections according to various economic models."
✅ "What are the main investment opportunities in Thailand's eastern economic corridor? Consider political, economic, and regulatory factors."
Advanced Implementation Strategies
Use Code for Outputs Extraction
It’s often easier to extract model outputs with code than to perfect your prompt.
Example:
const extractCodeBlock = (text) => { // Regular expression to match code blocks with their fences const codeBlockRegex = /\`\`\`(?:[a-zA-Z0-9]+)?([\s\S]*?)\`\`\`/gm;
// Array to store all extracted code blocks const extractedBlocks = [];
// Find all code blocks and extract their content let match; while ((match = codeBlockRegex.exec(text)) !== null) { // match[1] contains the content between the code fences extractedBlocks.push(match[1].trim()); }
// Return all extracted code blocks return extractedBlocks;}
Use Reasoning Models for Complex Tasks
When your task requires multiple-step thinking or editing, use a reasoning-focused model.
Example:
"I need to create a comprehensive marketing strategy for a new Thai street food chain targeting tourists and locals. Please think step by step about market research, positioning, pricing, promotion channels, and cultural considerations."
Implement Feedback Loops
Many issues can be solved through iterative feedback and refinement.
Example:
Initial process: Input → LLM → OutputRefined process: JSON.parse(output) → error → LLM → Refined output
"Your previous response had a JSON parsing error. Please fix the following issue and return only valid JSON: Missing comma after the 'name' field."
Break Down Complex Tasks
For challenging tasks, use a divide-and-conquer approach.
Example: Instead of:
❌ "Please create a presentation from this market research data." [large text dump]
Try:
✅ Step 1: "Please identify the 5 key insights from this market research data." [data]✅ Step 2: "For insight #1, create a slide with a compelling headline, 3 supporting points, and a visualization suggestion."✅ Step 3: "Organize these 5 slides into a coherent narrative that flows logically."
Use Explicit Instructions
Be specific about style, format, and restrictions.
Example for Stylization:
"Explain blockchain technology in language a 5-year-old Thai child would understand."
Example for Formatting:
"Answer this question about Thai history and provide citations as numbers [1], [2], etc. Include the full references at the end of your response."
Example for Restrictions:
"Answer this healthcare question based only on information in the attached documents. If the documents don't contain relevant information, politely decline to answer."
Leverage External Data Sources
Use RAG (Retrieval-Augmented Generation) or web search capabilities to reduce hallucinations.
Example:
"Using the attached Thai medical guidelines, answer the following question about diabetes treatment protocols. Only include information that is explicitly mentioned in the documents."
Troubleshooting Common Issues
Model Generating Thai When English is Needed (or Vice Versa)
Be explicit about the language you want in your system message:
# System message for enforcing English output{"role": "system", "content": "You are a helpful assistant. Always respond in English only, regardless of the language used in the query."}
# System message for enforcing Thai output{"role": "system", "content": "You are a helpful assistant. Always respond in Thai only, regardless of the language used in the query."}
Responses Too Long or Too Short
Specify desired length and format:
# For shorter responses"อธิบายวิธีการทำต้มยำกุ้งแบบดั้งเดิม โดยให้ตอบไม่เกิน 3 ประโยค"
# For longer, detailed responses"อธิบายประวัติและความสำคัญของอาหารไทยในวัฒนธรรมไทยอย่างละเอียด โดยแบ่งเป็นหัวข้อย่อยดังนี้: ประวัติความเป็นมา, วัตถุดิบสำคัญ, เทคนิคการปรุงเฉพาะ, และอิทธิพลจากวัฒนธรรมอื่น ให้ตอบอย่างละเอียดอย่างน้อย 500 คำ"
Repetitive or Generic Responses
Use temperature and specific instructions to get more varied responses:
# Using higher temperature for more creative responses# Set temperature=0.8 with this prompt:"แนะนำสถานที่ท่องเที่ยวที่ไม่เป็นที่รู้จักแต่น่าสนใจในจังหวัดเชียงใหม่ อธิบายด้วยภาษาที่สร้างสรรค์และน่าสนใจ ห้ามแนะนำสถานที่ที่เป็นที่นิยมแล้ว เช่น ดอยสุเทพ หรือ ถนนคนเดินท่าแพ"
Language Considerations
Choose Language Based on Priority
If natural Thai language is more important than precise instruction following, prompt in Thai.
Example:
❌ "Write a casual conversation between two Thai teenagers discussing their favorite music."
✅ "เขียนบทสนทนาระหว่างวัยรุ่นไทยสองคนที่กำลังคุยกันเรื่องเพลงที่ชอบ ใช้ภาษาวัยรุ่นที่เป็นธรรมชาติ"
Use English for Instructions, Thai for Content
Prompt in English, but include documents or user questions in Thai for better model understanding.
Example:
"Summarize the main points of this Thai news article:
[ข่าวเศรษฐกิจไทย: ธนาคารแห่งประเทศไทยประกาศมาตรการใหม่เพื่อกระตุ้นเศรษฐกิจ...]"
Bilingual Prompt Templates
For applications that need to work with both Thai and English users:
# System message for bilingual assistant{"role": "system", "content": "You are a bilingual Thai-English assistant. Respond in the same language the user used in their query. If they use Thai, respond in Thai. If they use English, respond in English. For mixed language queries, use the predominant language in your response."}
# Few-shot example to demonstrate bilingual capability{"role": "user", "content": "What is the weather like in Bangkok today?"}{"role": "assistant", "content": "I don't have real-time weather data, but Bangkok typically has a tropical climate. You would need to check a weather service for today's specific forecast in Bangkok."}
{"role": "user", "content": "อาหารไทยยอดนิยมมีอะไรบ้าง"}{"role": "assistant", "content": "อาหารไทยยอดนิยมมีหลากหลาย เช่น ต้มยำกุ้ง ผัดไทย ส้มตำ แกงเขียวหวาน มัสมั่น ผัดกะเพรา ต้มข่าไก่ และข้าวผัด แต่ละภูมิภาคของประเทศไทยก็มีอาหารเด่นๆ ที่แตกต่างกันไปตามวัฒนธรรมท้องถิ่น"}
Conclusion
Effective prompting is an art that improves with practice. Experiment with different approaches to find what works best for your specific use case. Remember that Typhoon models are optimized for Thai language, so leveraging their Thai language capabilities will yield the best results.
For more examples and community-contributed prompts, join our Discord community where users share effective prompting techniques and templates.