Class GenerationMiddlewarePlugin

java.lang.Object
com.google.genkit.plugins.middleware.GenerationMiddlewarePlugin
All Implemented Interfaces:
MiddlewarePlugin, Plugin

public class GenerationMiddlewarePlugin extends Object implements Plugin, MiddlewarePlugin
A plugin that ships a set of ready-to-use, parameterized generation middleware.

This is the Java analog of the JS @genkit-ai/middleware package and the Go plugins/middleware package. Adding it to the Genkit builder registers each middleware into the "middleware" registry bucket, so it appears in the Genkit Dev UI Middleware panel (with a parameters form derived from its configSchema) and can be attached to any generate() call by name.

Provided middleware:

Usage:


 Genkit genkit = Genkit.builder()
     .plugin(OpenAIPlugin.create())
     .plugin(GenerationMiddlewarePlugin.create())
     .build();

 // Attach by name (config optional) from code or the Dev UI:
 genkit.generate(GenerateOptions.builder()
     .model("openai/gpt-4o-mini")
     .prompt("Hello")
     .build());
 
  • Field Details

  • Constructor Details

    • GenerationMiddlewarePlugin

      public GenerationMiddlewarePlugin()
  • Method Details

    • create

      public static GenerationMiddlewarePlugin create()
      Creates the plugin.
      Returns:
      a new plugin instance
    • getName

      public String getName()
      Description copied from interface: Plugin
      Returns the unique identifier for the plugin. This name is used for registration and lookup.
      Specified by:
      getName in interface Plugin
      Returns:
      the plugin name
    • init

      public List<Action<?,?,?>> init()
      Description copied from interface: Plugin
      Initializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.
      Specified by:
      init in interface Plugin
      Returns:
      list of actions provided by this plugin
    • middlewares

      public List<GenerationMiddlewareDesc> middlewares(Registry registry)
      Description copied from interface: MiddlewarePlugin
      Returns the generation middleware this plugin provides. Called once during Genkit initialization.
      Specified by:
      middlewares in interface MiddlewarePlugin
      Parameters:
      registry - the Genkit registry, for middleware that needs to resolve dependencies (e.g. a fallback middleware that runs other models)
      Returns:
      the middleware descriptors to register (may be empty)