0Pricing
Prompt Engineering & LLM Optimization for Developers · Lezione

Chiamate di funzione e uso degli strumenti

Impari ad abilitare gli LLM a interagire con strumenti e API esterni, insegnando loro a chiamare funzioni specifiche in base ai prompt degli utenti.

Chiamate di funzione e uso degli strumenti è una lezione Prompt Engineering & LLM Optimization for Developers gratuita su CoddyKit. Questa è la lezione 2 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Prompt Engineering & LLM Optimization for Developers, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Prompt Engineering & LLM Optimization for Developers include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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.

Domande Frequenti

La lezione «Chiamate di funzione e uso degli strumenti» è gratuita?

Sì — il testo completo di «Chiamate di funzione e uso degli strumenti» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Prompt Engineering & LLM Optimization for Developers, passa a CoddyKit PRO. Il corso Prompt Engineering & LLM Optimization for Developers include 4 lezioni in totale.

Cosa imparerò in «Chiamate di funzione e uso degli strumenti»?

Impari ad abilitare gli LLM a interagire con strumenti e API esterni, insegnando loro a chiamare funzioni specifiche in base ai prompt degli utenti. Eserciti Prompt Engineering & LLM Optimization for Developers con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Prompt Engineering & LLM Optimization for Developers?

Non è richiesta alcuna esperienza precedente. Prompt Engineering & LLM Optimization for Developers su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 2 di 4.

Quanto tempo richiede la lezione «Chiamate di funzione e uso degli strumenti»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Prompt Engineering & LLM Optimization for Developers?

Sì. Ogni lezione Prompt Engineering & LLM Optimization for Developers include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Generazione aumentata dal recupero (RAG)
  2. Chiamate di funzione e uso degli strumenti
  3. Creazione di semplici agenti LLM
  4. Streaming delle risposte LLM agli utenti
← Torna a Prompt Engineering & LLM Optimization for Developers