This app demonstrates the usage of AI-powered function calling and integrates tools to fetch location and weather data. The app utilizes Google's Generative AI API to make function calls based on user queries, and then fetches the respective data using custom functions.
- Location and Weather Retrieval: The app retrieves the user's location and provides weather details based on that location.
- Function Calling: It interacts with custom functions (
getLocationandgetWeather) and handles asynchronous requests for data. - API Integration: Integrates with a Google API to handle generative function calls.
To install and run the project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/snrraptopack/intro-to-ai-tools-and-function-calling.git
-
Navigate to the project directory:
cd intro-to-ai-tools-and-function-calling -
Install dependencies:
npm install
-
Start the server:
npm start
The server will run on port
8001.
- getLocation: This function fetches the current location of the user (in this case, "Tarkwa Ghana").
- getWeather: This function retrieves the weather based on the provided location. It supports locations like
TarkwaandAccra.
When you query the app with a message like "What is the current weather at Tarkwa and Accra?", the app will perform the following steps:
- Send a query to the AI model to extract location and weather information.
- Use the
getLocationfunction to retrieve the location (e.g., Tarkwa or Accra). - Use the
getWeatherfunction to fetch the weather data for the specified location. - Return the weather response, such as:
- Tarkwa: "The weather is sunny and 72°F."
- Accra: "The weather is sunny and 55°F."
{
"location": "Tarkwa",
"weather": {
"temperature": 72,
"unit": "F",
"forecast": "sunny"
}
}