Skip to content

Commit

Permalink
Enhance the e2e testing of the ai-proxy plugin based on the LLM mock …
Browse files Browse the repository at this point in the history
…server
  • Loading branch information
hanxiantao committed Jan 24, 2025
1 parent 574d1aa commit fa9de35
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 90 deletions.
39 changes: 39 additions & 0 deletions test/e2e/conformance/base/llm-mock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2025 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: Pod
metadata:
name: llm-mock
namespace: higress-conformance-app-backend
labels:
name: llm-mock
spec:
containers:
- name: llm-mock
image: registry.cn-hangzhou.aliyuncs.com/hxt/llm-mock:latest
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: llm-mock-service
namespace: higress-conformance-app-backend
spec:
selector:
name: llm-mock
clusterIP: None
ports:
- port: 3000
71 changes: 10 additions & 61 deletions test/e2e/conformance/tests/go-wasm-ai-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,84 +27,33 @@ func init() {

var WasmPluginsAiProxy = suite.ConformanceTest{
ShortName: "WasmPluginAiProxy",
Description: "The Ingress in the higress-conformance-infra namespace test the ai-proxy WASM plugin.",
Description: "The Ingress in the higress-conformance-app-backend namespace test the ai-proxy WASM plugin.",
Features: []suite.SupportedFeature{suite.WASMGoConformanceFeature},
Manifests: []string{"tests/go-wasm-ai-proxy.yaml"},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
testcases := []http.Assertion{
{
Meta: http.AssertionMeta{
TestCaseName: "case 1: openai",
TargetBackend: "infra-backend-v1",
TargetNamespace: "higress-conformance-infra",
TestCaseName: "case 1: minimax",
TargetBackend: "llm-mock-service",
TargetNamespace: "higress-conformance-app-backend",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "openai.ai.com",
Path: "/v1/chat/completions",
Method:"POST",
ContentType: http.ContentTypeApplicationJson,
Body: []byte(`{
"model": "gpt-3",
"messages": [{"role":"user","content":"hi"}]}`),
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Host: "api.openai.com",
Path: "/v1/chat/completions",
Method: "POST",
ContentType: http.ContentTypeApplicationJson,
Body: []byte(`{
"model": "gpt-3",
"messages": [{"role":"user","content":"hi"}],
"max_tokens": 123,
"temperature": 0.66}`),
},
Host: "openai.ai.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,
Body: []byte(`{"id":"chatcmpl-llm-mock","choices":[{"index":0,"message":{"role":"assistant","content":"你好,你是谁?"},"finish_reason":"stop"}],"model":"abab6.5s-chat","object":"chat.completion","usage":{"prompt_tokens":9,"completion_tokens":1,"total_tokens":10}}`),
},
},
},
{
Meta: http.AssertionMeta{
TestCaseName: "case 2: qwen",
TargetBackend: "infra-backend-v1",
TargetNamespace: "higress-conformance-infra",
},
Request: http.AssertionRequest{
ActualRequest: http.Request{
Host: "qwen.ai.com",
Path: "/v1/chat/completions",
Method:"POST",
ContentType: http.ContentTypeApplicationJson,
Body: []byte(`{
"model": "qwen-long",
"input": {"messages": [{"role":"user","content":"hi"}]},
"parameters": {"max_tokens": 321, "temperature": 0.7}}`),
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Host: "dashscope.aliyuncs.com",
Path: "/api/v1/services/aigc/text-generation/generation",
Method: "POST",
ContentType: http.ContentTypeApplicationJson,
Body: []byte(`{
"model": "qwen-long",
"input": {"messages": [{"role":"user","content":"hi"}]},
"parameters": {"max_tokens": 321, "temperature": 0.66}}`),
},
},
},
Response: http.AssertionResponse{
ExpectedResponse: http.Response{
StatusCode: 500,
},
},
},

}
t.Run("WasmPlugins ai-proxy", func(t *testing.T) {
for _, testcase := range testcases {
Expand Down
49 changes: 20 additions & 29 deletions test/e2e/conformance/tests/go-wasm-ai-proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
name: wasmplugin-ai-proxy-openai
namespace: higress-conformance-infra
namespace: higress-conformance-app-backend
spec:
ingressClassName: higress
rules:
Expand All @@ -27,61 +26,53 @@ spec:
path: "/"
backend:
service:
name: infra-backend-v1
name: llm-mock-service
port:
number: 8080
number: 3000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
name: wasmplugin-ai-proxy-qwen
namespace: higress-conformance-infra
name: wasmplugin-ai-proxy-minimax
namespace: higress-conformance-app-backend
spec:
ingressClassName: higress
rules:
- host: "qwen.ai.com"
- host: "api.minimax.chat"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: infra-backend-v1
name: llm-mock-service
port:
number: 8080
number: 3000
---
apiVersion: extensions.higress.io/v1alpha1
kind: WasmPlugin
metadata:
name: ai-proxy
namespace: higress-system
spec:
priority: 200
defaultConfigDisable: true
phase: UNSPECIFIED_PHASE
priority: 100
matchRules:
- config:
provider:
type: "openai"
customSettings:
- name: "max_tokens"
value: 123
overwrite: false
- name: "temperature"
value: 0.66
overwrite: true
ingress:
- higress-conformance-infra/wasmplugin-ai-proxy-openai
- higress-conformance-app-backend/wasmplugin-ai-proxy-openai
- config:
provider:
type: "qwen"
apiTokens: "fake-token"
customSettings:
- name: "max_tokens"
value: 123
overwrite: false
- name: "temperature"
value: 0.66
overwrite: true
apiTokens:
- fake_token
modelMapping:
'gpt-3': abab6.5s-chat
'gpt-4': abab6.5g-chat
'*': abab6.5t-chat
type: minimax
ingress:
- higress-conformance-infra/wasmplugin-ai-proxy-qwen
- higress-conformance-app-backend/wasmplugin-ai-proxy-minimax
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-proxy:1.0.0

0 comments on commit fa9de35

Please sign in to comment.