Class GenerationMiddlewarePlugin
java.lang.Object
com.google.genkit.plugins.middleware.GenerationMiddlewarePlugin
- All Implemented Interfaces:
MiddlewarePlugin,Plugin
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:
retry— retry failed model calls with exponential backoff (RetryMiddleware)fallback— fall back to alternate models on failure (FallbackMiddleware)simulateSystemPrompt— rewrite the system message into a user/model exchange (SimulateSystemPromptMiddleware)
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GenerationMiddlewarePlugincreate()Creates the plugin.getName()Returns the unique identifier for the plugin.init()Initializes the plugin.middlewares(Registry registry) Returns the generation middleware this plugin provides.
-
Field Details
-
PLUGIN_NAME
The plugin name.- See Also:
-
-
Constructor Details
-
GenerationMiddlewarePlugin
public GenerationMiddlewarePlugin()
-
-
Method Details
-
create
Creates the plugin.- Returns:
- a new plugin instance
-
getName
Description copied from interface:PluginReturns the unique identifier for the plugin. This name is used for registration and lookup. -
init
Description copied from interface:PluginInitializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides. -
middlewares
Description copied from interface:MiddlewarePluginReturns the generation middleware this plugin provides. Called once duringGenkitinitialization.- Specified by:
middlewaresin interfaceMiddlewarePlugin- 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)
-