Documentation
¶
Overview ¶
Package zaicoding implements Z.ai Coding's Chat Completions dialect.
Index ¶
- Constants
- Variables
- func KnownModels() []elelem.Model
- func LookupModel(id string) elelem.Model
- type Driver
- func (d *Driver) Capabilities(model elelem.Model) elelem.Capabilities
- func (d *Driver) Complete(ctx context.Context, req elelem.DriverRequest, ...) (elelem.Usage, error)
- func (d *Driver) ListModels(ctx context.Context) ([]string, error)
- func (d *Driver) Stream(ctx context.Context, req elelem.DriverRequest, ...) (elelem.Usage, error)
- func (d *Driver) TokenCounter() elelem.TokenCounter
- type DriverOption
Constants ¶
const ( // Name identifies this provider-specific driver. Name = "zai-coding" // DefaultBaseURL is Z.ai Coding's OpenAI-compatible endpoint. DefaultBaseURL = "https://api.z.ai/api/coding/paas/v4" )
Variables ¶
var ( // ErrUnsupportedParameter marks a Z.ai Coding control that the selected // model cannot accept. ErrUnsupportedParameter = errors.New("unsupported Z.ai Coding parameter") // ErrSensitiveContent is Z.ai's refusal of input or output it classifies // as unsafe (business code 1301). Retrying the same request returns the // same refusal. ErrSensitiveContent = errors.New("sensitive content refused by Z.ai Coding") )
Functions ¶
func KnownModels ¶
KnownModels returns the models the Z.ai Coding Plan serves.
func LookupModel ¶
LookupModel returns known model metadata and leaves unknown IDs unchanged. GLM 5.3 Flash X and the retired IDs the Coding Plan routes to GLM 5.3 or GLM 5.3 Flash get the metadata of the model that serves them.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver translates Elelem requests to Z.ai Coding's OpenAI-shaped API.
func NewDriver ¶
func NewDriver(opts ...DriverOption) *Driver
NewDriver constructs a Z.ai Coding driver. It never reads OPENAI_* environment settings because those settings can belong to another upstream.
func (*Driver) Capabilities ¶
func (d *Driver) Capabilities(model elelem.Model) elelem.Capabilities
Capabilities reports the selected Z.ai Coding model's validated controls.
func (*Driver) Complete ¶
func (d *Driver) Complete( ctx context.Context, req elelem.DriverRequest, onDelta func(elelem.Delta) error, ) (elelem.Usage, error)
Complete issues one non-streaming Z.ai Coding chat completion.
func (*Driver) ListModels ¶
ListModels returns model IDs exposed by the configured endpoint.
func (*Driver) Stream ¶
func (d *Driver) Stream( ctx context.Context, req elelem.DriverRequest, onDelta func(elelem.Delta) error, ) (elelem.Usage, error)
Stream issues one streaming Z.ai Coding chat completion. When the request carries tools it asks for tool_stream, so tool-call arguments arrive in fragments instead of in one piece at the end of the call.
func (*Driver) TokenCounter ¶
func (d *Driver) TokenCounter() elelem.TokenCounter
TokenCounter returns the transport's token counter.
type DriverOption ¶
type DriverOption func(*driverConfig)
DriverOption configures a Z.ai Coding driver.
func WithAPIKey ¶
func WithAPIKey(apiKey string) DriverOption
WithAPIKey supplies the bearer token used by Z.ai Coding.
func WithBaseURL ¶
func WithBaseURL(baseURL string) DriverOption
WithBaseURL overrides Z.ai Coding's endpoint.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) DriverOption
WithHTTPClient supplies the HTTP client used by the underlying SDK.
func WithSDKOptions ¶
func WithSDKOptions(opts ...option.RequestOption) DriverOption
WithSDKOptions appends official OpenAI SDK options for this driver only.