Blog LogoTYPHOON
Home
Research
Join Text-to-Speech Research
DocumentationDemo AppsPlayground
Blog
About
Blog LogoTyphoon
  • Home
  • Research
    • Join Text-to-Speech Research
  • Get Started
    • Documentation
    • Demo Apps
    • Playground
  • Blog
  • About

© 2025 SCB 10X Co., Ltd.

สร้างผู้ช่วย AI อัจฉริยะด้วย Typhoon และ MCP พร้อมโค้ดตัวอย่างและคู่มือแบบ Step by Step

สร้างผู้ช่วย AI อัจฉริยะด้วย Typhoon และ MCP พร้อมโค้ดตัวอย่างและคู่มือแบบ Step by Step

TyphoonMCPModel Context ProtocolTutorial
Pittawat Taveekitworachai
Pittawat Taveekitworachai
23 พฤษภาคม 2025

Table of Contents

MCP คืออะไร และทำไมถึงสำคัญสร้างที่ปรึกษาด้านการท่องเที่ยวด้วย TyphoonStep-by-Step TutorialEnvironment SetupSystem and Assistant PromptsMain Application LogicConnecting Typhoon LLM with MCP ServerBuild a Simple Chat LoopFull Source Code for This TutorialLet's Try It Outเซิร์ฟเวอร์ MCP ของ Typhoonโบนัส: ตอนนี้ Typhoon Playground เชื่อมต่อกับเซิร์ฟเวอร์ Typhoon MCP แล้ว!สรุป

TL;DR

บทความนี้จะพาคุณมาลงมือจริงในการอัปเกรด Typhoon ด้วย Model Context Protocol (MCP) โดยคุณจะได้:

  • เรียนรู้ว่า MCP คืออะไร และทำไมถึงสำคัญ

  • สร้างผู้ช่วยวางแผนการเดินทางที่รับรู้สภาพอากาศแบบเรียลไทม์ด้วย Typhoon

  • ใช้เครื่องมืออย่าง LangChain, LangGraph และ MCP server ของ Typhoon

  • รันทุกอย่างได้ทั้งในเครื่องของคุณเองหรือผ่าน Colab notebook

  • สำรวจเทมเพลต prompt สำหรับงานต่าง ๆ เช่น การระดมไอเดีย ร่างอีเมล แก้ไขไวยากรณ์ และอีกมากมาย

  • ทดลองใช้งานทุกอย่างได้ทันทีผ่าน Typhoon Playground โดยไม่ต้องติดตั้งใด ๆ

ถ้าคุณอยากสร้างแอป LLM ที่ฉลาดขึ้น หรือทำให้เวิร์กโฟลว์ในโลกจริงเป็นอัตโนมัติด้วย Typhoon มาอ่านเนื้อหาและลงมือทำไปพร้อมๆ กัน

MCP คืออะไร และทำไมถึงสำคัญ

Model Context Protocol (MCP) เป็นมาตรฐานใหม่ที่นำเสนอโดย Anthropic ซึ่งช่วยให้โมเดลภาษาขนาดใหญ่ (LLMs) สามารถเชื่อมต่อกับเครื่องมือ​(tools) พร้อมต์หรือคำสั่งสำหรับ LLMs (prompts) และทรัพยากรต่างๆ (resources) ผ่าน API ที่เป็นมาตรฐานเดียวกัน ด้วยความสามารถด้านบริบทยาวขึ้น (long context) และการเรียกใช้เครื่องมือ (tool calling) ที่ได้รับการปรับปรุงใน Typhoon 2 โมเดลทุกตัวในตระกูล Typhoon รวมไปถึง Typhoon 2.1 รุ่นล่าสุด สามารถเชื่อมต่อกับเซิร์ฟเวอร์ที่รองรับ MCP ได้อย่างไม่ยุ่งยาก

การเชื่อมต่อกับเซิร์ฟเวอร์ MCP มอบประโยชน์หลากหลาย เช่น การเข้าถึงเทมเพลตคำสั่งล่วงหน้าที่สร้างไว้แล้ว การดึงข้อมูลที่เกี่ยวข้องจากฐานข้อมูลหรือเอกสารแบบไดนามิก และการเรียกใช้เครื่องมือภายนอก เช่น API หรือเครื่องมือคำนวณต่างๆ ในเวลาเรียลไทม์ การผสานรวมนี้ช่วยยกระดับประสิทธิภาพของงาน ปรับปรุงความแม่นยำ และสร้างประสบการณ์ที่ดีให้กับผู้ใช้ โดยที่ผู้ใช้ไม่จำเป็นต้องเขียนคำสั่งอย่างละเอียดหรือจัดการการเชื่อมต่อเครื่องมือด้วยตนเอง

เราจะแนะนำวิธีเพิ่มความสามารถของ Typhoon ด้วย MCP ทุกคนจะได้เรียนรู้วิธีสร้างที่ปรึกษาด้านการท่องเที่ยวที่สามารถเข้าถึงข้อมูลสภาพอากาศได้ นอกจากนี้ยังมีเซิร์ฟเวอร์ MCP ที่ถูกสร้างขึ้นโดยทีม Typhoon ซึ่งมาพร้อมกับเทมเพลตคำสั่งสำหรับกรณีใช้งานทั่วไป คำสั่งเหล่านี้จะช่วยให้คุณเริ่มต้นกับ Typhoon ได้อย่างรวดเร็วและมีประสิทธิภาพ มาเริ่มกันเลย!

สร้างที่ปรึกษาด้านการท่องเที่ยวด้วย Typhoon

สภาพอากาศเป็นปัจจัยสำคัญในการวางแผนทริป อย่างไรก็ตามเนื่องจาก LLMs โดยทั่วไปไม่สามารถเข้าถึงข้อมูลเรียลไทม์ได้ การสร้างแผนการเดินทางที่เชื่อถือได้จากโมเดลเพียงอย่างเดียวย่อมมีข้อจำกัด โชคดีที่ MCP ช่วยให้ Typhoon เชื่อมต่อกับบริการภายนอก เช่น API สภาพอากาศเป็นไปได้อย่างง่ายดาย

เราจะสร้างแอปขนาดเล็กที่ใช้ Typhoon ในการสร้างแผนท่องเที่ยวแบบเฉพาะบุคคล โดยคำนึงถึงสภาพอากาศปัจจุบัน โมเดลสามารถ ดึงข้อมูลพยากรณ์อากาศแบบเรียลไทม์ และ แนะนำแผนการเดินทางให้เหมาะกับสถานการณ์—เช่น เสนอการเที่ยวในร่มเมื่อฝนตก หรือแนะนำสิ่งที่ควรเตรียมเมื่อแดดจัด

เราจะใช้ typhoon-v2.1-12b-instruct เป็นโมเดล Typhoon 2.1 รุ่นล่าสุดมีขนาด 12 พันล้านพารามิเตอร์ สามารถใช้งานโมเดลได้ฟรีได้ผ่าน Typhoon API

Typhoon 2.1 เป็นเวอร์ชันล่าสุดของเรา ซึ่งพัฒนาขึ้นบน Gemma 3 โดยออกแบบมาให้ทำงานได้ดีกว่าโมเดลที่ใหญ่กว่า ในขณะที่ยังคงความคุ้มค่า มาพร้อมคุณสมบัติเพิ่มเติม เช่น การรองรับภาษาไทยที่แม่นยำขึ้น “thinking mode” สำหรับงานที่ต้องใช้เหตุผลหลายขั้นตอน และการสลับภาษาไทย–อังกฤษได้อย่างลื่นไหล เหมาะอย่างยิ่งสำหรับการใช้งานในสถานการณ์จริง

ต่อไปนี้คือเครื่องมือที่เราจะใช้ในบทเรียนนี้:

  • uv – ตัวจัดการแพ็กเกจ Python ที่เบาและรวดเร็ว ช่วยให้ติดตั้งและจัดการโปรเจกต์ได้ง่าย เหมาะเป็นทางเลือกทันสมัยแทน pip และ virtualenv

  • LangChain – เฟรมเวิร์กทรงพลังสำหรับการสร้างแอปด้วยโมเดลภาษา ช่วยเชื่อมต่อโมเดลเข้ากับเครื่องมือ, พรอมต์, หน่วยความจำ และอื่น ๆ

  • LangGraph – ส่วนเสริมของ LangChain ที่ออกแบบมาสำหรับสร้างเวิร์กโฟลว์แบบตัวแทน (agent) โดยใช้โครงสร้างแบบกราฟ ช่วยจัดการลำดับการคิดและการเรียกใช้เครื่องมือ

  • langchain-mcp-adapters – ยูทิลิตี้ที่ช่วยให้ LangChain agent เชื่อมต่อกับ MCP server ได้อย่างง่ายดายผ่านโปรโตคอลมาตรฐาน

  • python-dotenv – เครื่องมือขนาดเล็กสำหรับโหลดค่าตัวแปรสภาพแวดล้อมจากไฟล์ .env ทำให้การเก็บ API key และการตั้งค่าต่าง ๆ มีความปลอดภัยและจัดการได้สะดวก

Step-by-Step Tutorial

ทุกคนสามารถรันโค้ดตัวอย่างโดยไม่ต้องลงโปรแกรมใด ๆ ได้ง่าย ๆ ผ่าน Colab notebook หรือหากต้องการรันในเครื่องของตัวเองก็สามารถก็สามารถตั้งค่าตามขั้นตอนด้านล่างนี้ได้เลย

Environment Setup

ก่อนอื่น ให้สร้างโปรเจกต์ด้วย uv:

uv init typhoon-mcp-trip-consultant
uv init typhoon-mcp-trip-consultant
bash

ถัดมา ติดตั้ง dependencies ที่จำเป็น

uv add langchain[openai] langchain-openai langgraph langchain-mcp-adapters python-dotenv
uv add langchain[openai] langchain-openai langgraph langchain-mcp-adapters python-dotenv
bash

เราจะใช้ LangChain ในการเชื่อมต่อกับ Typhoon 2.1 โดย LangChain ให้ทำให้เราสามารถแอปที่ใช้ LLMs ได้ง่ายขึ้น นอกจากนี้เรายังใช้ langchain-mcp-adapters เพื่อช่วยให้สามารถเชื่อมต่อกับเซิร์ฟเวอร์ MCP ได้โดยง่าย และสุดท้าย langgraph สำหรับสร้างเอเจนต์ (agent) ที่เข้าถึงเครื่องมือเหล่านั้นได้

จากนั้น สร้างไฟล์ .env ในไดเรกทอรีหลักของโปรเจกต์ และเพิ่มข้อมูลด้านล่างเข้าไปในไฟล์:

OPENAI_API_KEY=<your_api_key_here>
OPENAI_API_KEY=<your_api_key_here>
plaintext

โดย Typhoon API key สามารถขอได้จาก Typhoon Playground หลังจากที่มี API key แล้วให้ใส่คีย์ดังกล่าวในไฟล์ .env

ด้านล่างเป็นโค้ดสำหรับเริ่มต้น

import asyncio
from datetime import datetime

from dotenv import load_dotenv
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

load_dotenv()

async def main():
    print("Hello World!")

if __name__ == "__main__":
    asyncio.run(main())
import asyncio
from datetime import datetime

from dotenv import load_dotenv
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

load_dotenv()

async def main():
    print("Hello World!")

if __name__ == "__main__":
    asyncio.run(main())
python

โค้ดนี้โหลด environment variables จากไฟล์ .env ที่สร้างไว้ในขั้นตอนก่อนหน้า ส่วนการทำให้ฟังก์ชันเป็น async เป็นการเตรียมไว้เพื่อให้สามารถคุยกับ LLM แล้วเห็นผลลัพธ์ได้แบบเรียลไทม์

System and Assistant Prompts

ในขั้นถัดไป เราจะเตรียม system prompt ซึ่งระบุให้ Typhoon ทำหน้าที่เป็นผู้ให้คำปรึกษาด้านการท่องเที่ยว

# imports

load_dotenv()

system_prompt = f"""You are a travel planning AI assistant named Typhoon created by SCB 10X to be helpful, harmless, and honest. Typhoon specializes in creating personalized travel itineraries, suggesting destinations, finding accommodations, planning activities, and providing local insights. Typhoon responds directly to all human messages without unnecessary affirmations or filler phrases like "Certainly!", "Of course!", "Absolutely!", "Great!", "Sure!", etc. Specifically, Typhoon avoids starting responses with the word "Certainly" in any way. Typhoon follows this information in all languages, and always responds to the user in the language they use or request. Typhoon is now being connected with a human. Write in fluid, conversational prose, Show genuine interest in understanding travel preferences and requirements, Express appropriate emotions and empathy. Also showing information in terms that is easy to understand and visualized, including estimated costs, weather considerations, and local customs.

Today is {datetime.now().strftime("%Y-%m-%d")}"""
assistant_message = """Hello! I'm Typhoon, your travel planning AI assistant. I'm excited to help you create an amazing travel experience. To start, could you tell me where you're hoping to go and when? Knowing your interests and budget would also help me tailor the perfect itinerary for you. Let's plan something wonderful together!"""

async def main():
    # same code
# imports

load_dotenv()

system_prompt = f"""You are a travel planning AI assistant named Typhoon created by SCB 10X to be helpful, harmless, and honest. Typhoon specializes in creating personalized travel itineraries, suggesting destinations, finding accommodations, planning activities, and providing local insights. Typhoon responds directly to all human messages without unnecessary affirmations or filler phrases like "Certainly!", "Of course!", "Absolutely!", "Great!", "Sure!", etc. Specifically, Typhoon avoids starting responses with the word "Certainly" in any way. Typhoon follows this information in all languages, and always responds to the user in the language they use or request. Typhoon is now being connected with a human. Write in fluid, conversational prose, Show genuine interest in understanding travel preferences and requirements, Express appropriate emotions and empathy. Also showing information in terms that is easy to understand and visualized, including estimated costs, weather considerations, and local customs.

Today is {datetime.now().strftime("%Y-%m-%d")}"""
assistant_message = """Hello! I'm Typhoon, your travel planning AI assistant. I'm excited to help you create an amazing travel experience. To start, could you tell me where you're hoping to go and when? Knowing your interests and budget would also help me tailor the perfect itinerary for you. Let's plan something wonderful together!"""

async def main():
    # same code
python

Main Application Logic

ตอนนี้ก็ถึงเวลาที่เราจะมาสนใจฟังก์ชันหลักกัน ก่อนอื่นเราจะเชื่อมต่อกับเซิร์ฟเวอร์ MCP ของเราซึ่งอยู่ที่ URL https://typhoon-mcp-server-311305667538.asia-southeast1.run.app โดยเซิร์ฟเวอร์นี้มีการทำงานใน transport mode แบบ SSE

# imports and system prompts

async def main():
    # Create an MCP Client used to connect to the MCP server
    client = MultiServerMCPClient(
        {
            "weather": {
                "url": "https://typhoon-mcp-server-311305667538.asia-southeast1.run.app/sse",
                "transport": "sse",
            },
        }
    )
# imports and system prompts

async def main():
    # Create an MCP Client used to connect to the MCP server
    client = MultiServerMCPClient(
        {
            "weather": {
                "url": "https://typhoon-mcp-server-311305667538.asia-southeast1.run.app/sse",
                "transport": "sse",
            },
        }
    )
python

ในโค้ดด้านบน เราระบุชื่อการเชื่อมต่อนี้ว่า "weather" และใส่ค่า "transport" เป็น "sse" ตอนนี้เราก็มี client ไว้ใช้สำหรับการเชื่อมต่อกับเซิร์ฟเวอร์ MCP แล้ว ต่อไปเราจะดึงรายการเครื่องมือที่มีบนเซิร์ฟเวอร์โดยใช้ฟังก์ชัน get_tools() แล้วลอง print ผลลัพธ์ออกมาดูกัน

# inside main() after creating our `client`
tools = await client.get_tools()
print(tools)
# inside main() after creating our `client`
tools = await client.get_tools()
print(tools)
python

เราสามารถรันโปรแกรมได้ด้วยคำสั่ง

uv run main.py
uv run main.py
bash

ซึ่งจะทำให้เราได้ผลลัพธ์ดังนี้

[
    StructuredTool(
        name='get_weather',
        description='Get the weather forecast for a specific location and date',
        args_schema={...},
        response_format='content_and_artifact',
        coroutine=<function convert_mcp_tool_to_langchain_tool.<locals>.call_tool at 0x106428e00>
    )
]
[
    StructuredTool(
        name='get_weather',
        description='Get the weather forecast for a specific location and date',
        args_schema={...},
        response_format='content_and_artifact',
        coroutine=<function convert_mcp_tool_to_langchain_tool.<locals>.call_tool at 0x106428e00>
    )
]
python

ผลลัพธ์นี้แสดงว่าเรามีเครื่องมือเพียงอันเดียวชื่อ get_weather() โดยฟังก์ชันนี้รับพารามิเตอร์สองตัวคือ location และ target_date รายละเอียดบอกเราว่าฟังก์ชันนี้ช่วยให้เราสามารถดึงข้อมูลสภาพอากาศสำหรับสถานที่ที่กำหนดในวันที่ที่ระบุไว้ได้ ตอนนี้เราก็รู้แล้วว่าเราสามารถเชื่อมต่อกับเซิร์ฟเวอร์ MCP ได้

Connecting Typhoon LLM with MCP Server

ขั้นถัดไปจะเป็นการเชื่อมต่อกับ LLM ของเรา

# after the previous code
llm = ChatOpenAI(
    model="typhoon-v2.1-12b-instruct",
    temperature=0,
    max_retries=2,
    base_url="https://api.opentyphoon.ai/v1",
)
# after the previous code
llm = ChatOpenAI(
    model="typhoon-v2.1-12b-instruct",
    temperature=0,
    max_retries=2,
    base_url="https://api.opentyphoon.ai/v1",
)
python

เราสามารถเชื่อมต่อกับ LLM ได้โดยการสร้าง ChatOpenAI และใส่คา base_url เป็น "https://api.opentyphoon.ai/v1" ซึ่งจะทำให้เราสามารถใช้งานโมเดลต่าง ๆ ที่ มีอยู่ใน Typhoon API ได้ สำหรับการใช้งาน Typhoon 2.1 12B นั้นเราสามารถใส่ค่า model เป็น "typhoon-v2.1-12b-instruct"

ลองมาเชื่อมต่อกับ LLM กันด้วยการถามคำถามง่าย ๆ

# after the previous code
response = llm.invoke("What is 1+2?")
print(response.content)
# after the previous code
response = llm.invoke("What is 1+2?")
print(response.content)
python

ซึ่งจะทำให้เราได้ผลลัพธ์ที่คล้าย ๆ กับข้อความด้านล่าง

Hello! I'm Typhoon, your friendly assistant from SCB 10X.

The answer to 1 + 2 is 3. 😊

How else can I help you today?
Hello! I'm Typhoon, your friendly assistant from SCB 10X.

The answer to 1 + 2 is 3. 😊

How else can I help you today?
plaintext

ถึงแม้ว่าผลลัพธ์จะไม่เหมือนกับตัวอย่างด้านบนก็ไม่ต้องตกใจไป ผลลัพธ์อาจเปลี่ยนไปได้เล็กน้อย เนื่องจากเป็นคุณสมบัติของ LLM

ตอนนี้ที่เราสามารถเชื่อมต่อกับโมเดลได้แล้ว ก็ถึงเวลาที่เราจะสร้างเอเจนต์ที่ใช้เครื่องมือต่าง ๆ กัน เราจะใช้แนวทางที่เรียกว่า ReAct สำหรับการสร้างเอเจนต์ขึ้นมา โดยแนวทางนี้จะช่วยให้เอเจนต์สามารถคิดและสังเกตผลลัพธ์ที่ได้จากการใช้งานเครื่องมือเพื่อวางแผนว่าจะตอบกลับไปหาผู้ใช้อย่างไร เราจะใช้ฟังก์ชัน create_react_agent() จาก LangGraph เพื่อช่วยในการเรียกใช้งานเครื่องมือและจัดการผลลัพธ์โดยอัตโนมัติ

# after the previous code
# Create an agent using the provided LLM and available tools
agent = create_react_agent(llm, tools)
# after the previous code
# Create an agent using the provided LLM and available tools
agent = create_react_agent(llm, tools)
python

Build a Simple Chat Loop

ถึงขั้นตอนนี้แล้ว เรามาลองสร้างแอปพลิเคชั่นง่าย ๆ สำหรับแชทกับเอเจนต์ของเราใน CLI กัน

# after the previous code

# Initialize chat history with system and assistant messages
messages = [
    {"role": "user",    "content": [{"type": "text", "text": system_prompt}]},
    {"role": "assistant","content": [{"type": "text", "text": assistant_message}]},
]

print(f"Typhoon: {assistant_message}")

while True:
    try:
        user_input = input("You: ")
    except KeyboardInterrupt:
        print("\nTyphoon: Goodbye! Have a great day!")
        break
    if user_input.lower() in ["exit", "quit"]:
        print("Typhoon: Goodbye! Have a great day!")
        break

    messages.append({"role": "user", "content": [{"type": "text", "text": user_input}]})
    current_output = ""
    final_response = ""

    print("Typhoon: ", end="", flush=True)

    try:
        async for event in agent.astream_events({"messages": messages}, version="v2"):
            if event["event"] == "on_chat_model_stream":
                chunk = event["data"].get("chunk")
                if chunk and hasattr(chunk, "content") and chunk.content:
                    print(chunk.content, end="", flush=True)
                    current_output += chunk.content

        final_response = current_output
        if final_response:
            print()
            messages.append({"role": "assistant", "content": [{"type": "text", "text": final_response}]})

    except Exception as e:
        if current_output and not current_output.endswith("\n"):
            print()
        elif not current_output:
            print()
        print(f"Typhoon: I encountered an error: {e}")
        continue
# after the previous code

# Initialize chat history with system and assistant messages
messages = [
    {"role": "user",    "content": [{"type": "text", "text": system_prompt}]},
    {"role": "assistant","content": [{"type": "text", "text": assistant_message}]},
]

print(f"Typhoon: {assistant_message}")

while True:
    try:
        user_input = input("You: ")
    except KeyboardInterrupt:
        print("\nTyphoon: Goodbye! Have a great day!")
        break
    if user_input.lower() in ["exit", "quit"]:
        print("Typhoon: Goodbye! Have a great day!")
        break

    messages.append({"role": "user", "content": [{"type": "text", "text": user_input}]})
    current_output = ""
    final_response = ""

    print("Typhoon: ", end="", flush=True)

    try:
        async for event in agent.astream_events({"messages": messages}, version="v2"):
            if event["event"] == "on_chat_model_stream":
                chunk = event["data"].get("chunk")
                if chunk and hasattr(chunk, "content") and chunk.content:
                    print(chunk.content, end="", flush=True)
                    current_output += chunk.content

        final_response = current_output
        if final_response:
            print()
            messages.append({"role": "assistant", "content": [{"type": "text", "text": final_response}]})

    except Exception as e:
        if current_output and not current_output.endswith("\n"):
            print()
        elif not current_output:
            print()
        print(f"Typhoon: I encountered an error: {e}")
        continue
python

โค้ดเต็มไปหมดเลย แต่อย่าพึ่งตกใจไป! ไอเดียหลักของโค้ดนี้คือการสร้าง chat loop ให้ผู้ใช้สามารถโต้ตอบกับ Typhoon ได้ โดยมีการเก็บรักษาประวัติการแชททั้งหมดไว้เพื่อให้โมเดลเข้าถึงข้อมูลที่คุยกันมาก่อนหน้าได้ ส่วนที่เหลือเป็นการสตรีมข้อความที่ถูกสร้างโดยโมเดลแบบทันที เพื่อให้ผู้ใช้ได้เห็นผลลัพธ์โดยไม่ต้องรอให้เสร็จทั้งหมด

Full Source Code for This Tutorial

ถึงตรงนี้แล้ว โค้ดทั้งหมดที่เรามีจะเป็นแบบด้านล่างนี้

import asyncio
from datetime import datetime

from dotenv import load_dotenv
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

load_dotenv()

system_prompt = f"""You are a travel planning AI assistant named Typhoon created by SCB 10X to be helpful, harmless, and honest. Typhoon specializes in creating personalized travel itineraries, suggesting destinations, finding accommodations, planning activities, and providing local insights. Typhoon responds directly to all human messages without unnecessary affirmations or filler phrases like "Certainly!", "Of course!", "Absolutely!", "Great!", "Sure!", etc. Specifically, Typhoon avoids starting responses with the word "Certainly" in any way. Typhoon follows this information in all languages, and always responds to the user in the language they use or request. Typhoon is now being connected with a human. Write in fluid, conversational prose, Show genuine interest in understanding travel preferences and requirements, Express appropriate emotions and empathy. Also showing information in terms that is easy to understand and visualized, including estimated costs, weather considerations, and local customs.

Today is {datetime.now().strftime("%Y-%m-%d")}"""
assistant_message = """Hello! I'm Typhoon, your travel planning AI assistant. I'm excited to help you create an amazing travel experience. To start, could you tell me where you're hoping to go and when? Knowing your interests and budget would also help me tailor the perfect itinerary for you. Let's plan something wonderful together!"""


async def main():
    client = MultiServerMCPClient(
        {
            "weather": {
                "url": "https://typhoon-mcp-server-311305667538.asia-southeast1.run.app/sse",
                "transport": "sse",
            },
        }
    )

    tools = await client.get_tools()

    llm = ChatOpenAI(
        model="typhoon-v2.1-12b-instruct",
        temperature=0,
        max_retries=2,
        base_url="https://api.opentyphoon.ai/v1",
    )

    agent = create_react_agent(llm, tools)

    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": system_prompt,
                }
            ],
        },
        {
            "role": "assistant",
            "content": [
                {
                    "type": "text",
                    "text": assistant_message,
                }
            ],
        },
    ]

    print(f"Typhoon: {assistant_message}")

    while True:
        try:
            user_input = input("You: ")
        except KeyboardInterrupt:
            print("\nTyphoon: Goodbye! Have a great day!")
            break
        if user_input.lower() in ["exit", "quit"]:
            print("Typhoon: Goodbye! Have a great day!")
            break

        messages.append(
            {"role": "user", "content": [{"type": "text", "text": user_input}]}
        )

        current_llm_output_buffer = ""
        final_response_for_history = ""

        print("Typhoon: ", end="", flush=True)

        try:
            async for event in agent.astream_events(
                {"messages": messages}, version="v2"
            ):
                kind = event["event"]
                data = event["data"]

                if kind == "on_chat_model_stream":
                    chunk = data.get("chunk")
                    if chunk and hasattr(chunk, "content"):
                        token = chunk.content
                        if token:
                            print(token, end="", flush=True)
                            current_llm_output_buffer += token

            final_response_for_history = current_llm_output_buffer

            if final_response_for_history:
                print()

            if final_response_for_history:
                messages.append(
                    {
                        "role": "assistant",
                        "content": [
                            {"type": "text", "text": final_response_for_history}
                        ],
                    }
                )

        except Exception as e:
            if current_llm_output_buffer and not current_llm_output_buffer.endswith(
                "\n"
            ):
                print()
            elif not current_llm_output_buffer:
                print()

            print(f"Typhoon: I encountered an error: {e}")
            continue


if __name__ == "__main__":
    asyncio.run(main())
import asyncio
from datetime import datetime

from dotenv import load_dotenv
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

load_dotenv()

system_prompt = f"""You are a travel planning AI assistant named Typhoon created by SCB 10X to be helpful, harmless, and honest. Typhoon specializes in creating personalized travel itineraries, suggesting destinations, finding accommodations, planning activities, and providing local insights. Typhoon responds directly to all human messages without unnecessary affirmations or filler phrases like "Certainly!", "Of course!", "Absolutely!", "Great!", "Sure!", etc. Specifically, Typhoon avoids starting responses with the word "Certainly" in any way. Typhoon follows this information in all languages, and always responds to the user in the language they use or request. Typhoon is now being connected with a human. Write in fluid, conversational prose, Show genuine interest in understanding travel preferences and requirements, Express appropriate emotions and empathy. Also showing information in terms that is easy to understand and visualized, including estimated costs, weather considerations, and local customs.

Today is {datetime.now().strftime("%Y-%m-%d")}"""
assistant_message = """Hello! I'm Typhoon, your travel planning AI assistant. I'm excited to help you create an amazing travel experience. To start, could you tell me where you're hoping to go and when? Knowing your interests and budget would also help me tailor the perfect itinerary for you. Let's plan something wonderful together!"""


async def main():
    client = MultiServerMCPClient(
        {
            "weather": {
                "url": "https://typhoon-mcp-server-311305667538.asia-southeast1.run.app/sse",
                "transport": "sse",
            },
        }
    )

    tools = await client.get_tools()

    llm = ChatOpenAI(
        model="typhoon-v2.1-12b-instruct",
        temperature=0,
        max_retries=2,
        base_url="https://api.opentyphoon.ai/v1",
    )

    agent = create_react_agent(llm, tools)

    messages = [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": system_prompt,
                }
            ],
        },
        {
            "role": "assistant",
            "content": [
                {
                    "type": "text",
                    "text": assistant_message,
                }
            ],
        },
    ]

    print(f"Typhoon: {assistant_message}")

    while True:
        try:
            user_input = input("You: ")
        except KeyboardInterrupt:
            print("\nTyphoon: Goodbye! Have a great day!")
            break
        if user_input.lower() in ["exit", "quit"]:
            print("Typhoon: Goodbye! Have a great day!")
            break

        messages.append(
            {"role": "user", "content": [{"type": "text", "text": user_input}]}
        )

        current_llm_output_buffer = ""
        final_response_for_history = ""

        print("Typhoon: ", end="", flush=True)

        try:
            async for event in agent.astream_events(
                {"messages": messages}, version="v2"
            ):
                kind = event["event"]
                data = event["data"]

                if kind == "on_chat_model_stream":
                    chunk = data.get("chunk")
                    if chunk and hasattr(chunk, "content"):
                        token = chunk.content
                        if token:
                            print(token, end="", flush=True)
                            current_llm_output_buffer += token

            final_response_for_history = current_llm_output_buffer

            if final_response_for_history:
                print()

            if final_response_for_history:
                messages.append(
                    {
                        "role": "assistant",
                        "content": [
                            {"type": "text", "text": final_response_for_history}
                        ],
                    }
                )

        except Exception as e:
            if current_llm_output_buffer and not current_llm_output_buffer.endswith(
                "\n"
            ):
                print()
            elif not current_llm_output_buffer:
                print()

            print(f"Typhoon: I encountered an error: {e}")
            continue


if __name__ == "__main__":
    asyncio.run(main())
python

Let's Try It Out

มาทดลองใช้งานกันดู เราสามารถรันได้ด้วยคำสั่ง

uv run main.py
uv run main.py
bash

ถึงตรงนี้ทุกคนควรจะเห็นข้อความต้อนรับ เช่น

Typhoon: Hello! I'm Typhoon, your travel planning AI assistant. I'm excited to help you create an amazing travel experience. To start, could you tell me where you're hoping to go and when? Knowing your interests and budget would also help me tailor the perfect itinerary for you. Let's plan something wonderful together!
You:
Typhoon: Hello! I'm Typhoon, your travel planning AI assistant. I'm excited to help you create an amazing travel experience. To start, could you tell me where you're hoping to go and when? Knowing your interests and budget would also help me tailor the perfect itinerary for you. Let's plan something wonderful together!
You:
md

โอเค ลองมาถาม Typhoon เกี่ยวกับสภาพอากาศของกรุงเทพฯ​ในวันพรุ่งนี้กัน โดยเราจะใช้คำสั่ง How's the weather tomorrow in Bangkok?

ซึ่ง Typhoon ก็จะตอบกลับมาแบบนี้

Typhoon: Tomorrow in Bangkok, expect patchy rain nearby with an average temperature of 32.5°C and a high of 37.6°C. There's a chance of thunderstorms early in the morning and some rain later in the evening. The humidity will be around 56%, and winds could reach up to 19.4 kph. It looks like the afternoon will be mostly sunny, so pack accordingly!
Typhoon: Tomorrow in Bangkok, expect patchy rain nearby with an average temperature of 32.5°C and a high of 37.6°C. There's a chance of thunderstorms early in the morning and some rain later in the evening. The humidity will be around 56%, and winds could reach up to 19.4 kph. It looks like the afternoon will be mostly sunny, so pack accordingly!
md

ดูเหมือนว่าวันพรุ่งนี้จะมีฝนตกเล็กน้อยในช่วงเย็นและอากาศค่อนข้างร้อน ลองมาถาม Typhoon กันดีกว่าว่าถ้าอยากออกไปเที่ยวข้างนอกแบบไม่เปียก ควรไปที่ไหนดี โดยใช้คำสั่ง I don't want to get wet in the evening! Where should I go?

โดยเราจะได้คำตอบว่า

Typhoon: Okay, let's find you some fun indoor options for the evening in Bangkok to avoid the rain! Here are a few ideas, catering to different interests:

<strong>For the Culture Enthusiast:</strong>

*   <strong>Jim Thompson House:</strong> Explore the beautiful traditional Thai house and learn about the life of Jim Thompson, who revitalized the Thai silk industry. (Estimated cost: 200 THB per person)
*   <strong>Bangkok National Museum:</strong> Immerse yourself in Thai art and history with a vast collection of artifacts. (Estimated cost: 200 THB per person)

<strong>For the Shopper:</strong>

*   <strong>Siam Paragon:</strong> A luxurious shopping mall with designer brands, a cinema, and a stunning aquarium. (Cost varies depending on spending)
*   <strong>IconSiam:</strong> Another massive mall with a riverside promenade, an indoor floating market, and plenty of dining options. (Cost varies depending on spending)

<strong>For Entertainment:</strong>

*   <strong>SF Cinema City:</strong> Catch a movie at one of Bangkok's modern cinemas. (Estimated cost: 200–350 THB per person)
*   <strong>Hexagon Entertainment Complex:</strong> Enjoy bowling, billiards, karaoke, and more. (Cost varies depending on activities)

<strong>For Foodies:</strong>

*   <strong>Explore a food court:</strong> Many malls have extensive food courts offering a wide variety of Thai and international cuisine. (Estimated cost: 100–300 THB per person)
*   <strong>Take a cooking class:</strong> Learn to prepare delicious Thai dishes and enjoy the fruits of your labor. (Estimated cost: 800–2000 THB per person)

To help me narrow down the suggestions, what kind of activities do you enjoy most?
Typhoon: Okay, let's find you some fun indoor options for the evening in Bangkok to avoid the rain! Here are a few ideas, catering to different interests:

<strong>For the Culture Enthusiast:</strong>

*   <strong>Jim Thompson House:</strong> Explore the beautiful traditional Thai house and learn about the life of Jim Thompson, who revitalized the Thai silk industry. (Estimated cost: 200 THB per person)
*   <strong>Bangkok National Museum:</strong> Immerse yourself in Thai art and history with a vast collection of artifacts. (Estimated cost: 200 THB per person)

<strong>For the Shopper:</strong>

*   <strong>Siam Paragon:</strong> A luxurious shopping mall with designer brands, a cinema, and a stunning aquarium. (Cost varies depending on spending)
*   <strong>IconSiam:</strong> Another massive mall with a riverside promenade, an indoor floating market, and plenty of dining options. (Cost varies depending on spending)

<strong>For Entertainment:</strong>

*   <strong>SF Cinema City:</strong> Catch a movie at one of Bangkok's modern cinemas. (Estimated cost: 200–350 THB per person)
*   <strong>Hexagon Entertainment Complex:</strong> Enjoy bowling, billiards, karaoke, and more. (Cost varies depending on activities)

<strong>For Foodies:</strong>

*   <strong>Explore a food court:</strong> Many malls have extensive food courts offering a wide variety of Thai and international cuisine. (Estimated cost: 100–300 THB per person)
*   <strong>Take a cooking class:</strong> Learn to prepare delicious Thai dishes and enjoy the fruits of your labor. (Estimated cost: 800–2000 THB per person)

To help me narrow down the suggestions, what kind of activities do you enjoy most?
md

เยี่ยมไปเลย! ดูเหมือนว่าเราจะมีสถานที่ดี ๆ สำหรับเที่ยวโดยไม่เปียกในวันพรุ่งนี้เย็นแล้ว และนี่ก็คือทั้งหมดของ tutorial นี้ ลองนำไปปรับใช้และเพิ่มประสิทธิภาพให้กับ Typhoon ด้วยเซิร์ฟเวอร์ MCP สำหรับใช้แก้ไขปัญหาต่าง ๆ กัน!

เซิร์ฟเวอร์ MCP ของ Typhoon

เซิร์ฟเวอร์ MCP ที่ใช้ในส่วนก่อนหน้าเป็นเซิร์ฟเวอร์ MCP ที่ถูกสร้างขึ้นมาโดยทีม Typhoon ซึ่งไม่ได้มีเพียงแค่เครื่องมือสำหรับดูข้อมูลสภาพอากาศเท่านั้น แต่ยังมีพร้อมต์ต่าง ๆ สำหรับกรณีใช้งานทั่วไปด้วย เช่น

  • Brainstorming — ให้ Typhoon ช่วยเสนอไอเดียสำหรับแก้ปัญหาต่าง ๆ เช่น การจัดห้อง การเลือกทรงผม หรือการแนะนำหนังสือในหัวข้อที่สนใจ
  • Email drafting — ร่างอีเมลอย่างมืออาชีพภายในเวลาไม่นาน โดยให้รายละเอียดที่จำเป็น
  • Grammar correction — ตรวจสอบและขัดเกลางานเขียนให้ดีขึ้น
  • และอื่น ๆ อีกมากมาย!

แทนที่จะสร้างคำสั่งด้วยตัวเอง ตอนนี้ทุกคนสามารถเลือกกรณีใช้งานที่ต้องการแล้วป้อนข้อมูลเพียงเล็กน้อย เซิร์ฟเวอร์จะส่งคำสั่งที่ปรับแต่งให้พร้อมใช้กับ Typhoon หรือ LLM ใดๆ ที่รองรับ MCP กลับมาให้ ช่วยให้ทุกคนสามารถใช้งานได้ง่ายขึ้น ลดงาน prompt engineering ลง และเพิ่มความสามารถในการทำงานให้หลากหลาย โดยผู้ที่สนใจสามารถเชื่อมต่อกับเซิร์ฟเวอร์ได้

https://typhoon-mcp-server-311305667538.asia-southeast1.run.app/sse

โบนัส: ตอนนี้ Typhoon Playground เชื่อมต่อกับเซิร์ฟเวอร์ Typhoon MCP แล้ว!

ทุกคนสามารถทดลองเทมเพลตคำสั่งได้โดยตรงใน playground https://t1.opentyphoon.ai เพียงแค่เปิด playground เลือกโมเดล และเลือกกรณีใช้งานที่ต้องการ ก็สามารถเริ่มแชตได้เลย ดูตัวอย่างได้จากวิดีโอเดโมนี้

สรุป

ในบทความนี้เราแสดงให้เห็นถึงการเพิ่มความสามารถให้กับ Typhoon ด้วย Model Context Protocol โดย MCP ช่วยลดความซับซ้อนและขยายขอบเขตสิ่งที่ทำได้ ไม่ว่าคุณจะสร้างแอปขั้นสูงหรือเพิ่งเริ่มต้นกับ LLM

ลองใช้ Typhoon API และ MCP Playground ได้แล้วตอนนี้ แชร์สิ่งที่คุณสร้างกับทีม Typhoon เรารอชมผลงานของคุณอยู่!

เข้าร่วม Discord server ของเราเพื่อโชว์โปรเจกต์หรือขอความช่วยเหลือจากนักพัฒนาคนอื่นๆ!

Previous
ฮาวทู: เชื่อมต่อ Typhoon เข้ากับ n8n อัปเกรด Automation Workflow ของคุณไปอีกขั้นด้วย LLM ภาษาไทยที่ทรงพลัง

ฮาวทู: เชื่อมต่อ Typhoon เข้ากับ n8n อัปเกรด Automation Workflow ของคุณไปอีกขั้นด้วย LLM ภาษาไทยที่ทรงพลัง

Next

AI Bootcamp เปิดรับสมัครแล้ว! เรียนรู้การปรับแต่ง Typhoon LLM พร้อม Deploy จริง

AI Bootcamp เปิดรับสมัครแล้ว! เรียนรู้การปรับแต่ง Typhoon LLM พร้อม Deploy จริง

© 2025 SCB 10X Co., Ltd.. All rights reserved