Compare commits

...

7 Commits

Author SHA1 Message Date
CaIon
aa455e7977 fix: update OpenAI response structure to use json.RawMessage for dynamic fields 2026-03-06 17:50:45 +08:00
Calcium-Ion
e768ae44e1 Merge pull request #3141 from seefs001/fix/claude-thinking-top_p
fix: If top_p is not provided, Claude's logic will set to 1
2026-03-06 12:08:12 +08:00
Seefs
be8a623586 fix: ignore top_p 2026-03-06 12:07:36 +08:00
Seefs
a6ede75415 fix: ignore top_p 2026-03-06 12:07:00 +08:00
Seefs
267c99b779 fix: If top_p is not provided, Claude's logic will automatically set it to 1. 2026-03-06 12:03:51 +08:00
Calcium-Ion
44e59e1ced Merge pull request #2769 from feitianbubu/pr/3d0aaa75866f8d958a777a7e7ac8c1e4b5b3e537
feat: kling cost quota support use FinalUnitDeduction as totalToken
2026-03-06 11:46:59 +08:00
feitianbubu
1a8567758f feat: kling cost quota support use FinalUnitDeduction as totalToken 2026-01-28 18:42:13 +08:00
3 changed files with 36 additions and 16 deletions

View File

@@ -267,7 +267,7 @@ type OpenAIResponsesResponse struct {
ID string `json:"id"`
Object string `json:"object"`
CreatedAt int `json:"created_at"`
Status string `json:"status"`
Status json.RawMessage `json:"status"`
Error any `json:"error,omitempty"`
IncompleteDetails *IncompleteDetails `json:"incomplete_details,omitempty"`
Instructions string `json:"instructions"`
@@ -275,14 +275,14 @@ type OpenAIResponsesResponse struct {
Model string `json:"model"`
Output []ResponsesOutput `json:"output"`
ParallelToolCalls bool `json:"parallel_tool_calls"`
PreviousResponseID string `json:"previous_response_id"`
PreviousResponseID json.RawMessage `json:"previous_response_id"`
Reasoning *Reasoning `json:"reasoning"`
Store bool `json:"store"`
Temperature float64 `json:"temperature"`
ToolChoice string `json:"tool_choice"`
ToolChoice json.RawMessage `json:"tool_choice"`
Tools []map[string]any `json:"tools"`
TopP float64 `json:"top_p"`
Truncation string `json:"truncation"`
Truncation json.RawMessage `json:"truncation"`
Usage *Usage `json:"usage"`
User json.RawMessage `json:"user"`
Metadata json.RawMessage `json:"metadata"`

View File

@@ -4,7 +4,9 @@ import (
"bytes"
"fmt"
"io"
"math"
"net/http"
"strconv"
"strings"
"time"
@@ -80,15 +82,28 @@ type responsePayload struct {
TaskId string `json:"task_id"`
TaskStatus string `json:"task_status"`
TaskStatusMsg string `json:"task_status_msg"`
TaskResult struct {
TaskInfo struct {
ExternalTaskId string `json:"external_task_id"`
} `json:"task_info"`
WatermarkInfo struct {
Enabled bool `json:"enabled"`
} `json:"watermark_info"`
TaskResult struct {
Videos []struct {
Id string `json:"id"`
Url string `json:"url"`
Duration string `json:"duration"`
Id string `json:"id"`
Url string `json:"url"`
WatermarkUrl string `json:"watermark_url"`
Duration string `json:"duration"`
} `json:"videos"`
Images []struct {
Index int `json:"index"`
Url string `json:"url"`
WatermarkUrl string `json:"watermark_url"`
} `json:"images"`
} `json:"task_result"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
FinalUnitDeduction string `json:"final_unit_deduction"`
} `json:"data"`
}
@@ -338,15 +353,22 @@ func (a *TaskAdaptor) ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, e
taskInfo.Status = model.TaskStatusInProgress
case "succeed":
taskInfo.Status = model.TaskStatusSuccess
if videos := resPayload.Data.TaskResult.Videos; len(videos) > 0 {
video := videos[0]
taskInfo.Url = video.Url
}
if tokens, err := strconv.ParseFloat(resPayload.Data.FinalUnitDeduction, 64); err == nil {
rounded := int(math.Ceil(tokens))
if rounded > 0 {
taskInfo.CompletionTokens = rounded
taskInfo.TotalTokens = rounded
}
}
case "failed":
taskInfo.Status = model.TaskStatusFailure
default:
return nil, fmt.Errorf("unknown task status: %s", status)
}
if videos := resPayload.Data.TaskResult.Videos; len(videos) > 0 {
video := videos[0]
taskInfo.Url = video.Url
}
return taskInfo, nil
}

View File

@@ -59,7 +59,6 @@ func ClaudeHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
Type: "adaptive",
}
request.OutputConfig = json.RawMessage(fmt.Sprintf(`{"effort":"%s"}`, effortLevel))
request.TopP = common.GetPointer[float64](0)
request.Temperature = common.GetPointer[float64](1.0)
info.UpstreamModelName = request.Model
} else if model_setting.GetClaudeSettings().ThinkingAdapterEnabled &&
@@ -77,7 +76,6 @@ func ClaudeHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
}
// TODO: 临时处理
// https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking
request.TopP = common.GetPointer[float64](0)
request.Temperature = common.GetPointer[float64](1.0)
}
if !model_setting.ShouldPreserveThinkingSuffix(info.OriginModelName) {