sora

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ValidStyles = []string{
	"festive", "kakalaka", "news", "selfie", "handheld",
	"golden", "anime", "retro", "nostalgic", "comic",
}

ValidStyles 有效的视频风格列表

Functions

func ExtractRemixID

func ExtractRemixID(text string) string

ExtractRemixID 从文本或 URL 中提取 Remix 视频 ID 支持: https://sora.chatgpt.com/p/s_[hex32] 或直接 s_[hex32]

func ExtractStyle

func ExtractStyle(prompt string) (string, string)

ExtractStyle 从提示词中提取 {style} 风格标记 返回清理后的提示词和风格 ID(无风格时为空字符串) 示例: "一只猫 {anime}" -> ("一只猫", "anime")

func ParseProxy

func ParseProxy(proxy string) string

ParseProxy 解析代理字符串

支持格式:

Types

type Client

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

Client Sora API 客户端

func New

func New(proxyURL string) (*Client, error)

New 创建客户端,proxyURL 为空则不使用代理

func (*Client) CreateImageTask

func (c *Client) CreateImageTask(accessToken, sentinelToken, prompt string, width, height int) (string, error)

CreateImageTask 创建图片生成任务(文生图) 如需图生图,先调用 UploadImage 获取 mediaID,再传入 CreateImageTaskWithImage

func (*Client) CreateImageTaskWithImage

func (c *Client) CreateImageTaskWithImage(accessToken, sentinelToken, prompt string, width, height int, mediaID string) (string, error)

CreateImageTaskWithImage 创建图生图任务 mediaID 为空表示文生图,非空表示图生图

func (*Client) CreateVideoTask

func (c *Client) CreateVideoTask(accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size string) (string, error)

CreateVideoTask 创建视频生成任务(文生视频) 如需图生视频,先调用 UploadImage 获取 mediaID,再传入 CreateVideoTaskWithImage

func (*Client) CreateVideoTaskWithImage

func (c *Client) CreateVideoTaskWithImage(accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size, mediaID string) (string, error)

CreateVideoTaskWithImage 创建图生视频任务

func (*Client) CreateVideoTaskWithOptions

func (c *Client) CreateVideoTaskWithOptions(accessToken, sentinelToken, prompt, orientation string, nFrames int, model, size, mediaID, styleID string) (string, error)

CreateVideoTaskWithOptions 创建视频任务的完整方法 mediaID 为空表示文生视频,非空表示图生视频 styleID 为空表示无风格,可选值见 ValidStyles

func (*Client) EnhancePrompt

func (c *Client) EnhancePrompt(accessToken, prompt, expansionLevel string, durationSec int) (string, error)

EnhancePrompt 使用 Sora 的提示词优化 API 增强提示词 expansionLevel: "medium" 或 "long" durationSec: 10、15 或 20

func (*Client) GenerateSentinelToken

func (c *Client) GenerateSentinelToken(accessToken string) (string, error)

GenerateSentinelToken 获取 sentinel token(含 PoW 计算)

func (*Client) GetDownloadURL

func (c *Client) GetDownloadURL(accessToken, taskID string) (string, error)

GetDownloadURL 从 drafts 接口获取下载链接

func (*Client) PollImageTask

func (c *Client) PollImageTask(accessToken, taskID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) (string, error)

PollImageTask 轮询图片任务进度,返回图片 URL onProgress 可为 nil,非 nil 时在每次轮询后回调进度

func (*Client) PollVideoTask

func (c *Client) PollVideoTask(accessToken, taskID string, pollInterval, pollTimeout time.Duration, onProgress ProgressFunc) error

PollVideoTask 轮询视频任务进度 onProgress 可为 nil,非 nil 时在每次轮询后回调进度

func (*Client) RemixVideo

func (c *Client) RemixVideo(accessToken, sentinelToken, remixTargetID, prompt, orientation string, nFrames int, styleID string) (string, error)

RemixVideo 基于已有视频创建 Remix 任务 remixTargetID 为 Sora 分享链接中的视频 ID,格式: s_[hex32]

func (*Client) UploadImage

func (c *Client) UploadImage(accessToken string, imageData []byte, filename string) (string, error)

UploadImage 上传图片,返回 mediaID,用于图生图/图生视频 imageData 为图片二进制数据,filename 为文件名(如 "image.png")

type Progress

type Progress struct {
	Percent int    // 进度百分比 0-100
	Status  string // 任务状态
	Elapsed int    // 已耗时(秒)
}

Progress 任务进度信息

type ProgressFunc

type ProgressFunc func(Progress)

ProgressFunc 进度回调函数类型

Jump to

Keyboard shortcuts

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