类 GeminiChatModel

java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.core.model.GeminiChatModel
所有已实现的接口:
Model

public class GeminiChatModel extends ChatModelBase
Gemini Chat Model implementation using the official Google GenAI Java SDK.

This implementation provides complete integration with Gemini's Content Generation API, including tool calling and multi-agent conversation support.

Supported Features:

  • Text generation with streaming and non-streaming modes
  • Tool/function calling support
  • Multi-agent conversation with history merging
  • Vision capabilities (images, audio, video)
  • Thinking mode (extended reasoning)
  • 嵌套类概要

    嵌套类
    修饰符和类型
    说明
    static class 
    Builder for creating GeminiChatModel instances.
  • 构造器概要

    构造器
    构造器
    说明
    GeminiChatModel(String apiKey, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder> formatter)
    Creates a new Gemini chat model instance using the default endpoint configuration.
    GeminiChatModel(String apiKey, String baseUrl, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder> formatter)
    Creates a new Gemini chat model instance.
  • 方法概要

    修饰符和类型
    方法
    说明
    Creates a new builder for GeminiChatModel.
    void
    Close the Gemini client.
    protected reactor.core.publisher.Flux<ChatResponse>
    doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
    Stream chat completion responses from Gemini's API.
    Get model name for logging and identification.

    从类继承的方法 io.agentscope.core.model.ChatModelBase

    stream

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 构造器详细资料

    • GeminiChatModel

      public GeminiChatModel(String apiKey, String baseUrl, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder> formatter)
      Creates a new Gemini chat model instance.
      参数:
      apiKey - the API key for authentication (for Gemini API)
      baseUrl - the custom base URL for Gemini API (null for default)
      modelName - the model name to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro")
      streamEnabled - whether streaming should be enabled
      project - the Google Cloud project ID (for Vertex AI)
      location - the Google Cloud location (for Vertex AI, e.g., "us-central1")
      vertexAI - whether to use Vertex AI APIs (null for auto-detection)
      httpOptions - HTTP options for the client
      credentials - Google credentials (for Vertex AI)
      clientOptions - client options for the API client
      defaultOptions - default generation options
      formatter - the message formatter to use (null for default Gemini formatter)
    • GeminiChatModel

      public GeminiChatModel(String apiKey, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder> formatter)
      Creates a new Gemini chat model instance using the default endpoint configuration.

      This overload passes null for baseUrl, allowing the SDK to use its default endpoint behavior for either Gemini API or Vertex AI, depending on the provided configuration.

      参数:
      apiKey - the API key for authentication (for Gemini API)
      modelName - the model name to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro")
      streamEnabled - whether streaming should be enabled
      project - the Google Cloud project ID (for Vertex AI)
      location - the Google Cloud location (for Vertex AI, e.g., "us-central1")
      vertexAI - whether to use Vertex AI APIs (null for auto-detection)
      httpOptions - HTTP options for the client
      credentials - Google credentials (for Vertex AI)
      clientOptions - client options for the API client
      defaultOptions - default generation options
      formatter - the message formatter to use (null for default Gemini formatter)
  • 方法详细资料

    • doStream

      protected reactor.core.publisher.Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
      Stream chat completion responses from Gemini's API.

      This method internally handles message formatting using the configured formatter. When streaming is enabled, it returns incremental responses as they arrive. When streaming is disabled, it returns a single complete response.

      指定者:
      doStream 在类中 ChatModelBase
      参数:
      messages - AgentScope messages to send to the model
      tools - Optional list of tool schemas (null or empty if no tools)
      options - Optional generation options (null to use defaults)
      返回:
      Flux stream of chat responses
    • getModelName

      public String getModelName()
      从接口复制的说明: Model
      Get model name for logging and identification.
      返回:
      model name
    • close

      public void close()
      Close the Gemini client.
    • builder

      public static GeminiChatModel.Builder builder()
      Creates a new builder for GeminiChatModel.
      返回:
      a new Builder instance