Class GoogleAiGeminiDecisionModel
java.lang.Object
dev.langchain4j.model.googleai.GoogleAiGeminiDecisionModel
- All Implemented Interfaces:
DecisionModel
A
DecisionModel backed by the Gemini Decisions
API (POST /v1beta/decisions of the Gemini Developer API), which answers yes/no, choice and scale
questions about a text, structured, media or conversation input, with probabilities.
DecisionModel model = GoogleAiGeminiDecisionModel.builder()
.apiKey(System.getenv("GOOGLE_AI_GEMINI_API_KEY"))
.modelName("gemini-decision-1")
.build();
The input can be:
- text,
- named fields: each field is sent as text labeled with its name, or, for a field that holds contents such as an image, as its label followed by the contents,
- a list of
TextContents,ImageContents,AudioContents,VideoContents andPdfFileContents, - a conversation (a list of
ChatMessages), sent as a JSON transcript followed by the images, audio, video and PDF files it refers to, for example as[image 1]or[audio 1].
data: URLs, or as URLs that
Gemini reads itself: publicly accessible https URLs, or the URIs of files uploaded with GeminiFiles.
URLs are passed to Gemini as they are: they are not downloaded by this class, and local files are not read. The
MIME type is taken from the content, or, when the content has none, from a data: URL, or guessed from the
file name of any other URL. The detail level of an image is sent as its resolution;
an image without a detail level, or with AUTO, gets Gemini's default resolution.
Gemini checks the limits of the API, such as the number of questions, options and levels, and the size of the
input, and rejects a request that exceeds them with an InvalidRequestException.
Gemini can block the whole input, for example because it goes against its safety policies. Then no question is
answered: the answer to each question is a RefusalAnswer, see DecisionResponse.isRefused(String).
The reason is in the metadata of the response, see
GoogleAiGeminiDecisionResponseMetadata.blockReason().
- Since:
- 1.24.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionbuilder()The model's default per-call parameters, applied to every request and overridden by any parameters set on the request itself.doDecide(DecisionRequest request) The provider hook behindDecisionModel.decide(DecisionRequest).doDecideAsync(DecisionRequest request) The provider hook behindDecisionModel.decideAsync(DecisionRequest).The listeners notified of every request, response and error of this model.provider()The provider of this model.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DecisionModel
decide, decideAsync, modelName
-
Constructor Details
-
GoogleAiGeminiDecisionModel
public GoogleAiGeminiDecisionModel(GoogleAiGeminiDecisionModel.GoogleAiGeminiDecisionModelBuilder builder)
-
-
Method Details
-
builder
-
doDecide
Description copied from interface:DecisionModelThe provider hook behindDecisionModel.decide(DecisionRequest).- Specified by:
doDecidein interfaceDecisionModel- Parameters:
request- the request, with the default parameters already applied.- Returns:
- one answer per question, keyed by question name.
-
doDecideAsync
Description copied from interface:DecisionModelThe provider hook behindDecisionModel.decideAsync(DecisionRequest). The default returns a failed future: a model that is not genuinely asynchronous does not pretend to be.Implementations return every failure, including mapping and validation errors, as a failed future, and never throw.
- Specified by:
doDecideAsyncin interfaceDecisionModel- Parameters:
request- the request, with the default parameters already applied.- Returns:
- a
CompletableFutureof the answers, keyed by question name.
-
defaultRequestParameters
Description copied from interface:DecisionModelThe model's default per-call parameters, applied to every request and overridden by any parameters set on the request itself. The default isDecisionRequestParameters.EMPTY.- Specified by:
defaultRequestParametersin interfaceDecisionModel
-
listeners
Description copied from interface:DecisionModelThe listeners notified of every request, response and error of this model.- Specified by:
listenersin interfaceDecisionModel
-
provider
Description copied from interface:DecisionModelThe provider of this model.- Specified by:
providerin interfaceDecisionModel
-