完善文档页文本向量与重排序调用支持

This commit is contained in:
2026-05-31 21:18:41 +08:00
parent 8ee7a7969e
commit 644a6f9d17
24 changed files with 1945 additions and 71 deletions
+49 -3
View File
@@ -698,7 +698,7 @@ func (s *Service) recordTaskParameterPreprocessing(ctx context.Context, taskID s
func skipTaskParameterPreprocessingLog(modelType string) bool {
switch strings.TrimSpace(modelType) {
case "text_generate", "chat", "responses", "text":
case "text_generate", "text_embedding", "text_rerank", "chat", "responses", "text":
return true
default:
return false
@@ -923,6 +923,10 @@ func modelTypeFromKind(kind string, body map[string]any) string {
switch kind {
case "chat.completions", "responses":
return "text_generate"
case "embeddings":
return "text_embedding"
case "reranks":
return "text_rerank"
case "images.generations", "images.edits":
if kind == "images.edits" {
return "image_edit"
@@ -943,7 +947,7 @@ func modelTypeFromKind(kind string, body map[string]any) string {
func requestedModelTypeFromBody(body map[string]any) string {
for _, key := range []string{"modelType", "model_type", "capability", "capabilityType"} {
value := strings.TrimSpace(stringFromMap(body, key))
value := canonicalModelType(strings.TrimSpace(stringFromMap(body, key)))
if isKnownModelType(value) {
return value
}
@@ -951,9 +955,21 @@ func requestedModelTypeFromBody(body map[string]any) string {
return ""
}
func canonicalModelType(value string) string {
normalized := strings.ReplaceAll(strings.ToLower(strings.TrimSpace(value)), "-", "_")
switch normalized {
case "embedding":
return "text_embedding"
case "rerank", "reranks":
return "text_rerank"
default:
return normalized
}
}
func isKnownModelType(value string) bool {
switch value {
case "text_generate", "image_generate", "image_edit", "video_generate", "image_to_video", "text_to_video", "video_edit", "video_reference", "video_first_last_frame", "omni_video", "omni":
case "text_generate", "text_embedding", "text_rerank", "image_generate", "image_edit", "video_generate", "image_to_video", "text_to_video", "video_edit", "video_reference", "video_first_last_frame", "omni_video", "omni":
return true
default:
return false
@@ -1001,6 +1017,14 @@ func isTextGenerationKind(kind string) bool {
return kind == "chat.completions" || kind == "responses"
}
func isTextInputOnlyKind(kind string) bool {
return kind == "embeddings" || kind == "reranks"
}
func isTextBillingKind(kind string) bool {
return isTextGenerationKind(kind) || isTextInputOnlyKind(kind)
}
func isSimulation(task store.GatewayTask, candidate store.RuntimeModelCandidate) bool {
if task.RunMode == "simulation" {
return true
@@ -1115,6 +1139,17 @@ func validateRequest(kind string, body map[string]any) error {
if body["input"] == nil && body["messages"] == nil {
return errors.New("input or messages is required")
}
case "embeddings":
if body["input"] == nil {
return errors.New("input is required")
}
case "reranks":
if body["query"] == nil {
return errors.New("query is required")
}
if !hasRerankDocuments(body["documents"]) {
return errors.New("documents is required")
}
case "images.generations", "images.edits":
if strings.TrimSpace(stringFromMap(body, "prompt")) == "" {
return errors.New("prompt is required")
@@ -1123,6 +1158,17 @@ func validateRequest(kind string, body map[string]any) error {
return nil
}
func hasRerankDocuments(value any) bool {
switch typed := value.(type) {
case []any:
return len(typed) > 0
case []string:
return len(typed) > 0
default:
return false
}
}
func parameterPreprocessClientError(err error) *clients.ClientError {
if err == nil {
return nil