Documentation
¶
Index ¶
- Constants
- Variables
- func ExtFromURL(rawURL, fallback string) string
- func ExtractRemixID(text string) string
- func ExtractStyle(prompt string) (string, string)
- func ExtractVideoID(text string) string
- func FormatStoryboardPrompt(prompt string) string
- func IsDataURI(s string) bool
- func IsStoryboardPrompt(prompt string) bool
- func ParseDataURI(dataURI string) (data []byte, ext string, err error)
- func ParseProxy(proxy string) string
- type CameoStatus
- type Client
- func (c *Client) CreateImageTask(ctx context.Context, accessToken, sentinelToken, prompt string, ...) (string, error)
- func (c *Client) CreateImageTaskWithImage(ctx context.Context, accessToken, sentinelToken, prompt string, ...) (string, error)
- func (c *Client) CreateStoryboardTask(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, ...) (string, error)
- func (c *Client) CreateVideoTask(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, ...) (string, error)
- func (c *Client) CreateVideoTaskWithImage(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, ...) (string, error)
- func (c *Client) CreateVideoTaskWithOptions(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, ...) (string, error)
- func (c *Client) DeleteCharacter(ctx context.Context, accessToken, characterID string) error
- func (c *Client) DeletePost(ctx context.Context, accessToken, postID string) error
- func (c *Client) DownloadCharacterImage(ctx context.Context, imageURL string) ([]byte, error)
- func (c *Client) DownloadFile(ctx context.Context, fileURL string) ([]byte, error)
- func (c *Client) EnhancePrompt(ctx context.Context, accessToken, prompt, expansionLevel string, ...) (string, error)
- func (c *Client) FinalizeCharacter(ctx context.Context, ...) (string, error)
- func (c *Client) GenerateSentinelToken(ctx context.Context, accessToken string) (string, error)
- func (c *Client) GetCameoStatus(ctx context.Context, accessToken, cameoID string) (CameoStatus, error)
- func (c *Client) GetCreditBalance(ctx context.Context, accessToken string) (CreditBalance, error)
- func (c *Client) GetDownloadURL(ctx context.Context, accessToken, taskID string) (string, error)
- func (c *Client) GetGenerationID(ctx context.Context, accessToken, taskID string) (string, error)
- func (c *Client) GetSubscriptionInfo(ctx context.Context, accessToken string) (SubscriptionInfo, error)
- func (c *Client) GetUserInfo(ctx context.Context, accessToken string) (UserInfo, error)
- func (c *Client) GetWatermarkFreeURL(ctx context.Context, accessToken, videoID string) (string, error)
- func (c *Client) PollCameoStatus(ctx context.Context, accessToken, cameoID string, ...) (CameoStatus, error)
- func (c *Client) PollImageTask(ctx context.Context, accessToken, taskID string, ...) (string, error)
- func (c *Client) PollVideoTask(ctx context.Context, accessToken, taskID string, ...) error
- func (c *Client) PublishVideo(ctx context.Context, accessToken, sentinelToken, generationID string) (string, error)
- func (c *Client) QueryImageTaskOnce(ctx context.Context, accessToken, taskID string, startTime time.Time) ImageTaskResult
- func (c *Client) QueryVideoTaskOnce(ctx context.Context, accessToken, taskID string, startTime time.Time, ...) VideoTaskResult
- func (c *Client) RefreshAccessToken(ctx context.Context, refreshToken, clientID string) (newAccessToken, newRefreshToken string, err error)
- func (c *Client) RemixVideo(ctx context.Context, ...) (string, error)
- func (c *Client) SetCharacterPrivate(ctx context.Context, accessToken, cameoID string) error
- func (c *Client) SetCharacterPublic(ctx context.Context, accessToken, cameoID string) error
- func (c *Client) SetCharacterVisibility(ctx context.Context, accessToken, cameoID, visibility string) error
- func (c *Client) TestConnectivity(ctx context.Context, targetURL string) (statusCode int, err error)
- func (c *Client) UploadCharacterImage(ctx context.Context, accessToken string, imageData []byte) (string, error)
- func (c *Client) UploadCharacterVideo(ctx context.Context, accessToken string, videoData []byte) (string, error)
- func (c *Client) UploadImage(ctx context.Context, accessToken string, imageData []byte, filename string) (string, error)
- type CreditBalance
- type ImageTaskResult
- type Progress
- type ProgressFunc
- type SubscriptionInfo
- type UserInfo
- type VideoTaskResult
Constants ¶
const DefaultSoraClientID = "app_1LOVEceTvrP2tHFDNnrPLQkJ"
DefaultSoraClientID 默认的 Sora 客户端 ID
Variables ¶
var ValidStyles = []string{
"festive", "kakalaka", "news", "selfie", "handheld",
"golden", "anime", "retro", "nostalgic", "comic",
}
ValidStyles 有效的视频风格列表
Functions ¶
func ExtFromURL ¶ added in v1.2.0
ExtFromURL 从 URL 中提取文件扩展名,默认返回 fallback
func ExtractRemixID ¶
ExtractRemixID 从文本或 URL 中提取 Remix 视频 ID 支持: https://sora.chatgpt.com/p/s_[hex32] 或直接 s_[hex32]
func ExtractStyle ¶
ExtractStyle 从提示词中提取 {style} 风格标记 返回清理后的提示词和风格 ID(无风格时为空字符串) 示例: "一只猫 {anime}" -> ("一只猫", "anime")
func ExtractVideoID ¶ added in v1.0.1
ExtractVideoID 从 Sora 分享链接或文本中提取视频 ID 支持: https://sora.chatgpt.com/p/s_xxx 或直接 s_xxx 等格式
func FormatStoryboardPrompt ¶ added in v1.0.5
FormatStoryboardPrompt 将分镜格式的提示词转换为 API 所需格式 输入: "总体描述\n[5.0s]场景1 [5.0s]场景2" 输出: "current timeline:\nShot 1:\nduration: 5.0sec\nScene: 场景1\n..."
func IsStoryboardPrompt ¶ added in v1.0.5
IsStoryboardPrompt 检测提示词是否为分镜模式格式 格式: [5.0s]场景描述 [5.0s]场景描述
func ParseDataURI ¶ added in v1.2.0
ParseDataURI 解析 data URI,返回二进制数据和对应的文件扩展名 支持格式: data:image/png;base64,iVBOR... 或 data:video/mp4;base64,AAAA...
func ParseProxy ¶
ParseProxy 解析代理字符串
支持格式:
- ip:port:username:password -> http://username:password@ip:port
- http://username:password@ip:port (原样返回)
- socks5://username:password@ip:port (原样返回)
- 空字符串 -> ""
Types ¶
type CameoStatus ¶ added in v1.0.5
type CameoStatus struct {
ID string // 角色 cameo ID
Status string // 处理状态
DisplayNameHint string // 推荐的显示名称
UsernameHint string // 推荐的用户名
ProfileAssetURL string // 角色头像 URL
}
CameoStatus 角色处理状态
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client Sora API 客户端
func (*Client) CreateImageTask ¶
func (c *Client) CreateImageTask(ctx context.Context, accessToken, sentinelToken, prompt string, width, height int) (string, error)
CreateImageTask 创建图片生成任务(文生图) 如需图生图,先调用 UploadImage 获取 mediaID,再传入 CreateImageTaskWithImage
func (*Client) CreateImageTaskWithImage ¶
func (c *Client) CreateImageTaskWithImage(ctx context.Context, accessToken, sentinelToken, prompt string, width, height int, mediaID string) (string, error)
CreateImageTaskWithImage 创建图生图任务 mediaID 为空表示文生图,非空表示图生图
func (*Client) CreateStoryboardTask ¶ added in v1.0.5
func (c *Client) CreateStoryboardTask(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, nFrames int, mediaID, styleID string) (string, error)
CreateStoryboardTask 创建分镜视频任务 prompt 应为分镜格式(会自动调用 FormatStoryboardPrompt 转换)
func (*Client) CreateVideoTask ¶
func (c *Client) CreateVideoTask(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size string) (string, error)
CreateVideoTask 创建视频生成任务(文生视频) 如需图生视频,先调用 UploadImage 获取 mediaID,再传入 CreateVideoTaskWithImage
func (*Client) CreateVideoTaskWithImage ¶
func (c *Client) CreateVideoTaskWithImage(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size, mediaID string) (string, error)
CreateVideoTaskWithImage 创建图生视频任务
func (*Client) CreateVideoTaskWithOptions ¶
func (c *Client) CreateVideoTaskWithOptions(ctx context.Context, accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size, mediaID, styleID string) (string, error)
CreateVideoTaskWithOptions 创建视频任务的完整方法 mediaID 为空表示文生视频,非空表示图生视频 styleID 为空表示无风格,可选值见 ValidStyles
func (*Client) DeleteCharacter ¶ added in v1.0.5
DeleteCharacter 删除角色
func (*Client) DeletePost ¶ added in v1.0.5
DeletePost 删除已发布的帖子
func (*Client) DownloadCharacterImage ¶ added in v1.0.5
DownloadCharacterImage 下载角色头像图片
func (*Client) DownloadFile ¶ added in v1.2.0
DownloadFile 下载 URL 内容并返回字节数据
func (*Client) EnhancePrompt ¶
func (c *Client) EnhancePrompt(ctx context.Context, accessToken, prompt, expansionLevel string, durationSec int) (string, error)
EnhancePrompt 使用 Sora 的提示词优化 API 增强提示词 expansionLevel: "medium" 或 "long" durationSec: 5、10、15 或 25
func (*Client) FinalizeCharacter ¶ added in v1.0.5
func (c *Client) FinalizeCharacter(ctx context.Context, accessToken, cameoID, username, displayName, profileAssetPointer string) (string, error)
FinalizeCharacter 定稿角色,返回 characterID
func (*Client) GenerateSentinelToken ¶
GenerateSentinelToken 获取 sentinel token(含 PoW 计算)
func (*Client) GetCameoStatus ¶ added in v1.0.5
func (c *Client) GetCameoStatus(ctx context.Context, accessToken, cameoID string) (CameoStatus, error)
GetCameoStatus 获取角色处理状态
func (*Client) GetCreditBalance ¶ added in v1.0.4
GetCreditBalance 获取当前账号的可用次数和配额信息
func (*Client) GetDownloadURL ¶
GetDownloadURL 从 drafts 接口获取下载链接
func (*Client) GetGenerationID ¶ added in v1.2.0
GetGenerationID 从 recent_tasks 或 drafts 接口获取任务的 generation ID 用于发布帖子时传入 PublishVideo
func (*Client) GetSubscriptionInfo ¶ added in v1.0.4
func (c *Client) GetSubscriptionInfo(ctx context.Context, accessToken string) (SubscriptionInfo, error)
GetSubscriptionInfo 获取当前账号的订阅信息(套餐类型、到期时间)
func (*Client) GetUserInfo ¶ added in v1.2.0
GetUserInfo 获取当前用户信息(邮箱、名称等)
func (*Client) GetWatermarkFreeURL ¶ added in v1.0.1
func (c *Client) GetWatermarkFreeURL(ctx context.Context, accessToken, videoID string) (string, error)
GetWatermarkFreeURL 获取 Sora 视频的无水印下载链接 需要使用 RefreshAccessToken 获取的 token,普通 ChatGPT access_token 不支持 videoID 为 Sora 分享链接中的视频 ID,也可以传入完整链接(自动提取 ID)
func (*Client) PollCameoStatus ¶ added in v1.0.5
func (c *Client) PollCameoStatus(ctx context.Context, accessToken, cameoID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) (CameoStatus, error)
PollCameoStatus 轮询角色处理状态直到完成
func (*Client) PollImageTask ¶
func (c *Client) PollImageTask(ctx context.Context, accessToken, taskID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) (string, error)
PollImageTask 轮询图片任务进度,返回图片 URL onProgress 可为 nil,非 nil 时在每次轮询后回调进度
func (*Client) PollVideoTask ¶
func (c *Client) PollVideoTask(ctx context.Context, accessToken, taskID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) error
PollVideoTask 轮询视频任务进度 onProgress 可为 nil,非 nil 时在每次轮询后回调进度
func (*Client) PublishVideo ¶ added in v1.0.5
func (c *Client) PublishVideo(ctx context.Context, accessToken, sentinelToken, generationID string) (string, error)
PublishVideo 发布视频帖子,返回 postID generationID 为视频的生成 ID(格式如 gen_xxx)
func (*Client) QueryImageTaskOnce ¶ added in v1.0.3
func (c *Client) QueryImageTaskOnce(ctx context.Context, accessToken, taskID string, startTime time.Time) ImageTaskResult
QueryImageTaskOnce 单次查询图片任务状态(非阻塞,供 TUI 使用)
func (*Client) QueryVideoTaskOnce ¶ added in v1.0.3
func (c *Client) QueryVideoTaskOnce(ctx context.Context, accessToken, taskID string, startTime time.Time, maxProgress int) VideoTaskResult
QueryVideoTaskOnce 单次查询视频任务状态(非阻塞,供 TUI 使用) maxProgress 应传入之前的最大进度值,返回的结果中会包含更新后的进度
func (*Client) RefreshAccessToken ¶ added in v1.0.1
func (c *Client) RefreshAccessToken(ctx context.Context, refreshToken, clientID string) (newAccessToken, newRefreshToken string, err error)
RefreshAccessToken 使用 refresh_token 获取新的 access_token 返回新的 accessToken 和 refreshToken(OpenAI 每次刷新都会返回新的 refresh_token)
func (*Client) RemixVideo ¶
func (c *Client) RemixVideo(ctx context.Context, accessToken, sentinelToken, remixTargetID, prompt, orientation string, nFrames int, styleID string) (string, error)
RemixVideo 基于已有视频创建 Remix 任务 remixTargetID 为 Sora 分享链接中的视频 ID,格式: s_[hex32]
func (*Client) SetCharacterPrivate ¶ added in v1.2.0
SetCharacterPrivate 设置角色为私密
func (*Client) SetCharacterPublic ¶ added in v1.0.5
SetCharacterPublic 设置角色为公开
func (*Client) SetCharacterVisibility ¶ added in v1.2.0
func (c *Client) SetCharacterVisibility(ctx context.Context, accessToken, cameoID, visibility string) error
SetCharacterVisibility 设置角色可见性(public/private)
func (*Client) TestConnectivity ¶ added in v1.2.0
func (c *Client) TestConnectivity(ctx context.Context, targetURL string) (statusCode int, err error)
TestConnectivity 测试代理连通性,向目标 URL 发送 GET 请求,只要收到响应即视为成功
func (*Client) UploadCharacterImage ¶ added in v1.0.5
func (c *Client) UploadCharacterImage(ctx context.Context, accessToken string, imageData []byte) (string, error)
UploadCharacterImage 上传角色头像图片,返回 assetPointer imageData 为图片二进制数据(webp 格式)
type CreditBalance ¶ added in v1.0.4
type CreditBalance struct {
RemainingCount int // 剩余可用次数
RateLimitReached bool // 是否触发速率限制
AccessResetsInSec int // 访问权限重置时间(秒)
}
CreditBalance 配额信息
type ImageTaskResult ¶ added in v1.0.3
ImageTaskResult 图片任务单次查询结果
type SubscriptionInfo ¶ added in v1.0.4
type SubscriptionInfo struct {
PlanID string // 套餐类型,例如 "chatgptplusplan"
PlanTitle string // 套餐名称,例如 "ChatGPT Plus"
EndTs int64 // 订阅到期时间戳(秒)
}
SubscriptionInfo 订阅信息
type VideoTaskResult ¶ added in v1.0.3
VideoTaskResult 视频任务单次查询结果