Preserve HTTP provider parameter numbers
This commit is contained in:
@@ -56,6 +56,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
body = http.MaxBytesReader(w, r.Body, h.options.MaxRequestBytes)
|
||||
}
|
||||
dec := json.NewDecoder(body)
|
||||
dec.UseNumber()
|
||||
dec.DisallowUnknownFields()
|
||||
if err := dec.Decode(&req); err != nil {
|
||||
if isRequestTooLarge(err) {
|
||||
|
||||
@@ -1373,23 +1373,33 @@ func TestHandlerRejectsOverlongSessionIDAndNonStringReasoningEffort(t *testing.T
|
||||
}
|
||||
|
||||
func TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams(t *testing.T) {
|
||||
r := &fakeRunner{result: &promptkit.RunResult{
|
||||
Artifact: promptkit.Artifact{Body: []byte("ok")},
|
||||
Validation: promptkit.ValidationResult{Status: promptkit.ValidationPassed, Mode: promptkit.ValidationBasic, IsValid: true},
|
||||
EffectiveModelParams: promptkit.ExecutionTarget{Endpoint: "http://llm/v1", Model: "m1"},
|
||||
}}
|
||||
h := NewHandler(r)
|
||||
observed := make(chan map[string]any, 1)
|
||||
provider := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var body map[string]any
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&body); err != nil {
|
||||
t.Errorf("decode provider request: %v", err)
|
||||
http.Error(w, "invalid request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
observed <- body
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"choices":[{"message":{"role":"assistant","content":"ok"},"finish_reason":"stop"}]}`))
|
||||
}))
|
||||
defer provider.Close()
|
||||
h := newRetryHandler(t, provider.URL, intPointer(0), 1, intPointer(0))
|
||||
|
||||
reqBody := `{
|
||||
"prompt_id": "prompt-1",
|
||||
"inputs": {"transcript": {"type": "file", "uri": "./t.md"}},
|
||||
"prompt_id": "p",
|
||||
"model": {
|
||||
"extra_params": {
|
||||
"string_value": "enabled",
|
||||
"number_value": 42,
|
||||
"number_value": 9007199254740993,
|
||||
"boolean_value": true,
|
||||
"object_value": {"nested": "value", "count": 2},
|
||||
"array_value": ["first", 3, false]
|
||||
"null_value": null,
|
||||
"object_value": {"nested": "value", "array": [9007199254740993, {"count": 9007199254740993}]},
|
||||
"array_value": ["first", 3, false, null]
|
||||
}
|
||||
}
|
||||
}`
|
||||
@@ -1401,18 +1411,24 @@ func TestHandlerModelOverrideAcceptsJSONCompatibleExtraParams(t *testing.T) {
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
if r.last.Execution == nil {
|
||||
t.Fatal("expected execution override in run request")
|
||||
var got map[string]any
|
||||
select {
|
||||
case got = <-observed:
|
||||
default:
|
||||
t.Fatal("provider did not receive a request")
|
||||
}
|
||||
want := map[string]any{
|
||||
"string_value": "enabled",
|
||||
"number_value": float64(42),
|
||||
"number_value": json.Number("9007199254740993"),
|
||||
"boolean_value": true,
|
||||
"object_value": map[string]any{"nested": "value", "count": float64(2)},
|
||||
"array_value": []any{"first", float64(3), false},
|
||||
"null_value": nil,
|
||||
"object_value": map[string]any{"nested": "value", "array": []any{json.Number("9007199254740993"), map[string]any{"count": json.Number("9007199254740993")}}},
|
||||
"array_value": []any{"first", json.Number("3"), false, nil},
|
||||
}
|
||||
if !reflect.DeepEqual(r.last.Execution.ExtraParams, want) {
|
||||
t.Fatalf("unexpected mapped extra_params:\ngot=%#v\nwant=%#v", r.last.Execution.ExtraParams, want)
|
||||
for key, value := range want {
|
||||
if actual, ok := got[key]; !ok || !reflect.DeepEqual(actual, value) {
|
||||
t.Errorf("provider parameter %s = %#v (present %t), want %#v", key, actual, ok, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user