Class ChatCompletionsHttpClient
java.lang.Object
com.google.adk.models.chat.ChatCompletionsHttpClient
- All Implemented Interfaces:
ChatCompletionsClient
An OkHttp-based implementation of
ChatCompletionsClient that targets OpenAI-compatible
chat completions endpoints. Both non-streaming responses (single LlmResponse emission)
and streaming Server-Sent Events (SSE) responses (multiple incremental LlmResponse
emissions) are supported.-
Constructor Summary
ConstructorsConstructorDescriptionChatCompletionsHttpClient(com.google.genai.types.HttpOptions httpOptions) Constructs a newChatCompletionsHttpClientthat facilitates API interaction with the standard/chat/completionsREST endpoint. -
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Flowable<LlmResponse> complete(LlmRequest llmRequest, boolean stream) Generates a conversational response from the chat completions endpoint based on the provided messages.
-
Constructor Details
-
ChatCompletionsHttpClient
public ChatCompletionsHttpClient(com.google.genai.types.HttpOptions httpOptions) Constructs a newChatCompletionsHttpClientthat facilitates API interaction with the standard/chat/completionsREST endpoint.All configuration is sourced from the supplied
HttpOptions:HttpOptions.baseUrl()-- required. The base URL of the chat completions endpoint. Thechat/completionspath segments are appended automatically usingHttpUrl, which handles trailing slashes and percent-encoding deterministically. Set viaHttpOptions.builder().baseUrl("https://...").build().HttpOptions.headers()-- optional. Extra HTTP headers to include in outgoing requests. TheContent-Typeheader is set automatically and cannot be overridden. Set viaHttpOptions.builder().headers(Map.of("Authorization", "Bearer ...")).HttpOptions.timeout()-- optional. Per-call timeout in milliseconds. A missing timeout defaults to 5 minutes (DEFAULT_CALL_TIMEOUT). A timeout of0is respected as the explicit caller opt-in to infinite wait. Set viaHttpOptions.builder().timeout(10_000).build().
Example:
HttpOptions options = HttpOptions.builder() .baseUrl("https://example.com/v1/") .headers(ImmutableMap.of("Authorization", "Bearer my-token")) .timeout(30_000) .build(); ChatCompletionsHttpClient client = new ChatCompletionsHttpClient(options);- Parameters:
httpOptions- HTTP configuration. Must not benull, andHttpOptions.baseUrl()must be present and parseable as an HTTP(S) URL.- Throws:
IllegalArgumentException- ifhttpOptions.baseUrl()is missing or is not a valid HTTP(S) URL.
-
-
Method Details
-
complete
public io.reactivex.rxjava3.core.Flowable<LlmResponse> complete(LlmRequest llmRequest, boolean stream) Description copied from interface:ChatCompletionsClientGenerates a conversational response from the chat completions endpoint based on the provided messages. This encapsulates building the payload, sending the request to the completions endpoint, and initiating the handling of complete calls.- Specified by:
completein interfaceChatCompletionsClient- Parameters:
llmRequest- The request containing the model, configuration, and sequence of messages.stream- Whether to request a streaming response.- Returns:
- A
Flowableemitting the discrete (or combined)LlmResponseobjects.
-