Documentation
¶
Overview ¶
Package ark implements chat model for ark runtime.
Index ¶
- Constants
- Variables
- func GetArkRequestID(msg *schema.Message) string
- func GetCacheExpiration(msg *schema.Message) (expireAtSec int64, ok bool)
- func GetContextID(msg *schema.Message) (string, bool)deprecated
- func GetFPS(part *schema.ChatMessageVideoURL) *float64
- func GetImageSize(part *schema.ChatMessageImageURL) (string, bool)
- func GetInputImageSize(part *schema.MessageInputImage) (string, bool)
- func GetInputVideoFPS(part *schema.MessageInputVideo) *float64
- func GetModelName(msg *schema.Message) (string, bool)
- func GetOutputImageSize(part *schema.MessageOutputImage) (string, bool)
- func GetOutputVideoFPS(part *schema.MessageOutputVideo) *float64
- func GetReasoningContent(msg *schema.Message) (string, bool)
- func GetResponseID(msg *schema.Message) (string, bool)
- func GetServiceTier(msg *schema.Message) (string, bool)
- func InvalidateMessageCaches(messages []*schema.Message) error
- func SetFPS(part *schema.ChatMessageVideoURL, fps float64)
- func SetImageSize(part *schema.ChatMessageImageURL, size string)
- func SetInputVideoFPS(part *schema.MessageInputVideo, fps float64)
- func SetPartial(msg *schema.Message)
- func WithCache(cache *CacheOption) model.Option
- func WithCustomHeader(m map[string]string) model.Option
- func WithEnableReasoningContentPassback(enable bool) model.Option
- func WithEnableToolWebSearch(toolWebSearch *ToolWebSearch) model.Option
- func WithMaxCompletionTokens(maxCompletionTokens int) model.Option
- func WithMaxToolCalls(n int64) model.Option
- func WithPrefixCache(contextID string) model.Optiondeprecated
- func WithReasoningEffort(effort arkModel.ReasoningEffort) model.Option
- func WithThinking(thinking *arkModel.Thinking) model.Option
- type APIType
- type BatchChatConfig
- type CacheConfig
- type CacheInfo
- type CacheOption
- type ChatModel
- func (cm *ChatModel) BindForcedTools(tools []*schema.ToolInfo) (err error)
- func (cm *ChatModel) BindTools(tools []*schema.ToolInfo) (err error)
- func (cm *ChatModel) CreatePrefixCache(ctx context.Context, prefix []*schema.Message, ttl int, opts ...fmodel.Option) (info *CacheInfo, err error)
- func (cm *ChatModel) CreateSessionCache(ctx context.Context, prefix []*schema.Message, ttl int, ...) (info *CacheInfo, err error)
- func (cm *ChatModel) Generate(ctx context.Context, in []*schema.Message, opts ...fmodel.Option) (outMsg *schema.Message, err error)
- func (cm *ChatModel) GetType() string
- func (cm *ChatModel) IsCallbacksEnabled() bool
- func (cm *ChatModel) Stream(ctx context.Context, in []*schema.Message, opts ...fmodel.Option) (outStream *schema.StreamReader[*schema.Message], err error)
- func (cm *ChatModel) WithTools(tools []*schema.ToolInfo) (fmodel.ToolCallingChatModel, error)
- type ChatModelConfig
- type ImageGenerationConfig
- type ImageGenerationModel
- func (im *ImageGenerationModel) Generate(ctx context.Context, in []*schema.Message, opts ...einoModel.Option) (outMsg *schema.Message, err error)
- func (im *ImageGenerationModel) Stream(ctx context.Context, in []*schema.Message, opts ...einoModel.Option) (outStream *schema.StreamReader[*schema.Message], err error)
- type ImageResponseFormat
- type ReasoningEffort
- type ResponseFormat
- type ResponsesAPIChatModel
- func (cm *ResponsesAPIChatModel) CreatePrefixCache(ctx context.Context, prefix []*schema.Message, ttl int, opts ...model.Option) (info *CacheInfo, err error)
- func (cm *ResponsesAPIChatModel) Generate(ctx context.Context, input []*schema.Message, opts ...model.Option) (outMsg *schema.Message, err error)
- func (cm *ResponsesAPIChatModel) GetType() string
- func (cm *ResponsesAPIChatModel) IsCallbacksEnabled() bool
- func (cm *ResponsesAPIChatModel) Stream(ctx context.Context, input []*schema.Message, opts ...model.Option) (outStream *schema.StreamReader[*schema.Message], err error)
- func (cm *ResponsesAPIChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
- type ResponsesAPIConfig
- type SequentialImageGeneration
- type SessionCacheConfig
- type Source
- type Thinking
- type ThinkingType
- type ToolWebSearch
- type UserLocation
Constants ¶
const ( SourceOfToutiao = "toutiao" SourceOfDouyin = "douyin" SourceOfMoji = "moji" )
const (
ImageSizeKey = "seedream-image-size"
)
Variables ¶
var (
ErrEmptyResponse = errors.New("empty response received from model")
)
Functions ¶
func GetArkRequestID ¶
func GetCacheExpiration ¶
GetCacheExpiration returns the cache expiration time in seconds. Only available for ResponsesAPI responses.
func GetContextID
deprecated
func GetFPS ¶
func GetFPS(part *schema.ChatMessageVideoURL) *float64
func GetImageSize ¶
func GetImageSize(part *schema.ChatMessageImageURL) (string, bool)
func GetInputImageSize ¶
func GetInputImageSize(part *schema.MessageInputImage) (string, bool)
func GetInputVideoFPS ¶
func GetInputVideoFPS(part *schema.MessageInputVideo) *float64
func GetOutputImageSize ¶
func GetOutputImageSize(part *schema.MessageOutputImage) (string, bool)
func GetOutputVideoFPS ¶
func GetOutputVideoFPS(part *schema.MessageOutputVideo) *float64
func GetResponseID ¶
GetResponseID returns the response ID from the message. Available only for ResponsesAPI responses.
func InvalidateMessageCaches ¶
InvalidateMessageCaches disables caching for the specified messages. When a message is modified, ARK invalidates caches for that message and all subsequent ones. Call this to mark those message caches as invalid.
func SetFPS ¶
func SetFPS(part *schema.ChatMessageVideoURL, fps float64)
func SetImageSize ¶
func SetImageSize(part *schema.ChatMessageImageURL, size string)
func SetInputVideoFPS ¶
func SetInputVideoFPS(part *schema.MessageInputVideo, fps float64)
func SetPartial ¶
SetPartial marks the message as a partial message to enable continuation (prefill) mode. By pre-filling part of the assistant role's content, it guides and controls the model to continue generating from existing text fragments and maintain consistency in role-play scenarios. To use this, set the role of the last message in the input list to assistant and call SetPartial on it. The model will then continue writing based on the message's content. Only available for ResponsesAPI.
func WithCache ¶
func WithCache(cache *CacheOption) model.Option
WithCache is an option to configure model caching.
func WithCustomHeader ¶
WithCustomHeader sets custom headers for a single request the headers will override all the headers given in ChatModelConfig.CustomHeader
func WithEnableReasoningContentPassback ¶
WithEnableReasoningContentPassback controls whether reasoning content is passed back to the model in multi-turn conversations. This option is only supported for the ResponsesAPIChatModel. See ResponsesAPIConfig.EnableReasoningContentPassback.
func WithEnableToolWebSearch ¶
func WithEnableToolWebSearch(toolWebSearch *ToolWebSearch) model.Option
WithEnableToolWebSearch enables the web search tool. This option is only supported for the ResponsesAPIChatModel. Web Search is a basic internet search tool that can obtain real-time public network information (such as news, products, weather, etc.) for your large model through the Responses API. This tool can solve core issues such as data timeliness, knowledge gaps, and information synchronization, and you do not need to develop your own search engine or maintain data resources. Note: This option is only effective for the Responses API. For more details, see https://www.volcengine.com/docs/82379/1756990?lang=zh
func WithMaxCompletionTokens ¶
WithMaxCompletionTokens is used to set the max completion tokens for the request.
func WithMaxToolCalls ¶
WithMaxToolCalls sets the maximum number of tool-calling rounds. This option is only supported for the ResponsesAPIChatModel. The value must be in the range [1, 10]. After this limit is reached, the model is prompted to stop making further tool calls and generate a response. Note: This is a best-effort parameter, and the actual number of calls may be affected by model performance and tool results. The default value for the Web Search tool is 3. For more details, see https://www.volcengine.com/docs/82379/1569618?lang=zh
func WithPrefixCache
deprecated
Deprecated: use WithCache instead. WithPrefixCache creates an option to specify a context ID for the request. The context ID is typically obtained from a previous call to CreatePrefixCache.
When this option is provided, the model will use the cached prefix context associated with this ID, allowing you to avoid resending the same context messages in each request, which improves efficiency and reduces token usage.
Note: it is unavailable for doubao models of version 1.6 and above.
func WithReasoningEffort ¶
func WithReasoningEffort(effort arkModel.ReasoningEffort) model.Option
Types ¶
type APIType ¶
type APIType string
const ( // ContextAPI is defined from https://www.volcengine.com/docs/82379/1528789 ContextAPI APIType = "context_api" // ResponsesAPI is defined from https://www.volcengine.com/docs/82379/1569618 // Deprecated: Use NewResponsesAPIChatModel to create a model for the ResponsesAPIChatModel. ResponsesAPI APIType = "responses_api" )
type BatchChatConfig ¶
type BatchChatConfig struct {
// EnableBatchChat specifies whether to use the batch chat completion API. Only applies to non-streaming scenarios.
// For authentication details, see: https://www.volcengine.com/docs/82379/1399517?lang=en#01826852
EnableBatchChat bool `json:"enable_batch_chat,omitempty"`
// BatchChatTimeout specifies the timeout for the batch chat completion API. When using batch chat model must set a timeout period.
// Model will keep retrying until the timeout or the execution succeeds. It is using context timeout to implement the retry time limit.
// Attention: BatchChatAsyncRetryTimeout is different from the http client timeout which controls the timeout for a single HTTP request.
// Required. Recommend to set a longer timeout period.
BatchChatAsyncRetryTimeout time.Duration `json:"batch_chat_async_retry_timeout,omitempty"`
// BatchMaxParallel specifies the maximum number of parallel requests to send to the chat completion API.
// Optional. Default: 3000.
BatchMaxParallel *int `json:"batch_max_parallel,omitempty"`
}
type CacheConfig ¶
type CacheConfig struct {
// APIType controls which API the cache uses to make calls.
// Note that if the type is ResponsesAPI,
// the following configuration will not be available (ARK may support it in the future):
// `Region`, `AccessKey`, `SecretKey`, `Stop`, `FrequencyPenalty`, `LogitBias`, `PresencePenalty`,
// `LogProbs`, `TopLogProbs`.
// It can be overridden by [WithCache].
// Optional. Default: ContextAPI.
//
// Deprecated: This field defaults to ContextAPI. To use the ResponsesAPI, use NewResponsesAPIChatModel to create a ResponsesAPIChatModel instead of setting APIType to ResponsesAPI.
APIType *APIType `json:"api_type,omitempty"`
// SessionCache is the configuration of ResponsesAPI session cache.
// It can be overridden by [WithCache].
// Optional.
SessionCache *SessionCacheConfig `json:"session_cache,omitempty"`
}
type CacheInfo ¶
type CacheInfo struct {
// ContextID return by ContextAPI, it's specifies the id of prefix that can be used with [WithCache.ContextID] option.
ContextID string
// ResponseID return by ResponsesAPI, it's specifies the id of prefix that can be used with [WithCache.HeadPreviousResponseID] option.
ResponseID string
// Usage specifies the token usage of prefix
Usage schema.TokenUsage
}
type CacheOption ¶
type CacheOption struct {
// APIType specifies the API type for caching.
// Deprecated: This field defaults to ContextAPI and will be removed in a future version.
// To use the ResponsesAPI, please use NewResponsesAPIChatModel to create a ResponsesAPIChatModel.
APIType APIType
// ContextID is the unique identifier returned by ContextAPI.
// Note: This field is only applicable when using ContextAPI.
// Important: ContextID will not be compatible with response ID from ResponsesAPI in future releases.
// For prefix caching with ResponsesAPI, use HeadPreviousResponseID instead.
// For session caching with ResponsesAPI, use SessionCache instead.
// Optional.
ContextID *string
// HeadPreviousResponseID is a response ID from a previous ResponsesAPI call.
// This ID links the current request to a previous conversation context, enabling
// features like conversation continuation and prefix caching.
// The referenced response must be cached before use.
// Only applicable for ResponsesAPI.
// Optional.
HeadPreviousResponseID *string
// SessionCache is the configuration of ResponsesAPI session cache.
// Optional.
SessionCache *SessionCacheConfig
}
type ChatModel ¶
type ChatModel struct {
// contains filtered or unexported fields
}
func NewChatModel ¶
func NewChatModel(_ context.Context, config *ChatModelConfig) (*ChatModel, error)
func (*ChatModel) BindForcedTools ¶
func (*ChatModel) CreatePrefixCache ¶
func (cm *ChatModel) CreatePrefixCache(ctx context.Context, prefix []*schema.Message, ttl int, opts ...fmodel.Option) (info *CacheInfo, err error)
CreatePrefixCache creates a prefix context on the server side. In each subsequent turn of conversation, use WithCache to pass in the ContextID. The server will input the prefix cached context and this turn of input into the model for processing. This improves efficiency by reducing token usage and request size.
Parameters:
- ctx: The context for the request
- prefix: Initial messages to be cached as prefix context
- ttl: Time-to-live in seconds for the cached prefix, default: 86400
Returns:
- info: Information about the created prefix cache, including the context ID and token usage
- err: Any error encountered during the operation
Note:
- It is unavailable for doubao models of version 1.6 and above.
func (*ChatModel) CreateSessionCache ¶
func (cm *ChatModel) CreateSessionCache(ctx context.Context, prefix []*schema.Message, ttl int, truncation *model.TruncationStrategy) (info *CacheInfo, err error)
CreateSessionCache creates an initial session context on the server side. It returns an initial context ID. In each subsequent turn of conversation, use WithCache to pass in the ContextID. The server will input all cached context and this turn of input into the model for processing. This turn of conversation will also be automatically cached. Suitable for use in multi-turn conversation scenarios. Note that it does not apply to concurrent requests.
Parameters:
- ctx: The context for the request
- prefix: Initial messages to be cached as prefix context
- ttl: Time-to-live in seconds for the cached prefix, default: 86400
- truncation: Truncation strategy, default: nil
Returns:
- info: Information about the created session cache, including the context ID and token usage
- err: Any error encountered during the operation
ref: https://www.volcengine.com/docs/82379/1396491?redirect=1#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B
Note:
- It is unavailable for doubao models of version 1.6 and above.
- Only supports calling by ContextAPI.
func (*ChatModel) IsCallbacksEnabled ¶
type ChatModelConfig ¶
type ChatModelConfig struct {
// Timeout specifies the maximum duration to wait for API responses
// If HTTPClient is set, Timeout will not be used.
// Optional. Default: 10 minutes
Timeout *time.Duration `json:"timeout"`
// HTTPClient specifies the client to send HTTP requests.
// If HTTPClient is set, Timeout will not be used.
// Optional. Default &http.Client{Timeout: Timeout}
HTTPClient *http.Client `json:"http_client"`
// RetryTimes specifies the number of retry attempts for failed API calls
// Optional. Default: 2
RetryTimes *int `json:"retry_times"`
// BaseURL specifies the base URL for Ark service
// Optional. Default: "https://ark.cn-beijing.volces.com/api/v3"
BaseURL string `json:"base_url"`
// Region specifies the region where Ark service is located
// Optional. Default: "cn-beijing"
Region string `json:"region"`
// The following three fields are about authentication - either APIKey or AccessKey/SecretKey pair is required
// For authentication details, see: https://www.volcengine.com/docs/82379/1298459
// APIKey takes precedence if both are provided
APIKey string `json:"api_key"`
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
// Model specifies the ID of endpoint on ark platform
// Required
Model string `json:"model"`
// MaxTokens limits the maximum number of output tokens in the Chat Completion API. See https://www.volcengine.com/docs/82379/1494384.
// In Responses API, corresponds to `max_output_tokens`, representing both the model output and reasoning output. See https://www.volcengine.com/docs/82379/1569618.
// Optional. In chat completion, default: 4096, in Responses API, no default.
MaxTokens *int `json:"max_tokens,omitempty"`
// MaxCompletionTokens specifies the maximum tokens in the Chat Completion API,
// representing both the model output and reasoning output. See https://www.volcengine.com/docs/82379/1569618.
// Range: 0 to 65,536 tokens. Exceeding the maximum threshold will result in an error.
// Note: In chat completion, MaxCompletionTokens and MaxTokens cannot both be set, in Responses API, this field is ignored; use MaxTokens.
// Optional.
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"`
// Temperature specifies what sampling temperature to use
// Generally recommend altering this or TopP but not both
// Range: 0.0 to 1.0. Higher values make output more random
// Optional. Default: 1.0
Temperature *float32 `json:"temperature,omitempty"`
// TopP controls diversity via nucleus sampling
// Generally recommend altering this or Temperature but not both
// Range: 0.0 to 1.0. Lower values make output more focused
// Optional. Default: 0.7
TopP *float32 `json:"top_p,omitempty"`
// Stop sequences where the API will stop generating further tokens
// Optional. Example: []string{"\n", "User:"}
Stop []string `json:"stop,omitempty"`
// FrequencyPenalty prevents repetition by penalizing tokens based on frequency
// Range: -2.0 to 2.0. Positive values decrease likelihood of repetition
// Optional. Default: 0
FrequencyPenalty *float32 `json:"frequency_penalty,omitempty"`
// LogitBias modifies likelihood of specific tokens appearing in completion
// Optional. Map token IDs to bias values from -100 to 100
LogitBias map[string]int `json:"logit_bias,omitempty"`
// PresencePenalty prevents repetition by penalizing tokens based on presence
// Range: -2.0 to 2.0. Positive values increase likelihood of new topics
// Optional. Default: 0
PresencePenalty *float32 `json:"presence_penalty,omitempty"`
// CustomHeader the http header passed to model when requesting model
CustomHeader map[string]string `json:"custom_header"`
// LogProbs specifies whether to return log probabilities of the output tokens.
LogProbs bool `json:"log_probs"`
// TopLogProbs specifies the number of most likely tokens to return at each token position, each with an associated log probability.
TopLogProbs int `json:"top_log_probs"`
// ResponseFormat specifies the format that the model must output.
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
// Thinking controls whether the model is set to activate the deep thinking mode.
// It is set to be enabled by default.
Thinking *model.Thinking `json:"thinking,omitempty"`
// ServiceTier specifies whether to use the TPM guarantee package. The effective target has purchased the inference access point for the guarantee package.
ServiceTier *string `json:"service_tier"`
// ReasoningEffort specifies the reasoning effort of the model.
// Optional.
ReasoningEffort *model.ReasoningEffort `json:"reasoning_effort,omitempty"`
// BatchChat ark batch chat config
// Optional.
BatchChat *BatchChatConfig `json:"batch_chat,omitempty"`
Cache *CacheConfig `json:"cache,omitempty"`
}
type ImageGenerationConfig ¶
type ImageGenerationConfig struct {
// For authentication, APIKey is required as the image generation API only supports API Key authentication.
// For authentication details, see: https://www.volcengine.com/docs/82379/1298459
// Required
APIKey string `json:"api_key"`
// Model specifies the ID of endpoint on ark platform
// Required
Model string `json:"model"`
// Timeout specifies the maximum duration to wait for API responses
// If HTTPClient is set, Timeout will not be used.
// Optional. Default: 10 minutes
Timeout *time.Duration `json:"timeout"`
// HTTPClient specifies the client to send HTTP requests.
// If HTTPClient is set, Timeout will not be used.
// Optional. Default &http.Client{Timeout: Timeout}
HTTPClient *http.Client `json:"http_client"`
// RetryTimes specifies the number of retry attempts for failed API calls
// Optional. Default: 2
RetryTimes *int `json:"retry_times"`
// BaseURL specifies the base URL for Ark service
// Optional. Default: "https://ark.cn-beijing.volces.com/api/v3"
BaseURL string `json:"base_url"`
// Region specifies the region where Ark service is located
// Optional. Default: "cn-beijing"
Region string `json:"region"`
// Size specifies the dimensions of the generated image.
// It can be a resolution keyword (e.g., "1K", "2K", "4K") or a custom resolution
// in "{width}x{height}" format (e.g., "1920x1080").
// When using custom resolutions, the total pixels must be between 1280x720 and 4096x4096,
// and the aspect ratio (width/height) must be between 1/16 and 16.
// Optional. Defaults to "2048x2048".
Size string `json:"size"`
// SequentialImageGeneration determines if the model should generate a sequence of images.
// Possible values:
// - "auto": The model decides whether to generate multiple images based on the prompt.
// - "disabled": Only a single image is generated.
// Optional. Defaults to "disabled".
SequentialImageGeneration SequentialImageGeneration `json:"sequential_image_generation"`
// SequentialImageGenerationOption sets the maximum number of images to generate when
// SequentialImageGeneration is set to "auto".
// The value must be between 1 and 15.
// Optional. Defaults to 15.
SequentialImageGenerationOption *model.SequentialImageGenerationOptions `json:"sequential_image_generation_option"`
// ResponseFormat specifies how the generated image data is returned.
// Possible values:
// - "url": A temporary URL to download the image (valid for 24 hours).
// - "b64_json": The image data encoded as a Base64 string in the response.
// Optional. Defaults to "url".
ResponseFormat ImageResponseFormat `json:"response_format"`
// DisableWatermark, if set to true, removes the "AI Generated" watermark
// from the bottom-right corner of the image.
// Optional. Defaults to false.
DisableWatermark bool `json:"disable_watermark"`
}
type ImageGenerationModel ¶
type ImageGenerationModel struct {
// contains filtered or unexported fields
}
func NewImageGenerationModel ¶
func NewImageGenerationModel(_ context.Context, config *ImageGenerationConfig) (*ImageGenerationModel, error)
type ImageResponseFormat ¶
type ImageResponseFormat string
const ( ImageResponseFormatURL ImageResponseFormat = "url" ImageResponseFormatB64 ImageResponseFormat = "b64_json" )
type ReasoningEffort ¶
type ReasoningEffort = arkModel.ReasoningEffort
type ResponseFormat ¶
type ResponseFormat struct {
Type model.ResponseFormatType `json:"type"`
JSONSchema *model.ResponseFormatJSONSchemaJSONSchemaParam `json:"json_schema,omitempty"`
}
type ResponsesAPIChatModel ¶
type ResponsesAPIChatModel struct {
// contains filtered or unexported fields
}
func NewResponsesAPIChatModel ¶
func NewResponsesAPIChatModel(_ context.Context, config *ResponsesAPIConfig) (*ResponsesAPIChatModel, error)
func (*ResponsesAPIChatModel) CreatePrefixCache ¶
func (cm *ResponsesAPIChatModel) CreatePrefixCache(ctx context.Context, prefix []*schema.Message, ttl int, opts ...model.Option) (info *CacheInfo, err error)
CreatePrefixCache establishes a server-side cache for a prefix context, which is ideal for storing initial information like system prompts, user roles, or background details.
Once the cache is created, you can reuse it in subsequent conversational turns by passing the returned ResponseID with the WithCache option. The server will then automatically combine the cached prefix context with the new input before processing it with the model.
This approach is particularly beneficial for applications with repetitive or standardized opening prompts, as it reduces token consumption, minimizes redundant computations, and lowers overall usage costs.
Note:
- The number of input tokens needs to be greater than or equal to 1024; otherwise, an error will be reported.
- The stream parameter cannot be set to true.
- When creating a prefix cache, in the returned usage, total_tokens=input_tokens, and output_tokens is always 0.
- It is unavailable for doubao models of version 1.6 and above.
Parameters:
- ctx: The context for the request.
- prefix: The initial messages to be cached, such as roles and backgrounds.
- ttl: Time-to-live in seconds for the cached prefix, default: 86400.
Returns:
- info: Information about the created prefix cache, including the response id and token usage.
- err: Any error encountered during the operation.
func (*ResponsesAPIChatModel) GetType ¶
func (cm *ResponsesAPIChatModel) GetType() string
func (*ResponsesAPIChatModel) IsCallbacksEnabled ¶
func (cm *ResponsesAPIChatModel) IsCallbacksEnabled() bool
func (*ResponsesAPIChatModel) WithTools ¶
func (cm *ResponsesAPIChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
type ResponsesAPIConfig ¶
type ResponsesAPIConfig struct {
// Timeout specifies the timeout for the HTTP client making requests to the ResponsesAPI.
// If HTTPClient is set, Timeout will not be used.
// Optional. Default: 10 minutes
Timeout *time.Duration `json:"timeout"`
// HTTPClient specifies the client to send HTTP requests.
// If HTTPClient is set, Timeout will not be used.
// Optional. Default &http.Client{Timeout: Timeout}
HTTPClient *http.Client `json:"http_client"`
// RetryTimes specifies the number of retry attempts for failed API calls
// Optional. Default: 2
RetryTimes *int `json:"retry_times"`
// BaseURL specifies the base URL for Ark service
// Optional. Default: "https://ark.cn-beijing.volces.com/api/v3"
BaseURL string `json:"base_url"`
// Region specifies the region where Ark service is located
// Optional. Default: "cn-beijing"
Region string `json:"region"`
// The following three fields are about authentication - either APIKey or AccessKey/SecretKey pair is required
// For authentication details, see: https://www.volcengine.com/docs/82379/1298459
// APIKey takes precedence if both are provided
APIKey string `json:"api_key"`
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
// Model specifies the ID of endpoint on ark platform
// Required
Model string `json:"model"`
// MaxOutputTokens specifies the maximum number of tokens for model output, including both model responses and thought chain content.
// Optional.
MaxOutputTokens *int `json:"max_output_tokens,omitempty"`
// Temperature specifies what sampling temperature to use
// Generally recommend altering this or TopP but not both
// Range: 0.0 to 2.0. Higher values make output more random
// Optional. Default: 1.0
Temperature *float32 `json:"temperature,omitempty"`
// TopP controls diversity via nucleus sampling
// Generally recommend altering this or Temperature but not both
// Range: 0.0 to 1.0. Lower values make output more focused
// Optional. Default: 0.7
TopP *float32 `json:"top_p,omitempty"`
// CustomHeader the http header passed to model when requesting model
// Optional.
CustomHeader map[string]string `json:"custom_header"`
// ResponseFormat specifies the format that the model must output.
// Optional.
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
// Thinking controls whether the model is set to activate the deep thinking mode.
// It is set to be enabled by default.
// Optional.
Thinking *Thinking `json:"thinking,omitempty"`
// ServiceTier specifies whether to use the TPM guarantee package. The effective target has purchased the inference access point for the guarantee package.
// Optional.
ServiceTier *string `json:"service_tier"`
// ReasoningEffort specifies the reasoning effort of the model.
// Optional.
ReasoningEffort *ReasoningEffort `json:"reasoning_effort,omitempty"`
// SessionCache is the configuration of ResponsesAPI session cache.
// It can be overridden by [WithCache].
// Optional.
SessionCache *SessionCacheConfig `json:"session_cache,omitempty"`
// EnableToolWebSearch enables the web search tool.
// Web Search is a basic internet search tool that can obtain real-time public network information
// (such as news, products, weather, etc.) for your large model through the Responses API.
// This tool can solve core issues such as data timeliness, knowledge gaps, and information synchronization,
// and you do not need to develop your own search engine or maintain data resources.
// Note: This option is only effective for the Responses API.
// For more details, see https://www.volcengine.com/docs/82379/1756990?lang=zh
// Optional.
EnableToolWebSearch *ToolWebSearch `json:"enable_tool_web_search,omitempty"`
// MaxToolCalls specifies the maximum number of tool-calling rounds.
// The value must be in the range [1, 10].
// After this limit is reached, the model is prompted to stop making further tool calls and generate a response.
// Note: This is a best-effort parameter, and the actual number of calls may be affected by model performance and tool results.
// The default value for the Web Search tool is 3.
// For more details, see https://www.volcengine.com/docs/82379/1569618?lang=zh
// Optional.
MaxToolCalls *int64 `json:"max_tool_calls,omitempty"`
// EnableReasoningContentPassback controls whether reasoning content
// from assistant messages is passed back to the model in multi-turn conversations.
// When enabled, reasoning summaries and raw reasoning content are passed back in their original form,
// allowing the model to be aware of its prior chain-of-thought.
// However, if a valid previous_response_id is set (via session cache), the passback is
// automatically skipped because previous_response_id already preserves the full conversation
// context including the chain-of-thought on the server side.
// Note: This feature requires doubao models v1.8+. Earlier versions (e.g., v1.6) do not
// support reasoning items in the input and will return an error.
// For more details, see https://www.volcengine.com/docs/82379/1449737
// Default: false.
// Optional.
EnableReasoningContentPassback bool `json:"enable_reasoning_content_passback,omitempty"`
}
type SequentialImageGeneration ¶
type SequentialImageGeneration string
const ( SequentialImageGenerationDisabled SequentialImageGeneration = "disabled" SequentialImageGenerationAuto SequentialImageGeneration = "auto" )
type SessionCacheConfig ¶
type SessionCacheConfig struct {
// EnableCache controls whether session caching is active.
// When enabled, the model stores both inputs and responses for each conversation turn,
// allowing them to be retrieved later via API.
// Response IDs are saved in output messages and can be accessed using GetResponseID.
// For multi-turn conversations, the ARK ChatModel automatically identifies the most recent
// cached message from all inputs and passes its response ID to model to maintain context continuity.
// This message and all previous ones are trimmed before being sent to the model.
// When both HeadPreviousResponseID and cached message exist, the message's response ID takes precedence.
// Use InvalidateMessageCaches to disables caching for the specified messages.
EnableCache bool `json:"enable_cache"`
// TTL specifies the survival time of cached data in seconds, with a maximum of 3 * 86400(3 days).
TTL int `json:"ttl"`
}
type Source ¶
type Source string
Source specifies the additional content source for web searches. Optional sources are Toutiao, Douyin , and Moji Weather.
- toutiao: Additional content source from Toutiao for web searches.
- douyin: Additional content source from Douyin for web searches.
- moji: Additional content source from Moji Weather for web searches.
type ThinkingType ¶
type ThinkingType = arkModel.ThinkingType
type ToolWebSearch ¶
type ToolWebSearch struct {
// Limit is the maximum number of results to retrieve per search in a single round.
// It affects input size and performance. The value must be in the range [1, 50].
// Optional. Default 10
Limit *int64 `json:"limit,omitempty"`
// UserLocation is the user's geographical location, used for scenarios like weather queries.
// It includes `type`, `country`, `city`, and `region` fields.
UserLocation *UserLocation `json:"user_location,omitempty"`
// Sources is a list of additional content sources for web searches. See the Source type for available options.
Sources []Source `json:"sources,omitempty"`
// MaxKeyword is the maximum number of keywords to search in parallel within a single tool-use round.
// For example, if the model identifies multiple keywords to search (e.g., "A", "B", "C")
// and max_keyword is 1, only the first keyword ("A") will be searched.
// The value must be in the range [1, 50].
// Optional.
MaxKeyword *int32 `json:"max_keyword,omitempty"`
}
ToolWebSearch holds the configuration for the web search tool.
type UserLocation ¶
type UserLocation struct {
City *string `json:"city,omitempty"`
Country *string `json:"country,omitempty"`
Region *string `json:"region,omitempty"`
Timezone *string `json:"timezone,omitempty"`
}
UserLocation is the user's geographical location, used for scenarios like weather queries. It includes `country`, `city`, `region` and `timezone` fields.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
generate
command
|
|
|
generate_batch_chat
command
|
|
|
generate_with_image
command
|
|
|
image_generate
command
|
|
|
intent_tool
command
|
|
|
prefixcache/contextapi
command
|
|
|
prefixcache/responsesapi
command
|
|
|
sessioncache/contextapi
command
|
|
|
sessioncache/responsesapi
command
|
|
|
stream
command
|