gateway: Mistral's key is written ahead of the body's members, not through a re-encode (daoche_wuzui on X)
withFields re-sorted the client's message keys, which the Mistral reasoning tests (byte-for-byte) caught. The fake Mistral's known fields now list prompt_cache_key, as Mistral's chat docs do. Run: Mistral, CacheKey, Hermes and the five full-run reds alone (all ok); gofmt.
This commit is contained in:
@@ -8615,7 +8615,21 @@ func withMistralCacheKey(p provider.Provider, in http.Header, body []byte) []byt
|
||||
return body
|
||||
}
|
||||
sum := sha256.Sum256([]byte("mistral\x00" + id))
|
||||
return withFields(body, map[string]any{cacheKeyField: hex.EncodeToString(sum[:])})
|
||||
// written in ahead of the first member, so the client's own bytes
|
||||
// (and the order its messages were sent in, for the cache) stay as sent
|
||||
i := bytes.IndexByte(body, '{')
|
||||
if i < 0 || len(bytes.TrimSpace(body[:i])) > 0 {
|
||||
return body
|
||||
}
|
||||
rest := bytes.TrimLeft(body[i+1:], " \t\r\n")
|
||||
sep := ","
|
||||
if len(rest) == 0 || rest[0] == '}' {
|
||||
sep = ""
|
||||
}
|
||||
out := make([]byte, 0, len(body)+96)
|
||||
out = append(out, body[:i+1]...)
|
||||
out = append(out, `"`+cacheKeyField+`":"`+hex.EncodeToString(sum[:])+`"`+sep...)
|
||||
return append(out, body[i+1:]...)
|
||||
}
|
||||
|
||||
// cacheKeyOf is the prompt cache key of the conversation req is a turn
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// field it doesn't know: 422 extra_forbidden, every such field listed.
|
||||
func mistralRefuse(body []byte) (int, string) {
|
||||
known := []string{"model", "messages", "stream", "stream_options", "max_tokens", "temperature", "top_p", "tools", "tool_choice",
|
||||
"parallel_tool_calls", "response_format", "stop", "random_seed", "presence_penalty", "frequency_penalty", "n", "reasoning_effort"}
|
||||
"parallel_tool_calls", "response_format", "stop", "random_seed", "presence_penalty", "frequency_penalty", "n", "reasoning_effort", "prompt_cache_key"}
|
||||
var m map[string]json.RawMessage
|
||||
json.Unmarshal(body, &m)
|
||||
var detail []string
|
||||
|
||||
Reference in New Issue
Block a user