Package com.google.genkit.ai
Class GenerateAction
java.lang.Object
com.google.genkit.ai.GenerateAction
- All Implemented Interfaces:
Action<GenerateAction.GenerateActionOptions,,ModelResponse, ModelResponseChunk> Registerable
public class GenerateAction
extends Object
implements Action<GenerateAction.GenerateActionOptions,ModelResponse,ModelResponseChunk>
GenerateAction is a utility action that provides a unified interface for
generating content from AI models. It's registered at /util/generate and is
used by the Dev UI.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classOptions for the generate utility action. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GenerateActionDefines and registers the generate utility action.getDesc()Returns the descriptor of the action containing metadata, schemas, etc.Returns the JSON schema for the action's input type.Returns additional metadata for the action.getName()Returns the name of the action.Returns the JSON schema for the action's output type.getType()Returns the type of the action.voidRegisters this primitive with the given registry.run(ActionContext ctx, GenerateAction.GenerateActionOptions options) Runs the action with the given input.run(ActionContext ctx, GenerateAction.GenerateActionOptions options, Consumer<ModelResponseChunk> streamCallback) Runs the action with the given input and streaming callback.com.fasterxml.jackson.databind.JsonNoderunJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns JSON output.ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) Runs the action with JSON input and returns the result with telemetry information.
-
Constructor Details
-
GenerateAction
-
-
Method Details
-
define
Defines and registers the generate utility action.- Parameters:
registry- the registry to register with- Returns:
- the generate action
-
getName
Description copied from interface:ActionReturns the name of the action.- Specified by:
getNamein interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Returns:
- the action name
-
getType
Description copied from interface:ActionReturns the type of the action.- Specified by:
getTypein interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Returns:
- the action type
-
getDesc
Description copied from interface:ActionReturns the descriptor of the action containing metadata, schemas, etc.- Specified by:
getDescin interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Returns:
- the action descriptor
-
run
public ModelResponse run(ActionContext ctx, GenerateAction.GenerateActionOptions options) throws GenkitException Description copied from interface:ActionRuns the action with the given input.- Specified by:
runin interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Parameters:
ctx- the action contextoptions- the input to the action- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
run
public ModelResponse run(ActionContext ctx, GenerateAction.GenerateActionOptions options, Consumer<ModelResponseChunk> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with the given input and streaming callback.- Specified by:
runin interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Parameters:
ctx- the action contextoptions- the input to the actionstreamCallback- callback for receiving streaming chunks, may be null- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
runJson
public com.fasterxml.jackson.databind.JsonNode runJson(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns JSON output.- Specified by:
runJsonin interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the JSON output
- Throws:
GenkitException- if the action fails
-
runJsonWithTelemetry
public ActionRunResult<com.fasterxml.jackson.databind.JsonNode> runJsonWithTelemetry(ActionContext ctx, com.fasterxml.jackson.databind.JsonNode input, Consumer<com.fasterxml.jackson.databind.JsonNode> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with JSON input and returns the result with telemetry information.- Specified by:
runJsonWithTelemetryin interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Parameters:
ctx- the action contextinput- the JSON inputstreamCallback- callback for receiving streaming JSON chunks, may be null- Returns:
- the action result including telemetry data
- Throws:
GenkitException- if the action fails
-
getInputSchema
Description copied from interface:ActionReturns the JSON schema for the action's input type.- Specified by:
getInputSchemain interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Returns:
- the input schema as a map, or null if not defined
-
getOutputSchema
Description copied from interface:ActionReturns the JSON schema for the action's output type.- Specified by:
getOutputSchemain interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Returns:
- the output schema as a map, or null if not defined
-
getMetadata
Description copied from interface:ActionReturns additional metadata for the action.- Specified by:
getMetadatain interfaceAction<GenerateAction.GenerateActionOptions,ModelResponse, ModelResponseChunk> - Returns:
- the metadata map
-
register
Description copied from interface:RegisterableRegisters this primitive with the given registry.- Specified by:
registerin interfaceRegisterable- Parameters:
registry- the registry to register with
-