完善文档页文本向量与重排序调用支持
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
|
||||
)
|
||||
|
||||
type OpenAIClient struct {
|
||||
@@ -27,10 +29,10 @@ func (c OpenAIClient) Run(ctx context.Context, request Request) (Response, error
|
||||
body = NormalizeChatCompletionRequestBody(body)
|
||||
}
|
||||
body["model"] = upstreamModelName(request.Candidate)
|
||||
stream := request.Stream || boolValue(body, "stream")
|
||||
stream := openAIEndpointSupportsStream(request.Kind) && (request.Stream || boolValue(body, "stream"))
|
||||
ensureOpenAIStreamUsage(body, request.Kind, stream)
|
||||
raw, _ := json.Marshal(body)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, joinURL(request.Candidate.BaseURL, endpoint), bytes.NewReader(raw))
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, joinURL(openAIBaseURL(request.Kind, request.Candidate), endpoint), bytes.NewReader(raw))
|
||||
if err != nil {
|
||||
return Response{}, err
|
||||
}
|
||||
@@ -81,6 +83,10 @@ func openAIEndpoint(kind string) string {
|
||||
return "/chat/completions"
|
||||
case "responses":
|
||||
return "/responses"
|
||||
case "embeddings":
|
||||
return "/embeddings"
|
||||
case "reranks":
|
||||
return "/reranks"
|
||||
case "images.generations":
|
||||
return "/images/generations"
|
||||
case "images.edits":
|
||||
@@ -90,6 +96,24 @@ func openAIEndpoint(kind string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func openAIEndpointSupportsStream(kind string) bool {
|
||||
return kind == "chat.completions" || kind == "responses"
|
||||
}
|
||||
|
||||
func openAIBaseURL(kind string, candidate store.RuntimeModelCandidate) string {
|
||||
base := strings.TrimSpace(candidate.BaseURL)
|
||||
if kind != "reranks" {
|
||||
return base
|
||||
}
|
||||
if strings.Contains(base, "/compatible-mode/") && (strings.EqualFold(candidate.Provider, "aliyun-bailian-openai") || strings.Contains(base, "dashscope")) {
|
||||
return strings.Replace(base, "/compatible-mode/", "/compatible-api/", 1)
|
||||
}
|
||||
if base == "" && strings.EqualFold(candidate.Provider, "aliyun-bailian-openai") {
|
||||
return "https://dashscope.aliyuncs.com/compatible-api/v1"
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
func cloneBody(body map[string]any) map[string]any {
|
||||
out := map[string]any{}
|
||||
for key, value := range body {
|
||||
|
||||
Reference in New Issue
Block a user