0Pricing
Prompt Engineering & LLM Optimization for Developers · บทเรียน

การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ

เรียนรู้วิธีเปิดให้ LLM โต้ตอบกับเครื่องมือและ API ภายนอก โดยสอนให้เรียกใช้ฟังก์ชันเฉพาะตามพรอมต์ของผู้ใช้

การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ เป็นบทเรียน Prompt Engineering & LLM Optimization for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Prompt Engineering & LLM Optimization for Developers และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Prompt Engineering & LLM Optimization for Developers มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

LLMs & External Tools

Large Language Models (LLMs) are amazing at understanding and generating text. However, they typically don't have direct access to:

  • Real-time information: Like today's weather or current stock prices.
  • External actions: Such as sending an email or booking a flight.
  • Complex computations: Beyond simple arithmetic.

This is where Function Calling comes in!

Bridging the Gap with Tools

Function calling allows LLMs to interact with the outside world by letting them 'call' external tools or APIs. It bridges the gap between the LLM's language abilities and real-world actions.

Think of it as giving the LLM a set of specialized gadgets it can recommend using when needed.

How it Works: The LLM's Role

When you use function calling, the LLM doesn't *execute* code itself. Instead, it acts like a smart planner or router:

  • It analyzes your prompt.
  • It identifies if any defined tools could help fulfill your request.
  • If so, it suggests which tool to use and what arguments (inputs) to pass to it.

Your application then takes this suggestion and performs the actual action.

Defining Your Tools (Schema)

Before an LLM can recommend a tool, it needs to know what tools are available. You provide a 'schema' – a description of each function/tool your application can perform.

This schema tells the LLM:

  • The function's name (e.g., get_current_weather).
  • A clear description of what the function does.
  • Its required parameters (inputs) and their types (e.g., location: string).

Example: A Weather Tool Definition

Here's how you might conceptually define a simple weather tool for an LLM. This description helps the LLM understand *when* and *how* to use it.

function get_current_weather(location: string, unit: "celsius" | "fahrenheit" = "fahrenheit") {
  // Gets the current weather for a given location.
  // Returns temperature, conditions, and humidity.
}

The Interaction Flow

Let's trace a typical interaction with function calling:

  1. User Prompt: You ask the LLM a question (e.g., "What's the weather in Paris?").
  2. LLM Suggestion: The LLM sees the weather tool definition and suggests calling get_current_weather(location="Paris").
  3. Your App Action: Your application receives this suggestion, calls a real weather API, and gets the data.
  4. LLM Final Response: Your app sends the weather data back to the LLM, which then generates a natural language response for you.

Step-by-Step Scenario

Imagine you have a get_stock_price tool defined. Here's a flow:

  • User: "What's the current price of Apple stock?"
  • LLM (internally): "Aha! The user wants a stock price. I have a get_stock_price tool that takes a symbol."
  • LLM Output: tool_call: get_stock_price(symbol="AAPL")
  • Your App: Executes the get_stock_price function with "AAPL".
  • Your App: Gets "$175.50" and sends it back to the LLM.
  • LLM: "The current price of Apple (AAPL) stock is $175.50."

Benefits of Function Calling

Function calling dramatically enhances LLM capabilities:

  • Access to Real-time Data: Get up-to-date information that the LLM's training data might not have.
  • Perform Actions: Enable LLMs to trigger real-world processes.
  • Reduce Hallucinations: Ground LLM responses in factual, external data, making them more reliable.
  • Complex Logic: Delegate complex calculations or data retrieval to robust external systems.

Common Use Cases

Function calling is versatile and can be applied to many scenarios:

  • Data Retrieval: Fetching information from databases, APIs, or files.
  • Calculations: Using a calculator tool for precise math.
  • Sending Notifications: Integrating with email or messaging services.
  • Database Interactions: Querying or updating records.
  • Home Automation: Turning on lights or adjusting thermostats.

Quick Check: LLM's Role

You've defined a tool for your LLM. A user asks a question that requires this tool.

Recap: Tools & Smarter LLMs

You've learned about Function Calling, a powerful technique that allows LLMs to interact with external tools and APIs. By defining schemas for your functions, you enable LLMs to act as smart planners, suggesting relevant actions and arguments based on user prompts.

This capability opens up a world of possibilities, making LLM-powered applications more dynamic, factual, and capable of real-world interaction.

คำถามที่พบบ่อย

บทเรียน “การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Prompt Engineering & LLM Optimization for Developers ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Prompt Engineering & LLM Optimization for Developers มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ”

เรียนรู้วิธีเปิดให้ LLM โต้ตอบกับเครื่องมือและ API ภายนอก โดยสอนให้เรียกใช้ฟังก์ชันเฉพาะตามพรอมต์ของผู้ใช้ คุณปฏิบัติ Prompt Engineering & LLM Optimization for Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Prompt Engineering & LLM Optimization for Developers หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Prompt Engineering & LLM Optimization for Developers บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Prompt Engineering & LLM Optimization for Developers นี้ได้ไหม

ได้ บทเรียน Prompt Engineering & LLM Optimization for Developers ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การสร้างเสริมด้วยการค้นคืน (RAG)
  2. การเรียกใช้ฟังก์ชันและการใช้เครื่องมือ
  3. การสร้างเอเจนต์ LLM อย่างง่าย
  4. การสตรีมคำตอบ LLM ไปยังผู้ใช้
← กลับไปที่ Prompt Engineering & LLM Optimization for Developers