mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
refactor(image): avoid using json.Marshal
This commit is contained in:
@@ -8,7 +8,6 @@ package chat_completions
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -187,18 +186,11 @@ func ConvertAntigravityResponseToOpenAI(_ context.Context, _ string, originalReq
|
|||||||
template, _ = sjson.SetRaw(template, "choices.0.delta.images", `[]`)
|
template, _ = sjson.SetRaw(template, "choices.0.delta.images", `[]`)
|
||||||
}
|
}
|
||||||
imageIndex := len(gjson.Get(template, "choices.0.delta.images").Array())
|
imageIndex := len(gjson.Get(template, "choices.0.delta.images").Array())
|
||||||
imagePayload, err := json.Marshal(map[string]any{
|
imagePayload := `{"type":"image_url","image_url":{"url":""}}`
|
||||||
"index": imageIndex,
|
imagePayload, _ = sjson.Set(imagePayload, "index", imageIndex)
|
||||||
"type": "image_url",
|
imagePayload, _ = sjson.Set(imagePayload, "image_url.url", imageURL)
|
||||||
"image_url": map[string]string{
|
|
||||||
"url": imageURL,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
template, _ = sjson.Set(template, "choices.0.delta.role", "assistant")
|
template, _ = sjson.Set(template, "choices.0.delta.role", "assistant")
|
||||||
template, _ = sjson.SetRaw(template, "choices.0.delta.images.-1", string(imagePayload))
|
template, _ = sjson.SetRaw(template, "choices.0.delta.images.-1", imagePayload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package chat_completions
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -176,18 +175,11 @@ func ConvertCliResponseToOpenAI(_ context.Context, _ string, originalRequestRawJ
|
|||||||
template, _ = sjson.SetRaw(template, "choices.0.delta.images", `[]`)
|
template, _ = sjson.SetRaw(template, "choices.0.delta.images", `[]`)
|
||||||
}
|
}
|
||||||
imageIndex := len(gjson.Get(template, "choices.0.delta.images").Array())
|
imageIndex := len(gjson.Get(template, "choices.0.delta.images").Array())
|
||||||
imagePayload, err := json.Marshal(map[string]any{
|
imagePayload := `{"type":"image_url","image_url":{"url":""}}`
|
||||||
"index": imageIndex,
|
imagePayload, _ = sjson.Set(imagePayload, "index", imageIndex)
|
||||||
"type": "image_url",
|
imagePayload, _ = sjson.Set(imagePayload, "image_url.url", imageURL)
|
||||||
"image_url": map[string]string{
|
|
||||||
"url": imageURL,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
template, _ = sjson.Set(template, "choices.0.delta.role", "assistant")
|
template, _ = sjson.Set(template, "choices.0.delta.role", "assistant")
|
||||||
template, _ = sjson.SetRaw(template, "choices.0.delta.images.-1", string(imagePayload))
|
template, _ = sjson.SetRaw(template, "choices.0.delta.images.-1", imagePayload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package chat_completions
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
@@ -188,18 +187,11 @@ func ConvertGeminiResponseToOpenAI(_ context.Context, _ string, originalRequestR
|
|||||||
template, _ = sjson.SetRaw(template, "choices.0.delta.images", `[]`)
|
template, _ = sjson.SetRaw(template, "choices.0.delta.images", `[]`)
|
||||||
}
|
}
|
||||||
imageIndex := len(gjson.Get(template, "choices.0.delta.images").Array())
|
imageIndex := len(gjson.Get(template, "choices.0.delta.images").Array())
|
||||||
imagePayload, err := json.Marshal(map[string]any{
|
imagePayload := `{"type":"image_url","image_url":{"url":""}}`
|
||||||
"index": imageIndex,
|
imagePayload, _ = sjson.Set(imagePayload, "index", imageIndex)
|
||||||
"type": "image_url",
|
imagePayload, _ = sjson.Set(imagePayload, "image_url.url", imageURL)
|
||||||
"image_url": map[string]string{
|
|
||||||
"url": imageURL,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
template, _ = sjson.Set(template, "choices.0.delta.role", "assistant")
|
template, _ = sjson.Set(template, "choices.0.delta.role", "assistant")
|
||||||
template, _ = sjson.SetRaw(template, "choices.0.delta.images.-1", string(imagePayload))
|
template, _ = sjson.SetRaw(template, "choices.0.delta.images.-1", imagePayload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,18 +323,11 @@ func ConvertGeminiResponseToOpenAINonStream(_ context.Context, _ string, origina
|
|||||||
template, _ = sjson.SetRaw(template, "choices.0.message.images", `[]`)
|
template, _ = sjson.SetRaw(template, "choices.0.message.images", `[]`)
|
||||||
}
|
}
|
||||||
imageIndex := len(gjson.Get(template, "choices.0.message.images").Array())
|
imageIndex := len(gjson.Get(template, "choices.0.message.images").Array())
|
||||||
imagePayload, err := json.Marshal(map[string]any{
|
imagePayload := `{"type":"image_url","image_url":{"url":""}}`
|
||||||
"index": imageIndex,
|
imagePayload, _ = sjson.Set(imagePayload, "index", imageIndex)
|
||||||
"type": "image_url",
|
imagePayload, _ = sjson.Set(imagePayload, "image_url.url", imageURL)
|
||||||
"image_url": map[string]string{
|
|
||||||
"url": imageURL,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
template, _ = sjson.Set(template, "choices.0.message.role", "assistant")
|
template, _ = sjson.Set(template, "choices.0.message.role", "assistant")
|
||||||
template, _ = sjson.SetRaw(template, "choices.0.message.images.-1", string(imagePayload))
|
template, _ = sjson.SetRaw(template, "choices.0.message.images.-1", imagePayload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user