mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-05 08:55:28 +08:00
28 lines
985 B
Go
28 lines
985 B
Go
package shared
|
|
|
|
import "net/http"
|
|
|
|
func ShouldWriteUpstreamEmptyOutputError(text string) bool {
|
|
return text == ""
|
|
}
|
|
|
|
func UpstreamEmptyOutputDetail(contentFilter bool, text, thinking string) (int, string, string) {
|
|
_ = text
|
|
if contentFilter {
|
|
return http.StatusBadRequest, "Upstream content filtered the response and returned no output.", "content_filter"
|
|
}
|
|
if thinking != "" {
|
|
return http.StatusTooManyRequests, "Upstream account hit a rate limit and returned reasoning without visible output.", "upstream_empty_output"
|
|
}
|
|
return http.StatusTooManyRequests, "Upstream account hit a rate limit and returned empty output.", "upstream_empty_output"
|
|
}
|
|
|
|
func WriteUpstreamEmptyOutputError(w http.ResponseWriter, text, thinking string, contentFilter bool) bool {
|
|
if !ShouldWriteUpstreamEmptyOutputError(text) {
|
|
return false
|
|
}
|
|
status, message, code := UpstreamEmptyOutputDetail(contentFilter, text, thinking)
|
|
WriteOpenAIErrorWithCode(w, status, message, code)
|
|
return true
|
|
}
|