Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.adk.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;

/** Shared models for Chat Completions Request and Response. */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
final class ChatCompletionsCommon {

private ChatCompletionsCommon() {}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class ToolCall {
public Integer index; // Applicable for response streaming, null in requests
public String id;
public String type;
public Function function;
public Custom custom;

@JsonProperty("extra_content")
public Map<String, Object> extraContent;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Function {
public String name;
public String arguments; // JSON string
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Custom {
public String input;
public String name;
}
}
316 changes: 316 additions & 0 deletions core/src/main/java/com/google/adk/models/ChatCompletionsRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.adk.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import java.util.List;
import java.util.Map;

/** Data Transfer Objects for Chat Completion API requests. */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
final class ChatCompletionsRequest {

public List<Message> messages;
public String model;
public AudioParam audio;

@JsonProperty("frequency_penalty")
public Double frequencyPenalty;

@JsonProperty("logit_bias")
public Map<String, Double> logitBias;

public Boolean logprobs;

@JsonProperty("max_completion_tokens")
public Integer maxCompletionTokens;

@JsonProperty("max_tokens")
public Integer maxTokens;

public Map<String, String> metadata;
public List<String> modalities;
public Integer n;

@JsonProperty("parallel_tool_calls")
public Boolean parallelToolCalls;

public Prediction prediction;

@JsonProperty("presence_penalty")
public Double presencePenalty;

@JsonProperty("prompt_cache_key")
public String promptCacheKey;

@JsonProperty("prompt_cache_retention")
public String promptCacheRetention;

@JsonProperty("reasoning_effort")
public String reasoningEffort;

@JsonProperty("response_format")
public ResponseFormat responseFormat;

@JsonProperty("safety_identifier")
public String safetyIdentifier;

public Long seed;

@JsonProperty("service_tier")
public String serviceTier;

public Object stop; // Can be String or List<String>
public Boolean store;
public Boolean stream;

@JsonProperty("stream_options")
public StreamOptions streamOptions;

public Double temperature;

@JsonProperty("tool_choice")
public ToolChoice toolChoice;

public List<Tool> tools;

@JsonProperty("top_logprobs")
public Integer topLogprobs;

@JsonProperty("top_p")
public Double topP;

public String user;
public String verbosity;

@JsonProperty("web_search_options")
public WebSearchOptions webSearchOptions;

@JsonProperty("extra_body")
public Map<String, Object> extraBody;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Message {
public String role;
public Object content; // Can be String or List<ContentPart>
public String name;

@JsonProperty("tool_calls")
public List<ChatCompletionsCommon.ToolCall> toolCalls;

@JsonProperty("function_call")
public FunctionCall functionCall; // Deprecated

@JsonProperty("tool_call_id")
public String toolCallId;

public Audio audio; // For assistant messages with audio
public String refusal;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class ContentPart {
public String type;
public String text;
public String refusal;

@JsonProperty("image_url")
public ImageUrl imageUrl;

@JsonProperty("input_audio")
public InputAudio inputAudio;

public File file;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class ImageUrl {
public String url;
public String detail;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class InputAudio {
public String data;
public String format;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class File {
@JsonProperty("file_data")
public String fileData;

@JsonProperty("file_id")
public String fileId;

public String filename;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class FunctionCall {
public String name;
public String arguments;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class AudioParam {
public String format;
public Object voice; // Can be String or Map
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Audio {
public String id;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Prediction {
public String type;
public Object content;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class StreamOptions {
@JsonProperty("include_obfuscation")
public Boolean includeObfuscation;

@JsonProperty("include_usage")
public Boolean includeUsage;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Tool {
public String type;
public FunctionDefinition function;
public CustomTool custom;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class FunctionDefinition {
public String name;
public String description;
public Object parameters; // JSON Schema
public Boolean strict;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class CustomTool {
public String name;
public String description;
public Object format;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class WebSearchOptions {
@JsonProperty("search_context_size")
public String searchContextSize;

@JsonProperty("user_location")
public UserLocation userLocation;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class UserLocation {
public String type;
public ApproximateLocation approximate;
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class ApproximateLocation {
public String city;
public String country;
public String region;
public String timezone;
}

interface ResponseFormat {}

static class ResponseFormatText implements ResponseFormat {
public String type = "text";
}

static class ResponseFormatJsonObject implements ResponseFormat {
public String type = "json_object";
}

static class ResponseFormatJsonSchema implements ResponseFormat {
public String type = "json_schema";

@JsonProperty("json_schema")
public JsonSchema jsonSchema;

static class JsonSchema {
public String name;
public String description;
public Object schema;
public Boolean strict;
}
}

interface ToolChoice {}

static class ToolChoiceMode implements ToolChoice {
private final String mode;

public ToolChoiceMode(String mode) {
this.mode = mode;
}

@JsonValue
public String getMode() {
return mode;
}
}

static class NamedToolChoice implements ToolChoice {
public String type = "function";
public FunctionName function;

static class FunctionName {
public String name;
}
}

static class NamedToolChoiceCustom implements ToolChoice {
public String type = "custom";
public CustomName custom;

static class CustomName {
public String name;
}
}
}
Loading