迁移音频生成与语音合成到 gateway 并补充 simulation 测试
This commit is contained in:
@@ -15,6 +15,8 @@ const (
|
||||
defaultSimulationTextMaxDuration = 2400 * time.Millisecond
|
||||
defaultSimulationImageMinDuration = 10 * time.Second
|
||||
defaultSimulationImageMaxDuration = 30 * time.Second
|
||||
defaultSimulationAudioMinDuration = 2 * time.Second
|
||||
defaultSimulationAudioMaxDuration = 6 * time.Second
|
||||
defaultSimulationVideoMinDuration = 2 * time.Minute
|
||||
defaultSimulationVideoMaxDuration = 3 * time.Minute
|
||||
maxSimulationDuration = 10 * time.Minute
|
||||
@@ -156,6 +158,24 @@ func simulatedResult(request Request) map[string]any {
|
||||
"model": request.Model,
|
||||
"data": simulatedVideoData(request),
|
||||
}
|
||||
case "song.generations", "music.generations":
|
||||
return map[string]any{
|
||||
"id": "song-simulated",
|
||||
"created": nowUnix(),
|
||||
"model": request.Model,
|
||||
"status": "success",
|
||||
"data": simulatedAudioData(request, "simulation music"),
|
||||
"message": "simulation music generated",
|
||||
}
|
||||
case "speech.generations":
|
||||
return map[string]any{
|
||||
"id": "speech-simulated",
|
||||
"created": nowUnix(),
|
||||
"model": request.Model,
|
||||
"status": "success",
|
||||
"data": simulatedAudioData(request, "simulation speech"),
|
||||
"message": "simulation speech generated",
|
||||
}
|
||||
default:
|
||||
modelType := strings.ToLower(request.ModelType)
|
||||
kind := strings.ToLower(request.Kind)
|
||||
@@ -167,6 +187,15 @@ func simulatedResult(request Request) map[string]any {
|
||||
"data": simulatedVideoData(request),
|
||||
}
|
||||
}
|
||||
if strings.Contains(modelType, "audio") || strings.Contains(modelType, "speech") || strings.Contains(kind, "audio") || strings.Contains(kind, "song") || strings.Contains(kind, "music") || strings.Contains(kind, "speech") {
|
||||
return map[string]any{
|
||||
"id": "audio-simulated",
|
||||
"created": nowUnix(),
|
||||
"model": request.Model,
|
||||
"status": "success",
|
||||
"data": simulatedAudioData(request, "simulation audio"),
|
||||
}
|
||||
}
|
||||
return map[string]any{
|
||||
"id": "img-simulated",
|
||||
"created": nowUnix(),
|
||||
@@ -307,6 +336,24 @@ func simulatedVideoData(request Request) []any {
|
||||
return items
|
||||
}
|
||||
|
||||
func simulatedAudioData(request Request, fallbackPrompt string) []any {
|
||||
count := simulatedOutputCount(request.Body)
|
||||
items := make([]any, 0, count)
|
||||
for index := 0; index < count; index += 1 {
|
||||
items = append(items, map[string]any{
|
||||
"type": "audio",
|
||||
"url": "/static/simulation/audio.wav",
|
||||
"audio_url": "/static/simulation/audio.wav",
|
||||
"duration": simulatedAudioDurationSeconds(request),
|
||||
"assetSource": "simulation",
|
||||
"index": index,
|
||||
"prompt": firstNonEmptyPrompt(request.Body, fallbackPrompt),
|
||||
"revised_text": firstNonEmptyString(stringValue(request.Body, "text"), firstNonEmptyPrompt(request.Body, fallbackPrompt)),
|
||||
})
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
func simulatedUsage(request Request) Usage {
|
||||
if request.ModelType == "chat" || request.ModelType == "text_generate" || request.Kind == "responses" {
|
||||
return Usage{InputTokens: 12, OutputTokens: 8, TotalTokens: 20}
|
||||
@@ -368,6 +415,9 @@ func defaultSimulationDurationRange(request Request) (time.Duration, time.Durati
|
||||
if simulationImageRequest(request) {
|
||||
return defaultSimulationImageMinDuration, defaultSimulationImageMaxDuration
|
||||
}
|
||||
if simulationAudioRequest(request) {
|
||||
return defaultSimulationAudioMinDuration, defaultSimulationAudioMaxDuration
|
||||
}
|
||||
return defaultSimulationTextMinDuration, defaultSimulationTextMaxDuration
|
||||
}
|
||||
|
||||
@@ -383,6 +433,12 @@ func simulationImageRequest(request Request) bool {
|
||||
return strings.Contains(kind, "image") || strings.Contains(modelType, "image")
|
||||
}
|
||||
|
||||
func simulationAudioRequest(request Request) bool {
|
||||
kind := strings.ToLower(request.Kind)
|
||||
modelType := strings.ToLower(request.ModelType)
|
||||
return strings.Contains(kind, "audio") || strings.Contains(kind, "song") || strings.Contains(kind, "music") || strings.Contains(kind, "speech") || strings.Contains(modelType, "audio") || strings.Contains(modelType, "speech")
|
||||
}
|
||||
|
||||
func simulationDurationSeconds(request Request, keys ...string) int {
|
||||
for _, source := range []map[string]any{request.Body, request.Candidate.PlatformConfig, request.Candidate.Credentials} {
|
||||
for _, key := range keys {
|
||||
@@ -440,6 +496,16 @@ func simulatedVideoDurationSeconds(request Request) int {
|
||||
return 5
|
||||
}
|
||||
|
||||
func simulatedAudioDurationSeconds(request Request) int {
|
||||
if duration := intValue(request.Body, "duration", 0); duration > 0 {
|
||||
return duration
|
||||
}
|
||||
if seconds := len([]rune(stringValue(request.Body, "text"))) / 8; seconds > 0 {
|
||||
return seconds
|
||||
}
|
||||
return 3
|
||||
}
|
||||
|
||||
func firstNonEmptyPrompt(body map[string]any, fallback string) string {
|
||||
for _, key := range []string{"prompt", "input"} {
|
||||
if value := strings.TrimSpace(stringValue(body, key)); value != "" {
|
||||
|
||||
Reference in New Issue
Block a user