AS AgentScopeAPI 手册 / API Reference

GeminiChatModel

public class GeminiChatModel extends ChatModelBase
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:64–647

Gemini 聊天模型,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.gemini 包,继承自 ChatModelBase。核心成员包括 doStream、doStream0、getModelName、close、builder、GeminiChatModel。

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)

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Builder类class
构建器,用于构建并配置目标实例。
Builder for creating GeminiChatModel instances.

构造器摘要Constructor Summary

构造器Constructor说明Description
public GeminiChatModel(String apiKey, String baseUrl, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, HttpOptions httpOptions, GoogleCredentials credentials, ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<Content, GenerateContentResponse, GenerateContentConfig.Builder> formatter)
初始化 `GeminiChatModel` 实例。
Creates a new Gemini chat model instance.
public GeminiChatModel(String apiKey, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, HttpOptions httpOptions, GoogleCredentials credentials, ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<Content, GenerateContentResponse, GenerateContentConfig.Builder> formatter)
初始化 `GeminiChatModel` 实例。
Creates a new Gemini chat model instance using the default endpoint configuration.

方法摘要Method Summary

方法Method说明Description
protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
以流式方式执行并返回结果。
Stream chat completion responses from Gemini's API.
protected Flux<ChatResponse> doStream0(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
以流式方式执行并返回结果。
Performs the do stream 0 operation.
public String getModelName()
获取模型名称。
Returns the model name.
public void close()
关闭连接并释放相关资源。
Close the Gemini client.
public static Builder builder()
static
创建新的构建器用于 GeminiChatModel。
Creates a new builder for GeminiChatModel.

构造器详情Constructor Detail

GeminiChatModel

public GeminiChatModel(String apiKey, String baseUrl, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, HttpOptions httpOptions, GoogleCredentials credentials, ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<Content, GenerateContentResponse, GenerateContentConfig.Builder> formatter)

初始化 GeminiChatModel 实例。

Creates a new Gemini chat model instance.

参数Parameters
名称Name类型Type说明Description
apiKeyStringAPI 键(类型 `String`)。the API key for authentication (for Gemini API)
baseUrlString基类 URL(类型 `String`)。the custom base URL for Gemini API (null for default)
modelNameString模型名称(类型 `String`)。the model name to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro")
streamEnabledboolean流已启用(类型 `boolean`)。whether streaming should be enabled
projectStringproject(类型 `String`)。the Google Cloud project ID (for Vertex AI)
locationStringlocation(类型 `String`)。the Google Cloud location (for Vertex AI, e.g., "us-central1")
vertexAIBooleanvertex AI(类型 `Boolean`)。whether to use Vertex AI APIs (null for auto-detection)
httpOptionsHttpOptions用于客户端的HTTP 选项。HTTP options for the client
credentialsGoogleCredentials凭证(类型 `GoogleCredentials`)。Google credentials (for Vertex AI)
clientOptionsClientOptions用于API 客户端的客户端选项。client options for the API client
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。default generation options
formatterFormatter<Content, GenerateContentResponse, GenerateContentConfig.Builder>格式化器(类型 `Formatter`)。the message formatter to use (null for default Gemini formatter)
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:101–158

GeminiChatModel

public GeminiChatModel(String apiKey, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, HttpOptions httpOptions, GoogleCredentials credentials, ClientOptions clientOptions, GenerateOptions defaultOptions, Formatter<Content, GenerateContentResponse, GenerateContentConfig.Builder> formatter)

初始化 GeminiChatModel 实例。

Creates a new Gemini chat model instance using the default endpoint configuration.

参数Parameters
名称Name类型Type说明Description
apiKeyStringAPI 键(类型 `String`)。the API key for authentication (for Gemini API)
modelNameString模型名称(类型 `String`)。the model name to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro")
streamEnabledboolean流已启用(类型 `boolean`)。whether streaming should be enabled
projectStringproject(类型 `String`)。the Google Cloud project ID (for Vertex AI)
locationStringlocation(类型 `String`)。the Google Cloud location (for Vertex AI, e.g., "us-central1")
vertexAIBooleanvertex AI(类型 `Boolean`)。whether to use Vertex AI APIs (null for auto-detection)
httpOptionsHttpOptions用于客户端的HTTP 选项。HTTP options for the client
credentialsGoogleCredentials凭证(类型 `GoogleCredentials`)。Google credentials (for Vertex AI)
clientOptionsClientOptions用于API 客户端的客户端选项。client options for the API client
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。default generation options
formatterFormatter<Content, GenerateContentResponse, GenerateContentConfig.Builder>格式化器(类型 `Formatter`)。the message formatter to use (null for default Gemini formatter)
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:182–207

方法详情Method Detail

doStream

protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)

以流式方式执行并返回结果。

Stream chat completion responses from Gemini's API.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息列表(类型 `List`)。AgentScope messages to send to the model
toolsList<ToolSchema>工具列表(类型 `List`)。Optional list of tool schemas (null or empty if no tools)
optionsGenerateOptions选项(类型 `GenerateOptions`)。Optional generation options (null to use defaults)
返回Returns Flux<ChatResponse>
返回Flux。Flux stream of chat responses
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:233–238

doStream0

protected Flux<ChatResponse> doStream0(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)

以流式方式执行并返回结果。

Performs the do stream 0 operation.

参数Parameters
名称Name类型Type说明Description
messagesList<Msg>消息列表(类型 `List`)。The messages.
toolsList<ToolSchema>工具列表(类型 `List`)。The tools.
optionsGenerateOptions选项(类型 `GenerateOptions`)。The options.
返回Returns Flux<ChatResponse>
返回Flux。Returns flux.
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:240–326

getModelName

public String getModelName()

获取模型名称。

Returns the model name.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:328–331

close

public void close()

关闭连接并释放相关资源。

Close the Gemini client.

源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:336–344

builder

public static Builder builder()
static

创建新的构建器用于 GeminiChatModel。

Creates a new builder for GeminiChatModel.

返回Returns Builder
一种新的构建器实例。a new Builder instance
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:351–353

嵌套类详情Nested Class Detail

Builder

public static class Builder

构建器,用于构建并配置目标实例。位于 io.agentscope.extensions.model.gemini 包。核心成员包括 apiKey、baseUrl、modelName、streamEnabled、project、location。

Builder for creating GeminiChatModel instances.

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.