From 06896706981c200afc66a522e121cd53c27caca0 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Wed, 25 Jun 2025 18:04:34 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(xinference):=20update=20Docu?= =?UTF-8?q?ment=20type=20to=20'any'=20for=20flexibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Changed the type of `Document` in `XinRerankResponseDocument` from `string` to `any` to accommodate various data types. - Updated the `RerankHandler` to handle `Document` as `any`, ensuring proper assignment based on its actual type. These modifications enhance the handling of document data, allowing for greater versatility in response structures. --- relay/channel/xinference/dto.go | 2 +- relay/common_handler/rerank.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/relay/channel/xinference/dto.go b/relay/channel/xinference/dto.go index 2f12ad10..35f339fe 100644 --- a/relay/channel/xinference/dto.go +++ b/relay/channel/xinference/dto.go @@ -1,7 +1,7 @@ package xinference type XinRerankResponseDocument struct { - Document string `json:"document,omitempty"` + Document any `json:"document,omitempty"` Index int `json:"index"` RelevanceScore float64 `json:"relevance_score"` } diff --git a/relay/common_handler/rerank.go b/relay/common_handler/rerank.go index 496278b5..bf36e8c9 100644 --- a/relay/common_handler/rerank.go +++ b/relay/common_handler/rerank.go @@ -38,10 +38,16 @@ func RerankHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Respo } if info.ReturnDocuments { var document any - if result.Document == "" { - document = info.Documents[result.Index] - } else { - document = result.Document + if result.Document != nil { + if doc, ok := result.Document.(string); ok { + if doc == "" { + document = info.Documents[result.Index] + } else { + document = doc + } + } else { + document = result.Document + } } respResult.Document = document }