Package com.google.genkit.ai
Interface Model
- All Superinterfaces:
Action<ModelRequest,,ModelResponse, ModelResponseChunk> Registerable
- All Known Implementing Classes:
AnthropicModel,AwsBedrockModel,CompatOAIModel,GeminiModel,ImagenModel,OllamaModel,OpenAIImageModel,OpenAIModel,TtsModel,VeoModel
Model is the interface for AI model implementations.
Models are registered as actions and can be invoked to generate responses
from prompts.
-
Method Summary
Modifier and TypeMethodDescriptiondefault ActionDescgetDesc()Returns the descriptor of the action containing metadata, schemas, etc.getInfo()Gets information about the model's capabilities.Returns the JSON schema for the action's input type.Returns additional metadata for the action.Returns the JSON schema for the action's output type.default ActionTypegetType()Returns the type of the action.default voidRegisters this primitive with the given registry.run(ActionContext ctx, ModelRequest request) Generates a response from the given request.default ModelResponserun(ActionContext ctx, ModelRequest request, Consumer<ModelResponseChunk> streamCallback) Generates a streaming response from the given request.default 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.default 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.default booleanReturns whether this model supports streaming.
-
Method Details
-
getInfo
ModelInfo getInfo()Gets information about the model's capabilities.- Returns:
- the model info
-
run
Generates a response from the given request.- Specified by:
runin interfaceAction<ModelRequest,ModelResponse, ModelResponseChunk> - Parameters:
ctx- the action contextrequest- the model request- Returns:
- the model response
- Throws:
GenkitException- if generation fails
-
run
default ModelResponse run(ActionContext ctx, ModelRequest request, Consumer<ModelResponseChunk> streamCallback) throws GenkitException Generates a streaming response from the given request.- Specified by:
runin interfaceAction<ModelRequest,ModelResponse, ModelResponseChunk> - Parameters:
ctx- the action contextrequest- the model requeststreamCallback- callback for streaming chunks- Returns:
- the final model response
- Throws:
GenkitException- if generation fails
-
supportsStreaming
default boolean supportsStreaming()Returns whether this model supports streaming.- Returns:
- true if streaming is supported
-
getType
Description copied from interface:ActionReturns the type of the action.- Specified by:
getTypein interfaceAction<ModelRequest,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<ModelRequest,ModelResponse, ModelResponseChunk> - Returns:
- the action descriptor
-
runJson
default 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<ModelRequest,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
default 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<ModelRequest,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<ModelRequest,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<ModelRequest,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<ModelRequest,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
-