Weather Forecast Example
This example helps you understand how to use the Go OpenAI Toolkit for creating and utilizing tools to respond to user requests effectively.
- Geocoding Tool: Transforms an address into geographical coordinates (latitude and longitude).
- Weather Tool: Provides the current weather conditions for a specific set of geographical coordinates.
By combining these tools, the system can handle complex requests. For example, if someone wants to know the weather at a certain address, the system first converts the address to coordinates using the Geocoding Tool, then fetches the weather for those coordinates with the Weather Tool, and finally, generates a user-friendly response.
sequenceDiagram
participant User
participant Runtime
participant LLM
participant weather_tool
participant geocoding_tool
User->>Runtime: What is the weather like is Oslo?
Runtime-->>LLM: Forward question with tools spec
LLM-->>Runtime: Tools to call
Runtime->>geocoding_tool: call with address extracted from question
geocoding_tool->>Runtime: return latitude/longitude of address
Runtime->>weather_tool: call with latitude/longitude
weather_tool->>Runtime: weather data
Runtime-->>LLM: Generate final response
LLM-->>User: Return final response
How It Works
- Geocoding: Utilizes the Google Maps Geocoding API to convert addresses to coordinates.
- Weather Checking: Uses the REST API from the Norwegian Meteorological Institute to get weather information.
Getting Started
-
Prerequisite: You must obtain a Google Maps Geocoding API Key to use the Geocoding Tool.
This api key needs to be set in the environment variable GOOGLE_API_KEY
.
-
Get the source code: Clone emilkje/go-openai-toolkit repository
-
Run the example: Run the example using the following command:
# with make
make run-example
# or directly
go run ./example/cmd/main.go
This setup allows for a flexible and efficient way to process and respond to user inquiries by leveraging specific tools for different parts of a request.