Package com.google.genkit.ai
Class Prompt<I>
java.lang.Object
com.google.genkit.ai.Prompt<I>
- Type Parameters:
I- the input type for the prompt
- All Implemented Interfaces:
Action<I,,ModelRequest, Void> Registerable
Prompt is a template that generates ModelRequests from input variables.
Prompts are registered as actions and can be rendered with different input
values to create model requests.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPrompt(String name, String model, String template, Map<String, Object> inputSchema, GenerationConfig config, Class<I> inputClass, BiFunction<ActionContext, I, ModelRequest> renderer) Creates a new Prompt. -
Method Summary
Modifier and TypeMethodDescriptionstatic <I> Prompt.Builder<I> builder()Creates a builder for Prompt.Gets the default generation config.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.getModel()Gets the default model name.getName()Returns the name of the action.Returns the JSON schema for the action's output type.Gets the prompt template.getType()Returns the type of the action.voidRegisters this primitive with the given registry.run(ActionContext ctx, I input) Runs the action with the given input.run(ActionContext ctx, I input, Consumer<Void> 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
-
Prompt
public Prompt(String name, String model, String template, Map<String, Object> inputSchema, GenerationConfig config, Class<I> inputClass, BiFunction<ActionContext, I, ModelRequest> renderer) Creates a new Prompt.- Parameters:
name- the prompt namemodel- the default model nametemplate- the prompt templateinputSchema- the input JSON schemaconfig- the default generation configinputClass- the input class for JSON deserializationrenderer- the function that renders the prompt
-
-
Method Details
-
builder
Creates a builder for Prompt.- Type Parameters:
I- the input type- Returns:
- a new builder
-
getName
Description copied from interface:ActionReturns the name of the action.- Specified by:
getNamein interfaceAction<I,ModelRequest, Void> - Returns:
- the action name
-
getType
Description copied from interface:ActionReturns the type of the action.- Specified by:
getTypein interfaceAction<I,ModelRequest, Void> - Returns:
- the action type
-
getDesc
Description copied from interface:ActionReturns the descriptor of the action containing metadata, schemas, etc.- Specified by:
getDescin interfaceAction<I,ModelRequest, Void> - Returns:
- the action descriptor
-
run
Description copied from interface:ActionRuns the action with the given input.- Specified by:
runin interfaceAction<I,ModelRequest, Void> - Parameters:
ctx- the action contextinput- the input to the action- Returns:
- the output of the action
- Throws:
GenkitException- if the action fails
-
run
public ModelRequest run(ActionContext ctx, I input, Consumer<Void> streamCallback) throws GenkitException Description copied from interface:ActionRuns the action with the given input and streaming callback.- Specified by:
runin interfaceAction<I,ModelRequest, Void> - Parameters:
ctx- the action contextinput- 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<I,ModelRequest, Void> - 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<I,ModelRequest, Void> - 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<I,ModelRequest, Void> - 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<I,ModelRequest, Void> - 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<I,ModelRequest, Void> - 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
-
getModel
Gets the default model name.- Returns:
- the model name
-
getTemplate
Gets the prompt template.- Returns:
- the template
-
getConfig
Gets the default generation config.- Returns:
- the config
-