gemini

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 51 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultModelID = "gemini-default"

DefaultModelID 是解析为各账号官方默认模型的公开 ID

View Source
const GemModelPrefix = "gem-"

GemModelPrefix 是 Gem 在公开模型目录中的 ID 前缀

View Source
const GuestID = "guest"

GuestID 是访客会话在账号池、日志与账本中的 ID

View Source
const ImageModelID = "gemini-3.1-flash-image"

ImageModelID 是官网 Create image 工具的公开模型 ID

View Source
const SpeechTextLimit = 4096

SpeechTextLimit 是单次朗读接受的最大字符数

Variables

View Source
var ErrAccountRestricted = errors.New("Gemini 账号不可用")

ErrAccountRestricted 表示模型目录的账号状态码显示账号暂时不能使用 Gemini,例如待同意条款、地区或监护人限制

View Source
var ErrCaptcha = errors.New("请求被 Google 人机验证页拦截")

ErrCaptcha 表示 Google 以人机验证页(/sorry)拦截了请求,出口 IP 与账号会话被判定为异常流量

View Source
var ErrConversationLost = errors.New("Gemini Web 网页会话已失效")

ErrConversationLost 表示续接的网页会话在上游已不存在:上游在新会话中作答或返回 1097

View Source
var ErrGuestAttachments = &ProtocolError{HTTPStatus: 503, Message: "访客会话不能上传附件,需要可用的登录账号"}

ErrGuestAttachments 表示带附件的请求落到访客会话,官网访客页面的上传入口全部禁用

View Source
var ErrInputBlocked = errors.New("Gemini Web 按输入拦截了请求")

ErrInputBlocked 表示 Gemini Web 按输入本身拦截了请求,同一输入重发仍被拦截

View Source
var ErrModelMismatch = errors.New("官网改用了其他模型回答")

ErrModelMismatch 表示上游实际回答的模型与请求的模型不同,常见于该模型额度用尽后的降级

View Source
var ErrSignedOut = errors.New("Gemini Web 会话已失效")

ErrSignedOut 表示账号会话已失效且未能续签,需要重新导入

View Source
var ErrTransport = errors.New("网络或上游临时故障")

ErrTransport 表示连接、TLS 或代理等网络层失败,与账号状态无关

View Source
var ErrUpstreamFailureText = errors.New("官网返回了固定的失败回复")

ErrUpstreamFailureText 表示 Gemini Web 用固定失败文字代替回答

Functions

func AccountCatalogs added in v0.2.0

func AccountCatalogs() map[string]AccountCatalog

AccountCatalogs 返回各账号最近一次读取的目录副本

func CanonicalModelID added in v0.2.0

func CanonicalModelID(value string) string

CanonicalModelID 返回规范化后的模型 ID,有改名记录时为改名后的当前 ID

func ChromeUserAgent added in v0.1.2

func ChromeUserAgent(major int) string

ChromeUserAgent 返回主版本 major 的 Chrome User-Agent,major 为 0 时为版本池中最新的版本

func InFencedCode added in v0.1.8

func InFencedCode(text string, position int) bool

InFencedCode 判断字节位置是否在 Markdown 围栏代码块内,未闭合的围栏延伸到正文末尾

func IsAuthenticationError added in v0.1.3

func IsAuthenticationError(err error) bool

IsAuthenticationError 判断错误是否表示账号会话失效,包括 HTTP 401、403 与续签失败

func IsChromeVersion added in v0.2.0

func IsChromeVersion(major int) bool

IsChromeVersion 判断 major 是否为版本池中的 Chrome 主版本

func LoadModelNames added in v0.2.0

func LoadModelNames(store ModelNameStore) error

LoadModelNames 从 store 读入改名记录与各账号最近的目录,之后读到的目录写回 store

func ModelRenames added in v0.2.0

func ModelRenames() map[string]string

ModelRenames 返回改名记录的副本,键为旧 ID,值为当前 ID

func NewHTTPClient added in v0.1.2

func NewHTTPClient(timeoutSeconds int, proxyURL string, major int) (tls_client.HttpClient, error)

NewHTTPClient 创建经代理 proxyURL 访问、TLS 与 HTTP/2 和主版本 major 的 Chrome 稳定版一致的客户端,proxyURL 为空时直连,major 为 0 时为版本池中最新的版本

func NormalizeModelID added in v0.2.0

func NormalizeModelID(value string) string

NormalizeModelID 返回去掉首尾空白、Gemini API 的 models/ 前缀与社区通用的 google/ 前缀并转为小写的模型 ID

func PickChromeVersion added in v0.2.0

func PickChromeVersion() int

PickChromeVersion 按版本池各版本的用户占比加权随机返回一个 Chrome 主版本

func ProbeProxy added in v0.1.5

func ProbeProxy(ctx context.Context, proxyURL string) (time.Duration, error)

ProbeProxy 经代理以浏览器导航请求官网首页,首页返回 200 时报告耗时

func TransientError added in v0.1.7

func TransientError(err error) bool

TransientError 判断错误是否为与账号状态无关的一次性上游失败:网络层失败、生成流在结束帧前中断或停顿,以及没有具体原因的 5xx(上游 HTTP 5xx、5xx 错误记录、没有完成的候选)

func WithSlotYieldController added in v0.2.0

func WithSlotYieldController(ctx context.Context, ctrl SlotYieldController) context.Context

WithSlotYieldController 将槽位让出协调器绑定到 context

Types

type AbuseStatus added in v0.2.0

type AbuseStatus struct {
	Restricted bool   `json:"restricted"`
	Code       int    `json:"code,omitempty"`
	Signal     string `json:"signal,omitempty"`
}

AbuseStatus 是官网页面加载时 GPRiHf 返回的账号异常状态,Restricted 为假表示没有异常标记

type AccountCatalog added in v0.2.0

type AccountCatalog struct {
	Tier    string         `json:"tier"`
	Entries []CatalogEntry `json:"entries"`
	Locked  []string       `json:"locked,omitempty"`
}

AccountCatalog 是账号最近一次读取的目录:层级、各位置键上的公开 ID 与上锁的公开 ID

type AccountSource

type AccountSource struct {
	ID       string
	Cookies  []Cookie
	Language string
	// AuthUser 是目标账号在多账号 Cookie 中的序号,对应官网地址 /u/N,0 为默认账号
	AuthUser int
	// Chrome 是账号绑定的 Chrome 主版本,0 为版本池中最新的版本
	Chrome  int
	Save    func([]Cookie) error
	Refresh func(context.Context) ([]Cookie, error)
	// RotateBound 在设备绑定 Cookie 将到期时刷新设备绑定会话并返回距下次刷新的等待时间,cookies 返回账号当前的 Cookie,send 以账号的客户端发出请求并写回响应 Cookie
	RotateBound func(ctx context.Context, cookies func() []Cookie, send func(*http.Request) (int, http.Header, error)) (time.Duration, error)
	// Concurrency 是账号同时进行的上游请求数,零按 1 处理
	Concurrency int
}

AccountSource 表示账号固定身份和 Cookie 持久化入口

type Bootstrap

type Bootstrap struct {
	// SNlM0e 为登录会话的表单令牌,访客会话为空
	SNlM0e string
	BL     string
	FSID   string
	// Language 为首页 TuX5cc 给出的账号界面语言,用于 hl 与生成载荷语言槽
	Language string
	// Email 为首页 oPEP7c 给出的当前登录邮箱
	Email string
	// UploadURL、UploadPushID、UploadClientContext 为首页 h1eoVe、qKIAYe、Ylro7b 给出的附件上传端点与请求头
	UploadURL           string
	UploadPushID        string
	UploadClientContext string
	// UploadTermsWindow 为首页实验 45725082 给出的上传条款确认有效期
	UploadTermsWindow time.Duration
	// TermsToken 为首页 thykhd 给出的服务条款同意令牌
	TermsToken string
	// APIKey、ServerToken 为首页 d2zJAe、PI9WOb 给出的生成会话 API key 与服务端令牌
	APIKey      string
	ServerToken string
	Catalog     ModelCatalog
	Preferences Preferences
}

Bootstrap 表示首页和模型目录共同产生的运行参数

type CatalogEntry added in v0.2.0

type CatalogEntry struct {
	Position string `json:"position"`
	ID       string `json:"id"`
}

CatalogEntry 是账号目录中一个位置键上的公开 ID

type Citation

type Citation struct {
	ID        int    `json:"id"`
	SourceID  string `json:"source_id,omitempty"`
	Claim     string `json:"claim,omitempty"`
	Title     string `json:"title,omitempty"`
	URL       string `json:"url"`
	Favicon   string `json:"favicon,omitempty"`
	Snippet   string `json:"snippet,omitempty"`
	Publisher string `json:"publisher,omitempty"`
	Start     int    `json:"start"`
	End       int    `json:"end"`
}

Citation 表示正文引用标记对应的网页来源

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 表示与单一账号身份绑定的 Gemini Web 协议客户端

func NewClient

func NewClient(source AccountSource, proxyURL string, saveHistory bool) (*Client, error)

NewClient 创建固定 Cookie、代理和语言的账号客户端

func NewGuestClient added in v0.1.3

func NewGuestClient(proxyURL string, concurrency int) (*Client, error)

NewGuestClient 创建以未登录会话访问官网的访客客户端

func (*Client) AbuseStatus added in v0.2.0

func (c *Client) AbuseStatus() *AbuseStatus

AbuseStatus 返回账号最近一次初始化读取的异常状态,访客会话与尚未读取时为 nil

func (*Client) AcquireRequest

func (c *Client) AcquireRequest(ctx context.Context) (func(), error)

AcquireRequest 占用账号的一个请求槽直到完整上游请求链结束,后台生成的轮询阶段让出

func (*Client) Busy added in v0.1.2

func (c *Client) Busy() bool

Busy 报告账号的请求槽是否已全部占用

func (*Client) CachedUsage added in v0.1.3

func (c *Client) CachedUsage() *UsageInfo

CachedUsage 返回最近一次读取的官网用量,尚未读取时为 nil

func (*Client) CloseIdleConnections

func (c *Client) CloseIdleConnections()

CloseIdleConnections 关闭协议客户端的空闲连接

func (*Client) ContextWindow

func (c *Client) ContextWindow() int

ContextWindow 返回账号套餐对应的网页输入窗口

func (*Client) DeleteConversation added in v0.1.9

func (c *Client) DeleteConversation(ctx context.Context, cid string, mode int) error

DeleteConversation 从账号的网页历史中删除会话,mode 为会话所用模型的模式

func (*Client) Email added in v0.1.4

func (c *Client) Email() string

Email 返回首页 oPEP7c 给出的当前登录邮箱,访客会话与尚未初始化时为空

func (*Client) FetchMedia

func (c *Client) FetchMedia(ctx context.Context, mediaURL string) ([]byte, error)

FetchMedia 使用账号固定身份和 Cookie 下载媒体内容

func (*Client) FetchMediaContent added in v0.1.2

func (c *Client) FetchMediaContent(ctx context.Context, media Media) ([]byte, error)

FetchMediaContent 下载媒体内容,生成图片按官网“下载原图”取推荐尺寸原图

func (*Client) FetchRemoteMedia added in v0.1.6

func (c *Client) FetchRemoteMedia(ctx context.Context, mediaURL string, limit int64) ([]byte, error)

FetchRemoteMedia 以账号的浏览器身份与出口、不带账号 Cookie 下载客户端给出的媒体地址,每条连接只连向解析后检查过的公网地址,声明或读到的大小超过 limit 时返回错误

func (*Client) FetchUsage

func (c *Client) FetchUsage(ctx context.Context) (UsageInfo, error)

FetchUsage 读取官网当前账号用量

func (*Client) Guest added in v0.1.3

func (c *Client) Guest() bool

Guest 报告客户端是否为未登录的访客会话

func (*Client) Init

func (c *Client) Init(ctx context.Context) error

Init 刷新首页动态参数并获取当前账号模型目录与偏好

func (*Client) Models

func (c *Client) Models() []Model

Models 返回当前账号初始化得到的模型目录

func (*Client) ObserveCatalog added in v0.2.0

func (c *Client) ObserveCatalog()

ObserveCatalog 把账号当前的目录与层级交给 observeCatalog,尚未初始化时不做任何事

func (*Client) Pending added in v0.1.3

func (c *Client) Pending() int

Pending 返回占用或等待账号请求槽的请求数

func (*Client) ResolveModel

func (c *Client) ResolveModel(id string) (Model, error)

ResolveModel 在当前账号模型目录中解析公开 ID

func (*Client) SetReleaseHook added in v0.1.6

func (c *Client) SetReleaseHook(hook func())

SetReleaseHook 设置请求槽释放后调用的函数

func (*Client) Speech added in v0.1.3

func (c *Client) Speech(ctx context.Context, text string, language string, format SpeechFormat) ([]byte, error)

Speech 以官网朗读 RPC 把文本合成为音频,language 为空时使用账号界面语言;调用方持有账号请求槽

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, request GenerateRequest, emit func(Event) error) error

Stream 执行一次生成并只输出规范事件,Deep Research 按官网计划、确认与报告流程执行

func (*Client) TemporaryChats added in v0.1.9

func (c *Client) TemporaryChats() bool

TemporaryChats 报告账号的生成请求是否默认使用 Temporary Chat,不写入网页历史

func (*Client) TryAcquireRequest added in v0.1.6

func (c *Client) TryAcquireRequest() (func(), bool)

TryAcquireRequest 在账号有空闲请求槽时占用一个并返回释放函数

func (*Client) YieldRequest added in v0.1.7

func (c *Client) YieldRequest() (func(), bool)

YieldRequest 取得一个让出请求槽的名额,同一账号同时只有一个请求能让出,成功时返回归还名额的函数

type CodeEventType

type CodeEventType string

CodeEventType 表示 Gemini Web 内置代码执行事件类型

const (
	CodeReference CodeEventType = "code_reference"
	CodeStdout    CodeEventType = "code_stdout"
	CodeStderr    CodeEventType = "code_stderr"
)

type CodeExecutionEvent

type CodeExecutionEvent struct {
	Index    int
	Type     CodeEventType
	Language string
	Offset   int
	Complete bool
}

CodeExecutionEvent 表示 Google 已执行的代码及其结果

type ConversationSnapshot

type ConversationSnapshot struct {
	CID  string
	RID  string
	RCID string
	// Token 为回答 payload[2]["26"] 给出的续接令牌
	Token     string
	ModelMode int
	Turns     int
	// Saved 表示会话不是 Temporary Chat,续接时同样不使用 Temporary Chat
	Saved bool
}

ConversationSnapshot 表示可序列化的网页会话三元组、续接令牌、上一轮使用的模型 mode 与截至该回答的轮数

type ConversationState

type ConversationState struct {
	// contains filtered or unexported fields
}

ConversationState 保存线程安全的网页会话状态

func NewConversationState

func NewConversationState() *ConversationState

NewConversationState 创建空网页会话状态

func NewConversationStateFrom

func NewConversationStateFrom(snapshot ConversationSnapshot) *ConversationState

NewConversationStateFrom 从已有三元组创建网页会话状态

func (*ConversationState) Snapshot

Snapshot 返回当前会话状态副本

func (*ConversationState) Update

func (s *ConversationState) Update(snapshot ConversationSnapshot)

Update 原子替换非空会话字段

type Cookie struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Domain   string `json:"domain"`
	Path     string `json:"path"`
	Expires  int64  `json:"expires"`
	HTTPOnly bool   `json:"http_only"`
	Secure   bool   `json:"secure"`
	SameSite string `json:"same_site"`
}

Cookie 表示可无损写回认证状态的 Cookie

type CookieRotator added in v0.1.2

type CookieRotator struct {
	// contains filtered or unexported fields
}

CookieRotator 以官网轮换页的方式为一个账号轮换 Cookie,同一时间只由一个调用方使用

func NewCookieRotator added in v0.1.2

func NewCookieRotator(client *Client) *CookieRotator

NewCookieRotator 创建账号的 Cookie 轮换器

func (*CookieRotator) Rotate added in v0.1.2

func (r *CookieRotator) Rotate(ctx context.Context) (time.Duration, error)

Rotate 轮换 __Secure-1PSIDTS 并经 ListAccounts 确认会话有效,释放请求槽后重读账号状态,返回下次轮换前的等待时间;会话失效且账号带续签材料时在请求槽内续签并重读

type Event

type Event struct {
	Kind         EventKind
	Candidate    int
	Operation    SnapshotOperation
	Delta        string
	Snapshot     string
	PrefixLength int
	Phase        Phase
	Session      ConversationSnapshot
	Code         *CodeExecutionEvent
	Citations    []Citation
	Media        *Media
	Metadata     *EventMetadataData
	Usage        *Usage
	FinishReason FinishReason
	Err          *ProtocolError
}

Event 表示所有公开适配器共享的上游事件

type EventKind

type EventKind string

EventKind 表示规范化协议事件类型

const (
	EventSession       EventKind = "session"
	EventText          EventKind = "text"
	EventThought       EventKind = "thought"
	EventCode          EventKind = "code"
	EventCitations     EventKind = "citations"
	EventMedia         EventKind = "media"
	EventImageProgress EventKind = "image_progress"
	EventPhase         EventKind = "phase"
	EventMetadata      EventKind = "metadata"
	EventError         EventKind = "error"
	EventDone          EventKind = "done"
)

type EventMetadataData

type EventMetadataData struct {
	Title        string
	ControlToken string
	ModelHash    string
	ModelName    string
	// LimitNotice 是用量用满后上游随降级回答给出的额度提示
	LimitNotice string
	// FailureReply 表示上游把本次回答标为固定失败回复
	FailureReply bool
}

EventMetadataData 表示页面协议返回的附加元数据

type Feature added in v0.1.2

type Feature int

Feature 表示网页输入框工具菜单选中的功能,取值为官网 featureMode 编号

const (
	// FeatureDeepResearch 是 Deep Research 研究报告,只能在普通会话中使用
	FeatureDeepResearch Feature = 1
	// FeatureCanvas 是 Canvas 文档工具
	FeatureCanvas Feature = 2
	// FeatureVideo 是 Create video 视频生成,成品在生成流结束后由会话读取
	FeatureVideo Feature = 11
	// FeatureImage 是 Create image 生图工具
	FeatureImage Feature = 14
	// FeatureMusic 是 Create music 音乐生成
	FeatureMusic Feature = 21
	// FeatureLearning 是 Guided Learning 引导式学习
	FeatureLearning Feature = 24
	// FeatureTask 是 Task 模式,只能在普通会话中使用
	FeatureTask Feature = 40
)

type FileData

type FileData struct {
	// Data 为待上传的文件内容,生成前上传
	Data []byte
	// URL 为上传服务返回的文件路径
	URL      string
	FileName string
	MimeType string
	// FileID 为 ProcessFile 返回的文件 ID,生成前登记
	FileID string
}

FileData 表示生成请求携带的附件

type FinishReason

type FinishReason string

FinishReason 表示规范化结束原因

const (
	FinishUnknown   FinishReason = "unknown"
	FinishStop      FinishReason = "stop"
	FinishCancelled FinishReason = "cancelled"
	FinishError     FinishReason = "error"
)

type FrameDecoder

type FrameDecoder struct {
	// contains filtered or unexported fields
}

FrameDecoder 将 Google 累计帧转换为唯一规范事件流

func NewFrameDecoder

func NewFrameDecoder() *FrameDecoder

NewFrameDecoder 创建独立的单响应解码器

func (*FrameDecoder) Decode

func (d *FrameDecoder) Decode(records func(yield func(streamRecord) error) error, state *ConversationState, emit func(Event) error) error

Decode 依次解析 records 给出的生成流记录并原子更新会话状态

type Gem added in v0.1.3

type Gem struct {
	ID          string
	Name        string
	Description string
	Predefined  bool
}

Gem 是官网的一个 Gem:系统预置或账号自建

type GenerateRequest

type GenerateRequest struct {
	Prompt        string
	Model         string
	ModelMode     int
	ThinkingLevel ThinkingLevel
	Feature       Feature
	// Gem 为在 Gem 中对话时的 Gem ID
	Gem string
	// AspectRatio 为生成媒体请求的宽高比,例如 16:9 或 1536x1024,空值使用官网默认
	AspectRatio string

	Files        []FileData
	Conversation *ConversationState
	// Branch 表示从会话中较早的回答继续,官网对应编辑该回答之后的提问
	Branch bool
	// ClientTools 表示请求带客户端执行的工具,这类请求不使用 Temporary Chat
	ClientTools bool
	// contains filtered or unexported fields
}

GenerateRequest 表示一次网页协议生成请求

type Media

type Media struct {
	Type        MediaType `json:"type"`
	URL         string    `json:"url"`
	Title       string    `json:"title,omitempty"`
	Alt         string    `json:"alt,omitempty"`
	FileName    string    `json:"file_name,omitempty"`
	MIMEType    string    `json:"mime_type,omitempty"`
	Generator   string    `json:"generator,omitempty"`
	Placeholder string    `json:"placeholder,omitempty"`
	Width       int       `json:"width,omitempty"`
	Height      int       `json:"height,omitempty"`
	SizeBytes   int       `json:"size_bytes,omitempty"`
	// Thumbnail 是网页视频条目给出的缩略图地址
	Thumbnail string `json:"thumbnail,omitempty"`
	Offset    int    `json:"offset"`
	// contains filtered or unexported fields
}

Media 表示规范事件携带的网页或生成媒体

type MediaType

type MediaType string

MediaType 表示 Gemini Web 媒体类型

const (
	// MediaGeneratedImage 是 Create image 生成的图片
	MediaGeneratedImage MediaType = "generated_image"
	// MediaGeneratedVideo 是 Create video 生成的视频
	MediaGeneratedVideo MediaType = "generated_video"
	// MediaGeneratedAudio 是 Create music 生成的音频
	MediaGeneratedAudio MediaType = "generated_audio"
)

type Model

type Model struct {
	ID           string
	DisplayName  string
	Description  string
	Hash         string
	Capabilities []string
	Mode         int
	Default      bool
	// ThinkingLevels 为官网模型菜单中该模型可选的思考强度
	ThinkingLevels []ThinkingLevel
	// Feature 为该 ID 在生成请求中选中的官网工具,普通对话模型为零
	Feature Feature
	// Gem 为 Gem 条目的 Gem ID,写入生成请求 19 槽
	Gem string
	// Variant 为模型策略中与其他模型共用 mode 的模型的变体键,这类模型的 Hash 也是该键
	Variant string
	// Position 是条目在官网目录中的位置键(界面与 mode、变体键或工具编号),官网改名时不变
	Position string
}

Model 表示账号启动时发现的网页模型

func (Model) ServedBy added in v0.1.9

func (m Model) ServedBy(metadata EventMetadataData) bool

ServedBy 报告上游元数据是否表明回答来自该模型:变体模型的响应带账号默认模型的 hash,按型号名核对,上游在 Low 以外的思考强度下于型号名后加档位名(如 4 Argon High)

type ModelCatalog

type ModelCatalog struct {
	// contains filtered or unexported fields
}

ModelCatalog 表示单个账号当前可用的模型目录

func (ModelCatalog) Default

func (c ModelCatalog) Default() (Model, error)

Default 返回官方标记的默认模型

func (ModelCatalog) List

func (c ModelCatalog) List() []Model

List 返回稳定排序的模型副本

func (ModelCatalog) Locked added in v0.2.0

func (c ModelCatalog) Locked() []string

Locked 返回模型策略中上锁、需要更高层级的模型公开 ID

func (ModelCatalog) Resolve

func (c ModelCatalog) Resolve(value string) (Model, error)

Resolve 依次按当前目录(公开 ID、官方名称或 hash)、改名记录与 gemini-default 查找模型,ID 可带 models/ 或 google/ 前缀

type ModelNameStore added in v0.2.0

type ModelNameStore interface {
	LoadModelNames() (renames map[string]string, catalogs map[string]AccountCatalog, err error)
	SaveModelNames(accountID string, catalog AccountCatalog, renames map[string]string) error
}

ModelNameStore 保存公开 ID 的改名记录与各账号最近一次读取的目录

type Phase

type Phase int

Phase 表示候选生成阶段

const (
	PhaseUnknown      Phase = 0
	PhaseGenerating   Phase = 1
	PhaseComplete     Phase = 2
	PhaseToolComplete Phase = 4
)

type Preferences added in v0.1.2

type Preferences []any

Preferences 是 ESY5D 返回的账号偏好消息,字段号超出数组的值位于末尾的稀疏对象

func (Preferences) Bool added in v0.1.2

func (p Preferences) Bool(number int) bool

Bool 按字段号返回布尔偏好,缺失时为 false

func (Preferences) Field added in v0.1.2

func (p Preferences) Field(number int) any

Field 按字段号返回偏好值

type ProtocolError

type ProtocolError struct {
	HTTPStatus int
	Code       int
	Message    string
	Retryable  bool
	Cause      error
}

ProtocolError 表示 HTTP 或帧内协议错误

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

Error 返回适合日志和公开错误映射的描述

func (*ProtocolError) Unwrap

func (e *ProtocolError) Unwrap() error

Unwrap 返回底层错误

type SlotYieldController added in v0.2.0

type SlotYieldController func() (restore func(), alreadyReleased bool)

SlotYieldController 协调外层超时让出与内部后台轮询让出,防止同一请求重复释放请求槽

type SnapshotOperation

type SnapshotOperation string

SnapshotOperation 表示累计快照相对上一版本的变化

const (
	SnapshotAppend   SnapshotOperation = "append"
	SnapshotReplace  SnapshotOperation = "replace"
	SnapshotTruncate SnapshotOperation = "truncate"
)

type SpeechFormat added in v0.1.3

type SpeechFormat int

SpeechFormat 是朗读音频的容器格式,取值写入 XqA3Ic 请求第 4 槽

const (
	// SpeechMP3 是 24 kHz 单声道 MPEG-2 Layer III
	SpeechMP3 SpeechFormat = 1
	// SpeechOggOpus 是官网页面播放使用的 Ogg Opus
	SpeechOggOpus SpeechFormat = 2
)

type ThinkingLevel added in v0.1.2

type ThinkingLevel int

ThinkingLevel 表示网页模型菜单中的思考强度,取值为官网协议编号

const (
	// ThinkingLow 是低思考强度
	ThinkingLow ThinkingLevel = 1
	// ThinkingMedium 是中等思考强度
	ThinkingMedium ThinkingLevel = 4
	// ThinkingHigh 是高思考强度
	ThinkingHigh ThinkingLevel = 2
)

func (ThinkingLevel) String added in v0.1.2

func (l ThinkingLevel) String() string

String 返回思考强度的小写名称

type Usage

type Usage struct {
	PromptTokens     int
	CompletionTokens int
	ThoughtTokens    int
	TotalTokens      int
}

Usage 表示上游提供的令牌用量

func (Usage) OutputTokens

func (u Usage) OutputTokens() int

OutputTokens 返回包含可见思考的输出 token 数

type UsageInfo

type UsageInfo struct {
	Tier                string       `json:"tier"`
	TierCode            int          `json:"tier_code"`
	Current             *UsageWindow `json:"current,omitempty"`
	Weekly              *UsageWindow `json:"weekly,omitempty"`
	RemainingCredits    *float64     `json:"remaining_credits,omitempty"`
	UseOverageAICredits bool         `json:"use_overage_ai_credits"`
	FetchedAt           time.Time    `json:"fetched_at"`
}

UsageInfo 表示单个账号的官网用量信息

type UsageWindow

type UsageWindow struct {
	UsedRatio float64   `json:"used_ratio"`
	ResetAt   time.Time `json:"reset_at"`
}

UsageWindow 表示官网展示的一段用量窗口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL