SDK examples
Run a prompt with tools
Learn how to run a prompt with tools using the Latitude SDK
Was this page helpful?
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Learn how to run a prompt with tools using the Latitude SDK
---
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 }}?
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()
import asyncio
import os
from typing import Any
from devtools import pprint
from latitude_sdk import (
ApiError,
FinishedResult,
Latitude,
LatitudeOptions,
OnToolCallDetails,
RunPromptOptions,
StreamEvent,
)
async def get_weather(arguments: dict[str, Any], details: OnToolCallDetails) -> str:
pprint(details)
# Simulate a call to a weather API
return "2°C"
async def on_event(event: StreamEvent):
print(event, "\n" * 2)
async def on_finished(result: FinishedResult):
print(result, "\n" * 2)
async def on_error(error: ApiError):
print(error, "\n" * 2)
async def run():
api_key = os.getenv("LATITUDE_API_KEY")
sdk_options = LatitudeOptions(
project_id=int(os.getenv("PROJECT_ID")),
version_uuid="live",
)
sdk = Latitude(api_key, sdk_options)
result = await sdk.prompts.run(
"run-prompt-with-tools/example",
RunPromptOptions(
parameters={
"location": "Boston",
},
tools={"get_weather": get_weather},
on_event=on_event,
on_finished=on_finished,
on_error=on_error,
stream=True,
),
)
if result:
print(result.response.text, "\n" * 2)
asyncio.run(run())
Was this page helpful?