Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractRemixID(text string) string
- func ExtractStyle(prompt string) (string, string)
- func ExtractVideoID(text string) string
- func ParseProxy(proxy string) string
- type Client
- func (c *Client) CreateImageTask(accessToken, sentinelToken, prompt string, width, height int) (string, error)
- func (c *Client) CreateImageTaskWithImage(accessToken, sentinelToken, prompt string, width, height int, mediaID string) (string, error)
- func (c *Client) CreateVideoTask(accessToken, sentinelToken, prompt, orientation string, nFrames int, ...) (string, error)
- func (c *Client) CreateVideoTaskWithImage(accessToken, sentinelToken, prompt, orientation string, nFrames int, ...) (string, error)
- func (c *Client) CreateVideoTaskWithOptions(accessToken, sentinelToken, prompt, orientation string, nFrames int, ...) (string, error)
- func (c *Client) EnhancePrompt(accessToken, prompt, expansionLevel string, durationSec int) (string, error)
- func (c *Client) GenerateSentinelToken(accessToken string) (string, error)
- func (c *Client) GetDownloadURL(accessToken, taskID string) (string, error)
- func (c *Client) GetWatermarkFreeURL(accessToken, videoID string) (string, error)
- func (c *Client) PollImageTask(accessToken, taskID string, pollInterval, pollTimeout time.Duration, ...) (string, error)
- func (c *Client) PollVideoTask(accessToken, taskID string, pollInterval, pollTimeout time.Duration, ...) error
- func (c *Client) RefreshAccessToken(refreshToken, clientID string) (newAccessToken, newRefreshToken string, err error)
- func (c *Client) RemixVideo(accessToken, sentinelToken, remixTargetID, prompt, orientation string, ...) (string, error)
- func (c *Client) UploadImage(accessToken string, imageData []byte, filename string) (string, error)
- type Progress
- type ProgressFunc
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 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 ParseProxy ¶
ParseProxy 解析代理字符串
支持格式:
- ip:port:username:password -> http://username:password@ip:port
- http://username:password@ip:port (原样返回)
- socks5://username:password@ip:port (原样返回)
- 空字符串 -> ""
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client Sora API 客户端
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 ¶
GenerateSentinelToken 获取 sentinel token(含 PoW 计算)
func (*Client) GetDownloadURL ¶
GetDownloadURL 从 drafts 接口获取下载链接
func (*Client) GetWatermarkFreeURL ¶ added in v1.0.1
GetWatermarkFreeURL 获取 Sora 视频的无水印下载链接 需要使用 RefreshAccessToken 获取的 token,普通 ChatGPT access_token 不支持 videoID 为 Sora 分享链接中的视频 ID,也可以传入完整链接(自动提取 ID)
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) RefreshAccessToken ¶ added in v1.0.1
func (c *Client) RefreshAccessToken(refreshToken, clientID string) (newAccessToken, newRefreshToken string, err error)
RefreshAccessToken 使用 refresh_token 获取新的 access_token 返回新的 accessToken 和 refreshToken(OpenAI 每次刷新都会返回新的 refresh_token)