From b217720868a174bdfa94b30ecfa8aff4c667e444 Mon Sep 17 00:00:00 2001 From: hanxiantao <601803023@qq.com> Date: Thu, 30 Jan 2025 19:42:51 +0800 Subject: [PATCH] =?UTF-8?q?ai-proxy=20e2e=20test=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=99=BE=E5=BA=A6=E9=97=AE=E5=BF=83=E4=B8=80=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../e2e/conformance/tests/go-wasm-ai-proxy.go | 60 +++++++++++++++++++ .../conformance/tests/go-wasm-ai-proxy.yaml | 29 +++++++++ 2 files changed, 89 insertions(+) diff --git a/test/e2e/conformance/tests/go-wasm-ai-proxy.go b/test/e2e/conformance/tests/go-wasm-ai-proxy.go index 5d14f0208d..882b0b0816 100644 --- a/test/e2e/conformance/tests/go-wasm-ai-proxy.go +++ b/test/e2e/conformance/tests/go-wasm-ai-proxy.go @@ -37,6 +37,66 @@ var WasmPluginsAiProxy = suite.ConformanceTest{ Manifests: []string{"tests/go-wasm-ai-proxy.yaml"}, Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { testcases := []http.Assertion{ + { + Meta: http.AssertionMeta{ + TestCaseName: "baidu case 1: non-streaming request", + CompareTarget: http.CompareTargetResponse, + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "qianfan.baidubce.com", + Path: "/v1/chat/completions", + Method: "POST", + ContentType: http.ContentTypeApplicationJson, + Body: []byte(`{"model":"gpt-3","messages":[{"role":"user","content":"你好,你是谁?"}],"stream":false}`), + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + ContentType: http.ContentTypeApplicationJson, + Body: []byte(`{"id":"chatcmpl-llm-mock","choices":[{"index":0,"message":{"role":"assistant","content":"你好,你是谁?"},"finish_reason":"stop"}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion","usage":{"prompt_tokens":9,"completion_tokens":1,"total_tokens":10}}`), + }, + }, + }, + { + Meta: http.AssertionMeta{ + TestCaseName: "baidu case 2: streaming request", + CompareTarget: http.CompareTargetResponse, + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Host: "qianfan.baidubce.com", + Path: "/v1/chat/completions", + Method: "POST", + ContentType: http.ContentTypeApplicationJson, + Body: []byte(`{"model":"gpt-3","messages":[{"role":"user","content":"你好,你是谁?"}],"stream":true}`), + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + ContentType: http.ContentTypeTextEventStream, + Body: []byte(`data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":"你"}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":"好"}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":","}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":"你"}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":"是"}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":"谁"}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: {"id":"chatcmpl-llm-mock","choices":[{"index":0,"delta":{"content":"?"}}],"created":10,"model":"ernie-3.5-8k","object":"chat.completion.chunk","usage":{}} + +data: [DONE] + +`), + }, + }, + }, { Meta: http.AssertionMeta{ TestCaseName: "doubao case 1: non-streaming request", diff --git a/test/e2e/conformance/tests/go-wasm-ai-proxy.yaml b/test/e2e/conformance/tests/go-wasm-ai-proxy.yaml index 07bf7d8a8b..6f80efa64f 100644 --- a/test/e2e/conformance/tests/go-wasm-ai-proxy.yaml +++ b/test/e2e/conformance/tests/go-wasm-ai-proxy.yaml @@ -13,6 +13,25 @@ # limitations under the License. apiVersion: networking.k8s.io/v1 kind: Ingress +metadata: + name: wasmplugin-ai-proxy-baidu + namespace: higress-conformance-ai-backend +spec: + ingressClassName: higress + rules: + - host: "qianfan.baidubce.com" + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: llm-mock-service + port: + number: 3000 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress metadata: name: wasmplugin-ai-proxy-doubao namespace: higress-conformance-ai-backend @@ -116,6 +135,16 @@ spec: phase: UNSPECIFIED_PHASE priority: 100 matchRules: + - config: + provider: + apiTokens: + - fake_token + modelMapping: + 'gpt-3': ernie-3.5-8k + '*': ernie-3.5-8k + type: baidu + ingress: + - higress-conformance-ai-backend/wasmplugin-ai-proxy-baidu - config: provider: apiTokens: