Builder
public static class Builder
io/agentscope/extensions/model/openai/OpenAIChatModel.java:219–503配置 API Key、模型名、端点、格式化器、流式开关与上下文窗口。位于 io.agentscope.extensions.model.openai 包。核心成员包括 apiKey、modelName、stream、generateOptions、baseUrl、endpointPath。
Builder for OpenAIChatModel.
The built model internally wraps the configuration so that calls without explicit options use the builder-provided values.
方法摘要Method Summary
方法详情Method Detail
apiKey
public Builder apiKey(String apiKey)
设置API 键。
Sets the API key for OpenAI authentication.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | API 密钥。the API key |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:239–242modelName
public Builder modelName(String modelName)
设置模型名称到使用。
Sets the model name to use.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称(类型 `String`)。the model name (e.g., "gpt-4", "gpt-3.5-turbo") |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:250–253stream
public Builder stream(boolean stream)
设置流。
Sets whether streaming should be enabled.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
stream | boolean | 流(类型 `boolean`)。true to enable streaming, false for non-streaming |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:261–264generateOptions
public Builder generateOptions(GenerateOptions options)
设置该配置项。
Sets the default generation options.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
options | GenerateOptions | 选项(类型 `GenerateOptions`)。the default options to use (null for defaults) |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:272–275baseUrl
public Builder baseUrl(String baseUrl)
设置自定义基类 URL 用于 OpenAI API。
Sets a custom base URL for OpenAI API.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
baseUrl | String | 基类 URL(类型 `String`)。the base URL (null for default) |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:283–286endpointPath
public Builder endpointPath(String endpointPath)
设置自定义端点路径用于 API 请求。
Sets a custom endpoint path for the API request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
endpointPath | String | 端点路径(类型 `String`)。the endpoint path (e.g., "/v1/chat/completions") |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:298–301formatter
public Builder formatter(Formatter<OpenAIMessage, OpenAIResponse, OpenAIRequest> formatter)
设置消息格式化器到使用。
Sets the message formatter to use.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
formatter | Formatter<OpenAIMessage, OpenAIResponse, OpenAIRequest> | 格式化器(类型 `Formatter`)。the formatter (null for default OpenAI formatter) |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:318–322httpTransport
public Builder httpTransport(HttpTransport httpTransport)
设置HTTP 传输层到使用。
Sets the HTTP transport to use.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
httpTransport | HttpTransport | HTTP 传输层(类型 `HttpTransport`)。the HTTP transport (null for default from factory) |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:345–348proxy
public Builder proxy(ProxyConfig proxyConfig)
设置代理。
Sets the proxy configuration for HTTP traffic.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
proxyConfig | ProxyConfig | 代理配置(类型 `ProxyConfig`)。the proxy configuration (see `ProxyConfig`) |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:375–378contextWindowSize
public Builder contextWindowSize(int contextWindowSize)
设置该配置项。
Performs the context window size operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
contextWindowSize | int | 上下文 Window 大小(类型 `int`)。The context window size. |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:380–383nativeStructuredOutput
public Builder nativeStructuredOutput(boolean nativeStructuredOutput)
设置原生结构化输出。
Sets whether this model supports native structured output via response_format.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
nativeStructuredOutput | boolean | 原生结构化输出(类型 `boolean`)。false to disable native structured output |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:397–400nativeStructuredOutputWithTools
public Builder nativeStructuredOutputWithTools(boolean nativeStructuredOutputWithTools)
设置原生结构化输出使用工具。
Sets whether this model correctly handles native structured output (response_format) alongside tool calling.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
nativeStructuredOutputWithTools | boolean | 原生结构化输出使用工具(类型 `boolean`)。false to use fallback when tools are present |
Builderio/agentscope/extensions/model/openai/OpenAIChatModel.java:414–417build
public OpenAIChatModel build()
构建OpenAIChatModel 实例。
Builds the OpenAIChatModel instance.
OpenAIChatModelIllegalArgumentException当if modelName是不设置时抛出 `IllegalArgumentException`。if modelName is not set
io/agentscope/extensions/model/openai/OpenAIChatModel.java:425–467