Class GeminiAdapter
java.lang.Object
com.aispect.core.client.adapter.gemini.GeminiAdapter
- All Implemented Interfaces:
AiClient
adaptation Google Gemini API client implementation.
Responsible for assembly Gemini unique JSON Format requirements (e.g. parts, systemInstruction)and make a request.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(PromptContext ctx, AiClientConfig config) Generates a single response in a blocking manner.streamGenerate(PromptContext ctx, AiClientConfig config) via streaming (Server-Sent Events mode) generates a response.
-
Constructor Details
-
GeminiAdapter
public GeminiAdapter()
-
-
Method Details
-
generate
Description copied from interface:AiClientGenerates a single response in a blocking manner.The client will report to the underlying AI The model sends the prompt context and waits for the complete calculation result. Suitable for non-streaming scenarios where the final result needs to be obtained in one go.
- Specified by:
generatein interfaceAiClient- Parameters:
ctx- Prompt context of the current request, including system prompts, historical messages, etc.config- Configuration parameters requested by the client, such as model name, temperature, maximum Token Count and so on- Returns:
- Full response generated by the model
Response - Throws:
AiSpectException- Thrown when the network request fails, times out, or the model service returns an exception status code
-
streamGenerate
public Stream<Response> streamGenerate(PromptContext ctx, AiClientConfig config) throws AiSpectException Description copied from interface:AiClientvia streaming (Server-Sent Events mode) generates a response.The client will continue to receive partial results generated by the model in the form of a stream. The stream will be terminated when the model has been generated or the connection is interrupted. Ideal for chat applications or long text generation scenarios that require a real-time "typewriter" output experience.
- Specified by:
streamGeneratein interfaceAiClient- Parameters:
ctx- Prompt context of the current request, including system prompts, historical messages, etc.config- Configuration parameters requested by the client (make sure to declare stream=true)- Returns:
- Include
ResponseSequential flow of data blocks, automatically closed when receiving the terminator - Throws:
AiSpectException- Thrown when the streaming request initialization fails or a connection error occurs
-