genkit_shelf 0.0.1-dev.1 copy "genkit_shelf: ^0.0.1-dev.1" to clipboard
genkit_shelf: ^0.0.1-dev.1 copied to clipboard

Shelf integration for Genkit Dart.

Genkit Shelf #

Shelf integration for Genkit Dart.

Installation #

dependencies:
  genkit_shelf: any

Usage #

Standalone Server #

The easiest way to serve your flows is using startFlowServer:

import 'package:genkit/genkit.dart';
import 'package:genkit_shelf/genkit_shelf.dart';

void main() async {
  final ai = Genkit();

  final flow = ai.defineFlow(
    name: 'myFlow',
    inputType: StringType,
    outputType: StringType,
    fn: (String input, _) async => 'Hello $input',
  );

  await startFlowServer(
    flows: [flow],
    port: 8080,
  );
}

Existing Shelf Application #

You can also integrate Genkit flows into an existing Shelf application using shelfHandler. This allows you to use your own routing, middleware, and server configuration.

import 'package:genkit/genkit.dart';
import 'package:genkit_shelf/genkit_shelf.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_router/shelf_router.dart';

void main() async {
  final ai = Genkit();

  final flow = ai.defineFlow(
    name: 'myFlow',
    inputType: StringType,
    outputType: StringType,
    fn: (String input, _) async => 'Hello $input',
  );

  // Create a Shelf Router
  final router = Router();

  // Mount the flow handler at a specific path
  router.post('/myFlow', shelfHandler(flow));

  // Add other application routes
  router.get('/health', (Request request) => Response.ok('OK'));

  // Start the server
  await io.serve(router.call, 'localhost', 8080);
}
0
likes
0
points
0
downloads

Publisher

verified publishergenkit.dev

Weekly Downloads

Shelf integration for Genkit Dart.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

genkit, shelf, shelf_router

More

Packages that depend on genkit_shelf