mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 16:04:01 +00:00
fix: normalize tool reasoning history across protocols
This commit is contained in:
1 parent
1c149e3657
commit
e68a0b9d19
3 files changed
+110
-34
No files matched your search
+11
-24
@@ -225,32 +225,19 @@ func (g *Gateway) handleInference(external Protocol) http.HandlerFunc {
|
||||
writeAPIError(w, external, http.StatusBadRequest, err.Error(), "invalid_request_error", "model")
|
||||
return
|
||||
}
|
||||
encoded := body
|
||||
upstreamPayload := payload
|
||||
needsEncoding := false
|
||||
if external == ProtocolAnthropic {
|
||||
upstreamURL := g.cfg.Upstream.Zen
|
||||
if route.Tier == TierGo {
|
||||
upstreamURL = g.cfg.Upstream.Go
|
||||
}
|
||||
if shouldNormalizeAnthropicToolThinkingHistory(model, upstreamURL) {
|
||||
needsEncoding = normalizeAnthropicToolThinkingHistory(upstreamPayload)
|
||||
}
|
||||
upstreamURL := g.cfg.Upstream.Zen
|
||||
if route.Tier == TierGo {
|
||||
upstreamURL = g.cfg.Upstream.Go
|
||||
}
|
||||
if external != route.Protocol {
|
||||
upstreamPayload, err = convertRequest(external, route.Protocol, upstreamPayload)
|
||||
if err != nil {
|
||||
writeAPIError(w, external, http.StatusBadRequest, err.Error(), "invalid_request_error", "")
|
||||
return
|
||||
}
|
||||
needsEncoding = true
|
||||
upstreamPayload, err := prepareUpstreamRequest(external, route.Protocol, payload, upstreamURL)
|
||||
if err != nil {
|
||||
writeAPIError(w, external, http.StatusBadRequest, err.Error(), "invalid_request_error", "")
|
||||
return
|
||||
}
|
||||
if needsEncoding {
|
||||
encoded, err = json.Marshal(upstreamPayload)
|
||||
if err != nil {
|
||||
writeAPIError(w, external, http.StatusBadRequest, "request contains unsupported JSON values", "invalid_request_error", "")
|
||||
return
|
||||
}
|
||||
encoded, err := json.Marshal(upstreamPayload)
|
||||
if err != nil {
|
||||
writeAPIError(w, external, http.StatusBadRequest, "request contains unsupported JSON values", "invalid_request_error", "")
|
||||
return
|
||||
}
|
||||
ids := deriveRequestIDs(r, payload)
|
||||
stream := boolAt(payload, "stream")
|
||||
|
||||
Reference in new issue
Block a user