mirror of
https://github.com/githubhjs/CLIProxyAPIPlus.git
synced 2026-07-12 01:25:13 +00:00
Merge branch 'router-for-me:main' into main
This commit is contained in:
@@ -95,7 +95,13 @@ func (rw *ResponseRewriter) Write(data []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rw.isStreaming {
|
if rw.isStreaming {
|
||||||
return rw.ResponseWriter.Write(rw.rewriteStreamChunk(data))
|
n, err := rw.ResponseWriter.Write(rw.rewriteStreamChunk(data))
|
||||||
|
if err == nil {
|
||||||
|
if flusher, ok := rw.ResponseWriter.(http.Flusher); ok {
|
||||||
|
flusher.Flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n, err
|
||||||
}
|
}
|
||||||
return rw.body.Write(data)
|
return rw.body.Write(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -648,8 +648,9 @@ func GetIFlowModels() []*ModelInfo {
|
|||||||
{ID: "glm-4.6", DisplayName: "GLM-4.6", Description: "Zhipu GLM 4.6 general model", Created: 1759190400},
|
{ID: "glm-4.6", DisplayName: "GLM-4.6", Description: "Zhipu GLM 4.6 general model", Created: 1759190400},
|
||||||
{ID: "kimi-k2", DisplayName: "Kimi-K2", Description: "Moonshot Kimi K2 general model", Created: 1752192000},
|
{ID: "kimi-k2", DisplayName: "Kimi-K2", Description: "Moonshot Kimi K2 general model", Created: 1752192000},
|
||||||
{ID: "kimi-k2-thinking", DisplayName: "Kimi-K2-Thinking", Description: "Moonshot Kimi K2 thinking model", Created: 1762387200, Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}},
|
{ID: "kimi-k2-thinking", DisplayName: "Kimi-K2-Thinking", Description: "Moonshot Kimi K2 thinking model", Created: 1762387200, Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}},
|
||||||
{ID: "deepseek-v3.2-chat", DisplayName: "DeepSeek-V3.2", Description: "DeepSeek V3.2", Created: 1764576000},
|
{ID: "deepseek-v3.2-chat", DisplayName: "DeepSeek-V3.2", Description: "DeepSeek V3.2 Chat", Created: 1764576000},
|
||||||
{ID: "deepseek-v3.2", DisplayName: "DeepSeek-V3.2-Exp", Description: "DeepSeek V3.2 experimental", Created: 1759104000},
|
{ID: "deepseek-v3.2-reasoner", DisplayName: "DeepSeek-V3.2", Description: "DeepSeek V3.2 Reasoner", Created: 1764576000},
|
||||||
|
{ID: "deepseek-v3.2-exp", DisplayName: "DeepSeek-V3.2-Exp", Description: "DeepSeek V3.2 experimental", Created: 1759104000},
|
||||||
{ID: "deepseek-v3.1", DisplayName: "DeepSeek-V3.1-Terminus", Description: "DeepSeek V3.1 Terminus", Created: 1756339200},
|
{ID: "deepseek-v3.1", DisplayName: "DeepSeek-V3.1-Terminus", Description: "DeepSeek V3.1 Terminus", Created: 1756339200},
|
||||||
{ID: "deepseek-r1", DisplayName: "DeepSeek-R1", Description: "DeepSeek reasoning model R1", Created: 1737331200, Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}},
|
{ID: "deepseek-r1", DisplayName: "DeepSeek-R1", Description: "DeepSeek reasoning model R1", Created: 1737331200, Thinking: &ThinkingSupport{Levels: []string{"low", "medium", "high"}}},
|
||||||
{ID: "deepseek-v3", DisplayName: "DeepSeek-V3-671B", Description: "DeepSeek V3 671B", Created: 1734307200},
|
{ID: "deepseek-v3", DisplayName: "DeepSeek-V3-671B", Description: "DeepSeek V3 671B", Created: 1734307200},
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -784,20 +786,45 @@ func parseRetryDelay(errorBody []byte) (*time.Duration, error) {
|
|||||||
// Try to parse the retryDelay from the error response
|
// Try to parse the retryDelay from the error response
|
||||||
// Format: error.details[].retryDelay where @type == "type.googleapis.com/google.rpc.RetryInfo"
|
// Format: error.details[].retryDelay where @type == "type.googleapis.com/google.rpc.RetryInfo"
|
||||||
details := gjson.GetBytes(errorBody, "error.details")
|
details := gjson.GetBytes(errorBody, "error.details")
|
||||||
if !details.Exists() || !details.IsArray() {
|
if details.Exists() && details.IsArray() {
|
||||||
return nil, fmt.Errorf("no error.details found")
|
for _, detail := range details.Array() {
|
||||||
|
typeVal := detail.Get("@type").String()
|
||||||
|
if typeVal == "type.googleapis.com/google.rpc.RetryInfo" {
|
||||||
|
retryDelay := detail.Get("retryDelay").String()
|
||||||
|
if retryDelay != "" {
|
||||||
|
// Parse duration string like "0.847655010s"
|
||||||
|
duration, err := time.ParseDuration(retryDelay)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse duration")
|
||||||
|
}
|
||||||
|
return &duration, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: try ErrorInfo.metadata.quotaResetDelay (e.g., "373.801628ms")
|
||||||
|
for _, detail := range details.Array() {
|
||||||
|
typeVal := detail.Get("@type").String()
|
||||||
|
if typeVal == "type.googleapis.com/google.rpc.ErrorInfo" {
|
||||||
|
quotaResetDelay := detail.Get("metadata.quotaResetDelay").String()
|
||||||
|
if quotaResetDelay != "" {
|
||||||
|
duration, err := time.ParseDuration(quotaResetDelay)
|
||||||
|
if err == nil {
|
||||||
|
return &duration, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, detail := range details.Array() {
|
// Fallback: parse from error.message "Your quota will reset after Xs."
|
||||||
typeVal := detail.Get("@type").String()
|
message := gjson.GetBytes(errorBody, "error.message").String()
|
||||||
if typeVal == "type.googleapis.com/google.rpc.RetryInfo" {
|
if message != "" {
|
||||||
retryDelay := detail.Get("retryDelay").String()
|
re := regexp.MustCompile(`after\s+(\d+)s\.?`)
|
||||||
if retryDelay != "" {
|
if matches := re.FindStringSubmatch(message); len(matches) > 1 {
|
||||||
// Parse duration string like "0.847655010s"
|
seconds, err := strconv.Atoi(matches[1])
|
||||||
duration, err := time.ParseDuration(retryDelay)
|
if err == nil {
|
||||||
if err != nil {
|
duration := time.Duration(seconds) * time.Second
|
||||||
return nil, fmt.Errorf("failed to parse duration")
|
|
||||||
}
|
|
||||||
return &duration, nil
|
return &duration, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user