Building a Weather Service With Genkit and AI

Overview

This project demonstrates how to build an AI-enhanced weather service using Genkit, TypeScript, OpenWeatherAPI, and GitHub models. The application showcases modern Node.js patterns and AI integration techniques.

Prerequisites

Before you begin, ensure you have the following:

  1. Node.js installed on your machine
  2. GitHub account and access token for GitHub APIs
  3. An OpenWeatherAPI key for fetching weather data
  4. Genkit CLI installed on your machine

Technical Deep Dive

AI Configuration

The core AI setup is initialized with Genkit and GitHub plugin integration. In this case, we are going to use the OpenAI GPT-3 model:

TypeScript

 

Weather Tool Implementation

The application defines a custom weather tool using Zod schema validation:

TypeScript

 

AI Flow Definition

The service exposes an AI flow that processes weather requests:

TypeScript

 

Express Server Configuration

The application uses the Genkit Express plugin to create an API server:

TypeScript

 

Full Code

The full code for the weather service is as follows:

TypeScript

 

Setup and Development

1. Install dependencies:

Shell

 

2. Configure environment variables:

Shell

 

3. Start the development server:

Shell

 

4. To run the project in debug mode and set breakpoints, you can run:

Shell

 

Then, launch the debugger in your IDE. See the .vscode/launch.json file for the configuration.

5. If you want to build the project, you can run:

Shell

 

6. Run the project in production mode:

Shell

 

Dependencies

Core Dependencies

  • genkit: ^1.0.5
  • @genkit-ai/express: ^1.0.5
  • openweather-api-node: ^3.1.5
  • genkitx-github: ^1.13.1
  • dotenv: ^16.4.7

Development Dependencies

  • tsx: ^4.19.2
  • typescript: ^5.7.2

Project Configuration

  • Uses ES Modules ("type": "module")
  • TypeScript with NodeNext module resolution
  • Output directory: lib
  • Full TypeScript support with type definitions

License

Apache 2.0

Resources

Conclusion

This project demonstrates how to build a weather service using Genkit in Node.js with AI integration. The application showcases modern Node.js patterns and AI integration techniques.

You can find the full code of this example in the GitHub repository.

Happy coding!

Source:
https://dzone.com/articles/building-weather-service-genkit-ai