fix(protocol): OpenAI 兼容插件 - 请求路径不再硬编码 /v1 前缀 (#399)

This commit is contained in:
Dade authored and GitHub committed 2026-09-02 20:19:33 +08:00
1 parent a0b65006fb
commit 9fed0aa324
6 files changed
+10 -8

No files matched your search

+2 -2
View File
@@ -5,12 +5,14 @@ go 1.25.0
require ( require (
github.com/aws/aws-sdk-go v1.40.45 github.com/aws/aws-sdk-go v1.40.45
github.com/gin-gonic/gin v1.12.0 github.com/gin-gonic/gin v1.12.0
github.com/google/uuid v1.5.0
github.com/qiniu/go-sdk/v7 v7.27.0 github.com/qiniu/go-sdk/v7 v7.27.0
github.com/redis/go-redis/v9 v9.22.0 github.com/redis/go-redis/v9 v9.22.0
github.com/tencentyun/cos-go-sdk-v5 v0.7.75 github.com/tencentyun/cos-go-sdk-v5 v0.7.75
github.com/volcengine/volc-sdk-golang v1.0.253 github.com/volcengine/volc-sdk-golang v1.0.253
golang.org/x/crypto v0.54.0 golang.org/x/crypto v0.54.0
golang.org/x/net v0.57.0 golang.org/x/net v0.57.0
golang.org/x/sync v0.22.0
gorm.io/driver/postgres v1.6.2 gorm.io/driver/postgres v1.6.2
gorm.io/driver/sqlite v1.6.0 gorm.io/driver/sqlite v1.6.0
gorm.io/gorm v1.31.2 gorm.io/gorm v1.31.2
@@ -35,7 +37,6 @@ require (
github.com/goccy/go-yaml v1.19.2 // indirect github.com/goccy/go-yaml v1.19.2 // indirect
github.com/gofrs/flock v0.8.1 // indirect github.com/gofrs/flock v0.8.1 // indirect
github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.10.0 // indirect github.com/jackc/pgx/v5 v5.10.0 // indirect
@@ -60,7 +61,6 @@ require (
go.mongodb.org/mongo-driver/v2 v2.8.0 // indirect go.mongodb.org/mongo-driver/v2 v2.8.0 // indirect
go.uber.org/atomic v1.11.0 // indirect go.uber.org/atomic v1.11.0 // indirect
golang.org/x/arch v0.29.0 // indirect golang.org/x/arch v0.29.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.40.0 // indirect golang.org/x/text v0.40.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect google.golang.org/protobuf v1.36.11 // indirect
@@ -129,11 +129,11 @@ func TestOfficialAgentProfilesMapToolRequestsAndResponses(t *testing.T) {
name, packageName, providerID, marker, wantPath, response, wantID, wantSignature string name, packageName, providerID, marker, wantPath, response, wantID, wantSignature string
}{ }{
{ {
name: "openai-chat", packageName: "openai-chat-completions.yingce-plugin", providerID: "chat-completion", marker: "chat", wantPath: "/v1/chat/completions", wantID: "call-chat", name: "openai-chat", packageName: "openai-chat-completions.yingce-plugin", providerID: "chat-completion", marker: "chat", wantPath: "/chat/completions", wantID: "call-chat",
response: `{"choices":[{"message":{"content":"chat answer","tool_calls":[{"id":"call-chat","function":{"name":"canvas_get_state","arguments":"{\"scope\":\"all\"}"}}]}}]}`, response: `{"choices":[{"message":{"content":"chat answer","tool_calls":[{"id":"call-chat","function":{"name":"canvas_get_state","arguments":"{\"scope\":\"all\"}"}}]}}]}`,
}, },
{ {
name: "openai-responses", packageName: "openai-responses.yingce-plugin", providerID: "openai-response", marker: "responses", wantPath: "/v1/responses", wantID: "call-responses", name: "openai-responses", packageName: "openai-responses.yingce-plugin", providerID: "openai-response", marker: "responses", wantPath: "/responses", wantID: "call-responses",
response: `{"output_text":"responses answer","output":[{"type":"message"},{"type":"function_call","call_id":"call-responses","name":"canvas_get_state","arguments":"{\"scope\":\"all\"}"}]}`, response: `{"output_text":"responses answer","output":[{"type":"message"},{"type":"function_call","call_id":"call-responses","name":"canvas_get_state","arguments":"{\"scope\":\"all\"}"}]}`,
}, },
{ {
@@ -59,6 +59,8 @@ func TestChannelAPIURLNormalizesConfiguredVersionPrefix(t *testing.T) {
{name: "same v1beta is not duplicated", base: "http://provider.test:8000/v1beta", path: "/v1beta/models/model", want: "http://provider.test:8000/v1beta/models/model"}, {name: "same v1beta is not duplicated", base: "http://provider.test:8000/v1beta", path: "/v1beta/models/model", want: "http://provider.test:8000/v1beta/models/model"},
{name: "path carries v2", base: "http://provider.test:8000/v1", path: "/v2/tasks", want: "http://provider.test:8000/v2/tasks"}, {name: "path carries v2", base: "http://provider.test:8000/v1", path: "/v2/tasks", want: "http://provider.test:8000/v2/tasks"},
{name: "ark v3", base: "https://ark.example.com/api/v3", path: "/images/generations", want: "https://ark.example.com/api/v3/images/generations"}, {name: "ark v3", base: "https://ark.example.com/api/v3", path: "/images/generations", want: "https://ark.example.com/api/v3/images/generations"},
{name: "ark v3 chat", base: "https://ark.example.com/api/v3", path: "/chat/completions", want: "https://ark.example.com/api/v3/chat/completions"},
{name: "ark v3 responses", base: "https://ark.example.com/api/v3", path: "/responses", want: "https://ark.example.com/api/v3/responses"},
{name: "path carries ark v3", base: "https://ark.example.com", path: "/api/v3/images/generations", want: "https://ark.example.com/api/v3/images/generations"}, {name: "path carries ark v3", base: "https://ark.example.com", path: "/api/v3/images/generations", want: "https://ark.example.com/api/v3/images/generations"},
{name: "path carries autodl api v1", base: "https://autodl.art", path: "/api/v1/comfyui/comfyui_workflow/workflow-1", want: "https://autodl.art/api/v1/comfyui/comfyui_workflow/workflow-1"}, {name: "path carries autodl api v1", base: "https://autodl.art", path: "/api/v1/comfyui/comfyui_workflow/workflow-1", want: "https://autodl.art/api/v1/comfyui/comfyui_workflow/workflow-1"},
} }
+4 -4
View File
@@ -86,7 +86,7 @@ function add(spec) {
add({ add({
id: "openai-chat-completions", providerId: "chat-completion", name: "OpenAI Chat Completions", vendor: "OpenAI", capability: "text", id: "openai-chat-completions", providerId: "chat-completion", name: "OpenAI Chat Completions", vendor: "OpenAI", capability: "text",
baseUrl: "https://api.openai.com", auth: bearer, params: textParams, baseUrl: "https://api.openai.com", auth: bearer, params: textParams,
create: jsonCreate("/v1/chat/completions", { create: jsonCreate("/chat/completions", {
model: ref("request.model"), messages: ref("request.messages"), model: ref("request.model"), messages: ref("request.messages"),
temperature: omit(ref("request.providerOptions.chat-completion.temperature")), temperature: omit(ref("request.providerOptions.chat-completion.temperature")),
top_p: omit(ref("request.providerOptions.chat-completion.top_p")), top_p: omit(ref("request.providerOptions.chat-completion.top_p")),
@@ -103,7 +103,7 @@ add({
top_logprobs: omit(ref("request.providerOptions.chat-completion.top_logprobs")), top_logprobs: omit(ref("request.providerOptions.chat-completion.top_logprobs")),
user: omit(ref("request.providerOptions.chat-completion.user")) user: omit(ref("request.providerOptions.chat-completion.user"))
}), }),
agent: jsonCreate("/v1/chat/completions", { $merge: [ref("request.extra.agent.chatCompletion"), { model: ref("request.model") }] }), agent: jsonCreate("/chat/completions", { $merge: [ref("request.extra.agent.chatCompletion"), { model: ref("request.model") }] }),
agentResponse: { textPaths: ["choices.0.message.content", "choices.0.text"], reasoningPaths: ["choices.0.message.reasoning_content"], toolCallsPath: "choices.0.message.tool_calls", toolCallIdPaths: ["id"], toolCallNamePaths: ["function.name"], toolCallArgumentsPaths: ["function.arguments"] }, agentResponse: { textPaths: ["choices.0.message.content", "choices.0.text"], reasoningPaths: ["choices.0.message.reasoning_content"], toolCallsPath: "choices.0.message.tool_calls", toolCallIdPaths: ["id"], toolCallNamePaths: ["function.name"], toolCallArgumentsPaths: ["function.arguments"] },
response: { status: "succeeded", textPaths: ["choices.0.message.content", "choices.0.text"], reasoningPaths: ["choices.0.message.reasoning_content"], usage: ref("response.usage"), errorPaths: ["error.code"], messagePaths: ["error.message"] } response: { status: "succeeded", textPaths: ["choices.0.message.content", "choices.0.text"], reasoningPaths: ["choices.0.message.reasoning_content"], usage: ref("response.usage"), errorPaths: ["error.code"], messagePaths: ["error.message"] }
}); });
@@ -111,7 +111,7 @@ add({
add({ add({
id: "openai-responses", providerId: "openai-response", name: "OpenAI Responses", vendor: "OpenAI", capability: "text", id: "openai-responses", providerId: "openai-response", name: "OpenAI Responses", vendor: "OpenAI", capability: "text",
baseUrl: "https://api.openai.com", auth: bearer, params: textParams, baseUrl: "https://api.openai.com", auth: bearer, params: textParams,
create: jsonCreate("/v1/responses", { create: jsonCreate("/responses", {
model: ref("request.model"), input: ref("request.messages"), instructions: omit(ref("request.instructions")), model: ref("request.model"), input: ref("request.messages"), instructions: omit(ref("request.instructions")),
temperature: omit(ref("request.providerOptions.openai-response.temperature")), temperature: omit(ref("request.providerOptions.openai-response.temperature")),
top_p: omit(ref("request.providerOptions.openai-response.top_p")), top_p: omit(ref("request.providerOptions.openai-response.top_p")),
@@ -123,7 +123,7 @@ add({
stream: omit(ref("request.providerOptions.openai-response.stream")), truncation: omit(ref("request.providerOptions.openai-response.truncation")), stream: omit(ref("request.providerOptions.openai-response.stream")), truncation: omit(ref("request.providerOptions.openai-response.truncation")),
user: omit(ref("request.providerOptions.openai-response.user")) user: omit(ref("request.providerOptions.openai-response.user"))
}), }),
agent: jsonCreate("/v1/responses", { $merge: [ref("request.extra.agent.responses"), { model: ref("request.model") }] }), agent: jsonCreate("/responses", { $merge: [ref("request.extra.agent.responses"), { model: ref("request.model") }] }),
agentResponse: { textPaths: ["output_text"], reasoningPaths: ["reasoning.summary.0.text"], toolCallsPath: "output", toolCallIdPaths: ["call_id", "id"], toolCallNamePaths: ["name"], toolCallArgumentsPaths: ["arguments"] }, agentResponse: { textPaths: ["output_text"], reasoningPaths: ["reasoning.summary.0.text"], toolCallsPath: "output", toolCallIdPaths: ["call_id", "id"], toolCallNamePaths: ["name"], toolCallArgumentsPaths: ["arguments"] },
response: { status: "succeeded", textPaths: ["output_text"], reasoningPaths: ["reasoning.summary.0.text"], usage: ref("response.usage"), errorPaths: ["error.code"], messagePaths: ["error.message"] } response: { status: "succeeded", textPaths: ["output_text"], reasoningPaths: ["reasoning.summary.0.text"], usage: ref("response.usage"), errorPaths: ["error.code"], messagePaths: ["error.message"] }
}); });
Binary file not shown.