Live example

You can play with this example in the Latitude Playground.

Overview

Curious if you need an umbrella before heading out? In this example, you’ll build a Weather Chatbot that fetches real-time weather information whenever users ask. Powered by Latitude prompts and your custom backend code, this bot delivers instant updates on sunshine, rain, or snow—with just a dash of magic.

The prompt

---
provider: openai
model: gpt-4o
temperature: 0.2
tools:
  - get_weather:
      description: Fetch weather data for a given location.
      parameters:
        type: object
        properties:
          location:
            type: string
            description: The name of the location to fetch weather data for.
        required:
          - location
---

You are a helpful assistant that can provide weather information.
If the user asks for the weather in a specific location, use the
`get_weather` tool to fetch the data.

<user>
  {{ question }}
</user>

Breakdown

The main concept to learn in this example is tool calling. This tool fetches weather data from the OpenWeatherMap API using the specified location. It returns the location name, temperature, and a description of the current weather conditions.

Tool calling

The key feature in this prompt is the use of a tool call. This allows the model to trigger a custom backend function to fetch weather data, such as by calling the OpenWeatherMap API. In the Latitude Playground, you can simulate this tool call, as shown in the screenshot above.

---
provider: openai
model: gpt-4o
temperature: 0.2
tools:
  - get_weather:
      description: Fetch weather data for a given location.
      parameters:
        type: object
        properties:
          location:
            type: string
            description: The name of the location to fetch weather data for.
        required:
          - location
---

Resources