Documentation
¶
Overview ¶
Package dashscope provides a Genkit plugin for Alibaba Cloud's Qwen models, served through DashScope's OpenAI-compatible mode.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ModelRef ¶
func ModelRef(id string, config *ChatConfig) ai.ModelRef
ModelRef names a Qwen model and carries the config to generate with, so the config is typed at the call site instead of an any the model checks at runtime. A nil config leaves the request's config unset.
ai.WithModel(dashscope.ModelRef("qwen-plus", &dashscope.ChatConfig{
EnableThinking: openai.Ptr(true),
}))
id is the model ID, with or without the provider prefix.
Types ¶
type ChatConfig ¶
type ChatConfig struct {
compat_oai.RequestConfig
// Temperature controls the degree of randomness in token selection, from
// 0 inclusive up to but not including 2.
Temperature *float64 `` /* 193-byte string literal not displayed */
// TopP is the nucleus sampling threshold, above 0 and up to 1 inclusive.
TopP *float64 `` /* 147-byte string literal not displayed */
// MaxOutputTokens is the maximum number of tokens to generate, sent as the
// API's max_tokens; the default and the ceiling are both the model's
// maximum output length.
MaxOutputTokens int `` /* 220-byte string literal not displayed */
// StopSequences stop generation when produced by the model.
StopSequences []string `json:"stopSequences,omitempty" jsonschema_description:"Stop generation when produced by the model."`
// PresencePenalty penalizes tokens that have appeared at all, from -2.0 to
// 2.0. DashScope's compatible mode documents no frequency penalty.
PresencePenalty *float64 `` /* 153-byte string literal not displayed */
// Seed makes generation reproducible across calls when set, from 0 to
// 2^31-1.
Seed *int `` /* 159-byte string literal not displayed */
// EnableThinking turns the thinking mode of hybrid Qwen models on or off,
// sent as the API's enable_thinking.
EnableThinking *bool `` /* 148-byte string literal not displayed */
// ThinkingBudget is the maximum number of tokens the model may think
// with, sent as the API's thinking_budget; it requires EnableThinking.
// The default is the model's maximum chain-of-thought length.
ThinkingBudget *int `` /* 247-byte string literal not displayed */
// EnableSearch lets the model consult web search, sent as the API's
// enable_search.
EnableSearch *bool `json:"enableSearch,omitempty" jsonschema_description:"Lets the model consult web search, sent as the API's enable_search."`
}
ChatConfig is the per-request config for Qwen models served through DashScope's OpenAI-compatible mode: the common generation fields plus the DashScope-specific controls the mode accepts as extra request fields. See https://www.alibabacloud.com/help/en/model-studio/use-qwen-by-calling-api.
func (ChatConfig) ApplyToChatCompletion ¶
func (c ChatConfig) ApplyToChatCompletion(params *openai.ChatCompletionNewParams)
ApplyToChatCompletion implements compat_oai.ChatConfig: the generation fields land on their chat completion counterparts and the DashScope controls ride as the mode's extra request fields.
type DashScope ¶
type DashScope struct {
// APIKey is the DashScope API key. If empty, DASHSCOPE_API_KEY is consulted.
APIKey string
// Opts contains additional OpenAI client request options, such as
// [option.WithBaseURL] for a different endpoint (DASHSCOPE_BASE_URL works
// too). Options supplied here are applied after the plugin defaults, so
// they win on overlap.
Opts []option.RequestOption
// Models overrides what the plugin knows about a Qwen model, keyed by
// model ID, bare or provider-prefixed. Every Qwen model already works
// without an entry: known IDs carry curated capabilities and the rest take
// the Qwen defaults. Supply an entry only to correct or extend what the
// plugin resolves, most often for a model released after this version of
// the plugin.
//
// &dashscope.DashScope{Models: map[string]ai.ModelOptions{
// "qwen-plus": {Supports: &ai.ModelSupports{Multiturn: true, Tools: true}},
// }}
//
// Fields left at their zero value keep what the plugin resolves, so an
// entry can pin one capability without restating the label or the
// versions. Entries apply to the models Init registers as well as the
// ones [DashScope.ListActions] advertises and [DashScope.ResolveAction] builds,
// which is the way to describe a curated model differently: Init has
// already registered those and nothing can re-register them.
Models map[string]ai.ModelOptions
// contains filtered or unexported fields
}
DashScope configures the Alibaba Cloud DashScope (Qwen) plugin.
func (*DashScope) ListActions ¶
func (d *DashScope) ListActions(ctx context.Context) []api.ActionDesc
ListActions lists the models the configured DashScope endpoint exposes, described by the plugin's config schema and capabilities.
func (*DashScope) ResolveAction ¶
ResolveAction dynamically builds a model exposed by the DashScope endpoint, described by the plugin's config schema and capabilities.