feat(runtime): 适配推理模式开关
This commit is contained in:
@@ -1295,6 +1295,9 @@ func validateRequest(kind string, body map[string]any) error {
|
||||
if body["messages"] == nil {
|
||||
return errors.New("messages is required")
|
||||
}
|
||||
if err := clients.ValidateOpenAIReasoningEffort(body["reasoning_effort"]); err != nil {
|
||||
return err
|
||||
}
|
||||
case "responses":
|
||||
if body["input"] == nil && body["messages"] == nil {
|
||||
return errors.New("input or messages is required")
|
||||
|
||||
@@ -2,6 +2,7 @@ package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/easyai/easyai-ai-gateway/apps/api/internal/clients"
|
||||
@@ -14,6 +15,37 @@ func (namedClient) Run(context.Context, clients.Request) (clients.Response, erro
|
||||
return clients.Response{}, nil
|
||||
}
|
||||
|
||||
func TestValidateRequestAcceptsOpenAIReasoningEffort(t *testing.T) {
|
||||
for _, effort := range []string{"none", "minimal", "low", "medium", "high", "xhigh"} {
|
||||
t.Run(effort, func(t *testing.T) {
|
||||
err := validateRequest("chat.completions", map[string]any{
|
||||
"messages": []any{map[string]any{"role": "user", "content": "ping"}},
|
||||
"reasoning_effort": effort,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("expected %s to be accepted: %v", effort, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRequestRejectsNonOpenAIReasoningEffort(t *testing.T) {
|
||||
for _, effort := range []string{"max", "auto"} {
|
||||
t.Run(effort, func(t *testing.T) {
|
||||
err := validateRequest("chat.completions", map[string]any{
|
||||
"messages": []any{map[string]any{"role": "user", "content": "ping"}},
|
||||
"reasoning_effort": effort,
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("expected %s to be rejected", effort)
|
||||
}
|
||||
if clients.ErrorCode(err) != "invalid_parameter" || !strings.Contains(err.Error(), clients.OpenAIReasoningEffortValidationMessage) {
|
||||
t.Fatalf("unexpected validation error for %s: %T %v", effort, err, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientForMapsGoogleGeminiSpecToGeminiClient(t *testing.T) {
|
||||
service := &Service{clients: map[string]clients.Client{
|
||||
"gemini": namedClient("gemini"),
|
||||
|
||||
Reference in New Issue
Block a user