AS AgentScopeAPI 手册 / API Reference

Builder

public static class Builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:358–646

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

Builder for creating GeminiChatModel instances.

方法摘要Method Summary

方法Method说明Description
public Builder apiKey(String apiKey)
设置API 键。
Sets the API key (for Gemini API).
public Builder baseUrl(String baseUrl)
设置基类 URL。
Sets the custom base URL (for Gemini API).
public Builder modelName(String modelName)
设置模型名称。
Sets the model name.
public Builder streamEnabled(boolean streamEnabled)
设置流已启用。
Sets whether streaming is enabled.
public Builder project(String project)
设置该配置项。
Sets the Google Cloud project ID (for Vertex AI).
public Builder location(String location)
设置该配置项。
Sets the Google Cloud location (for Vertex AI).
public Builder vertexAI(boolean vertexAI)
设置该配置项。
Sets whether to use Vertex AI APIs.
public Builder httpOptions(HttpOptions httpOptions)
设置HTTP 选项用于客户端。
Sets the HTTP options for the client.
public Builder credentials(GoogleCredentials credentials)
设置凭证。
Sets the Google credentials (for Vertex AI).
public Builder clientOptions(ClientOptions clientOptions)
设置客户端选项。
Sets the client options.
public Builder defaultOptions(GenerateOptions defaultOptions)
设置默认选项。
Sets the default generation options.
public Builder formatter(Formatter<Content, GenerateContentResponse, GenerateContentConfig.Builder> formatter)
设置格式化器。
Sets the formatter.
public Builder proxy(ProxyConfig proxyConfig)
设置代理。
Sets the proxy configuration for HTTP traffic.
public Builder contextWindowSize(int contextWindowSize)
构建GeminiChatModel 实例。
Builds the GeminiChatModel instance.
public GeminiChatModel build()
构建并返回最终实例。
Creates and returns an instance.

方法详情Method Detail

apiKey

public Builder apiKey(String apiKey)

设置API 键。

Sets the API key (for Gemini API).

参数Parameters
名称Name类型Type说明Description
apiKeyStringAPI 键(类型 `String`)。the Gemini API key
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:381–384

baseUrl

public Builder baseUrl(String baseUrl)

设置基类 URL。

Sets the custom base URL (for Gemini API).

参数Parameters
名称Name类型Type说明Description
baseUrlString基类 URL(类型 `String`)。the custom Gemini API base URL
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:392–395

modelName

public Builder modelName(String modelName)

设置模型名称。

Sets the model name.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称(默认:"gemini-2.5-flash")。the model name (default: "gemini-2.5-flash")
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:403–406

streamEnabled

public Builder streamEnabled(boolean streamEnabled)

设置流已启用。

Sets whether streaming is enabled.

参数Parameters
名称Name类型Type说明Description
streamEnabledboolean流已启用(类型 `boolean`)。true to enable streaming (default: false)
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:414–417

project

public Builder project(String project)

设置该配置项。

Sets the Google Cloud project ID (for Vertex AI).

参数Parameters
名称Name类型Type说明Description
projectStringproject(类型 `String`)。the project ID
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:425–428

location

public Builder location(String location)

设置该配置项。

Sets the Google Cloud location (for Vertex AI).

参数Parameters
名称Name类型Type说明Description
locationStringlocation(类型 `String`)。the location (e.g., "us-central1")
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:436–439

vertexAI

public Builder vertexAI(boolean vertexAI)

设置该配置项。

Sets whether to use Vertex AI APIs.

参数Parameters
名称Name类型Type说明Description
vertexAIbooleanvertex AI(类型 `boolean`)。true to use Vertex AI, false for Gemini API
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:447–450

httpOptions

public Builder httpOptions(HttpOptions httpOptions)

设置HTTP 选项用于客户端。

Sets the HTTP options for the client.

参数Parameters
名称Name类型Type说明Description
httpOptionsHttpOptionsHTTP 选项。the HTTP options
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:458–461

credentials

public Builder credentials(GoogleCredentials credentials)

设置凭证。

Sets the Google credentials (for Vertex AI).

参数Parameters
名称Name类型Type说明Description
credentialsGoogleCredentials凭证(类型 `GoogleCredentials`)。the Google credentials
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:469–472

clientOptions

public Builder clientOptions(ClientOptions clientOptions)

设置客户端选项。

Sets the client options.

参数Parameters
名称Name类型Type说明Description
clientOptionsClientOptions客户端选项。the client options
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:480–483

defaultOptions

public Builder defaultOptions(GenerateOptions defaultOptions)

设置默认选项。

Sets the default generation options.

参数Parameters
名称Name类型Type说明Description
defaultOptionsGenerateOptions默认选项。the default options
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:491–494

formatter

public Builder formatter(Formatter<Content, GenerateContentResponse, GenerateContentConfig.Builder> formatter)

设置格式化器。

Sets the formatter.

参数Parameters
名称Name类型Type说明Description
formatterFormatter<Content, GenerateContentResponse, GenerateContentConfig.Builder>格式化器到使用。the formatter to use
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:502–507

proxy

public Builder proxy(ProxyConfig proxyConfig)

设置代理。

Sets the proxy configuration for HTTP traffic.

参数Parameters
名称Name类型Type说明Description
proxyConfigProxyConfig代理配置(类型 `ProxyConfig`)。the proxy configuration (see `ProxyConfig`)
返回Returns Builder
返回当前实例,以支持链式调用。this builder
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:541–544

contextWindowSize

public Builder contextWindowSize(int contextWindowSize)

构建GeminiChatModel 实例。

Builds the GeminiChatModel instance.

参数Parameters
名称Name类型Type说明Description
contextWindowSizeint上下文 Window 大小(类型 `int`)。The context window size.
返回Returns Builder
一种新的GeminiChatModel。a new GeminiChatModel
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:558–561

build

public GeminiChatModel build()

构建并返回最终实例。

Creates and returns an instance.

返回Returns GeminiChatModel
返回GeminiChatModel。Returns Gemini chat model.
源码Source io/agentscope/extensions/model/gemini/GeminiChatModel.java:563–584
基于官方固定版本源码静态生成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.