Prompt

In this example, we define a tool to get the weather. How you obtain the weather is up to you—you might call a third-party service or something within your own system. Once you have the weather information, you return the response to the LLM, and it finishes processing the prompt with that data. You can read more about tool calling here.

---
provider: Latitude
model: gpt-4o-mini
tools:
  - get_weather:
      description: Gets the weather temperature from a given location.
      parameters:
        type: object
        additionalProperties: false
        required: ['location']
        properties:
          location:
            type: string
            description: Name of the location
---

What should I wear for the weather in {{ location }}?

Code

When calling a tool, you can process the data using the arguments your users provide and return a response.

import { Latitude } from '@latitude-data/sdk'

// You can type the tools you are using
type Tools = { get_weather: { location: string } }

async function run() {
  const sdk = new Latitude(process.env.LATITUDE_API_KEY, {
    projectId: Number(process.env.PROJECT_ID),
    versionUuid: 'live',
  })

  const response = await sdk.prompts.run<Tools>(
    'run-prompt-with-tools/example',
    {
      parameters: { location: 'Boston' },
      tools: {
        get_weather: async ({ location }) => {
          return { temperature: `2°C for ${location}` }
        },
      },
    },
  )

  console.log('RESPONSE', JSON.stringify(response, null, 2))
}

run()