- POST /ai/v1/tts:xAI 官方 TTS 格式转换层(text/voice_id→input/voice),复用 Speech 编排,model 缺省 xai.grok-tts;实测 output_format/speed 透传生效 - 「过滤弃用模型」开关(GET/PUT /api/v1/ai-settings,settings 表持久化):开启后已宣布弃用(未退役)模型从列表与路由排除;同步入库与退役提醒不受影响 - AI 网关文档更名 docs/AI网关.md,补 tts 矩阵段与开关说明;README 引用同步 - CHANGELOG 0.5.0(0.4.0 已发版冻结);DASH_VERSION v0.5.0
64 lines
2.5 KiB
Go
64 lines
2.5 KiB
Go
package aiwire
|
|
|
|
import "encoding/json"
|
|
|
|
// ModerationsRequest 是 /ai/v1/moderations 请求体;input 兼容 OpenAI 的
|
|
// string 与 []string 两种形态,model 字段接受但忽略(上游为服务级 API)。
|
|
type ModerationsRequest struct {
|
|
Model string `json:"model,omitempty"`
|
|
Input json.RawMessage `json:"input"`
|
|
}
|
|
|
|
// ModerationPii 是一处 PII 命中(OCI 扩展,OpenAI 协议无对应物)。
|
|
type ModerationPii struct {
|
|
Text string `json:"text"`
|
|
Label string `json:"label"`
|
|
Score float64 `json:"score"`
|
|
Offset int `json:"offset"`
|
|
Length int `json:"length"`
|
|
}
|
|
|
|
// ModerationResult 是一条输入的审核结果:categories / category_scores 用
|
|
// OCI 原生维度(overall / blocklist / prompt_injection),pii 为扩展字段。
|
|
type ModerationResult struct {
|
|
Flagged bool `json:"flagged"`
|
|
Categories map[string]bool `json:"categories"`
|
|
CategoryScores map[string]float64 `json:"category_scores"`
|
|
Pii []ModerationPii `json:"pii,omitempty"`
|
|
}
|
|
|
|
// ModerationsResponse 是 /ai/v1/moderations 响应体(OpenAI moderations 外壳)。
|
|
type ModerationsResponse struct {
|
|
ID string `json:"id"`
|
|
Model string `json:"model"`
|
|
Results []ModerationResult `json:"results"`
|
|
}
|
|
|
|
// SpeechRequest 描述 /ai/v1/audio/speech 请求体的已知字段(文档用途)。
|
|
// 直通端点实际按原样透传,未列字段与 xAI 专属参数(如 output_format)同样保留。
|
|
type SpeechRequest struct {
|
|
Model string `json:"model"`
|
|
Input string `json:"input"`
|
|
Voice string `json:"voice,omitempty"`
|
|
ResponseFormat string `json:"response_format,omitempty"`
|
|
Language string `json:"language,omitempty"`
|
|
}
|
|
|
|
// TtsRequest 描述 /ai/v1/tts 请求体的已知字段(xAI 官方 TTS 格式,文档用途)。
|
|
// model 为网关扩展字段(缺省 xai.grok-tts);未列字段原样透传上游。
|
|
type TtsRequest struct {
|
|
Model string `json:"model,omitempty"`
|
|
Text string `json:"text"`
|
|
Language string `json:"language"`
|
|
VoiceID string `json:"voice_id,omitempty"`
|
|
OutputFormat *TtsOutputFormat `json:"output_format,omitempty"`
|
|
Speed float64 `json:"speed,omitempty"`
|
|
}
|
|
|
|
// TtsOutputFormat 是 xAI TTS 输出格式配置(缺省 MP3 24kHz/128kbps)。
|
|
type TtsOutputFormat struct {
|
|
Codec string `json:"codec,omitempty"`
|
|
SampleRate int `json:"sample_rate,omitempty"`
|
|
BitRate int `json:"bit_rate,omitempty"`
|
|
}
|