mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-08 17:36:47 +08:00
fix(translator): 工具输出与 custom input 解包的健壮性改进
采纳 review 意见:responsesToolOutputText 支持纯字符串数组元素, 避免非 content-parts 形态的输出被静默丢弃;unwrapCustomToolInput 在 input 为对象/数组时以原始 JSON 解包,不再仅限字符串。 Ref #4219
This commit is contained in:
@@ -120,6 +120,10 @@ func responsesToolOutputText(output gjson.Result) string {
|
||||
if output.IsArray() {
|
||||
var b strings.Builder
|
||||
output.ForEach(func(_, part gjson.Result) bool {
|
||||
if part.Type == gjson.String {
|
||||
b.WriteString(part.String())
|
||||
return true
|
||||
}
|
||||
if text := part.Get("text"); text.Exists() {
|
||||
b.WriteString(text.String())
|
||||
}
|
||||
@@ -168,8 +172,11 @@ func responsesCustomToolNames(requestRawJSON []byte) map[string]struct{} {
|
||||
// function-call arguments produced for a converted custom tool; it falls back
|
||||
// to the raw arguments when the wrapper is absent.
|
||||
func unwrapCustomToolInput(arguments string) string {
|
||||
if v := gjson.Get(arguments, "input"); v.Exists() && v.Type == gjson.String {
|
||||
return v.String()
|
||||
if v := gjson.Get(arguments, "input"); v.Exists() {
|
||||
if v.Type == gjson.String {
|
||||
return v.String()
|
||||
}
|
||||
return v.Raw
|
||||
}
|
||||
return arguments
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user