-
Notifications
You must be signed in to change notification settings - Fork 11.1k
feat: 支持渠道级透传选项,支持设置渠道系统提示词 #1441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b25841e
d6cbf43
1297add
2469c43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| package dto | ||
|
|
||
| type ChannelSettings struct { | ||
| ForceFormat bool `json:"force_format,omitempty"` | ||
| ThinkingToContent bool `json:"thinking_to_content,omitempty"` | ||
| Proxy string `json:"proxy"` | ||
| ForceFormat bool `json:"force_format,omitempty"` | ||
| ThinkingToContent bool `json:"thinking_to_content,omitempty"` | ||
| Proxy string `json:"proxy"` | ||
| PassThroughBodyEnabled bool `json:"pass_through_body_enabled,omitempty"` | ||
| SystemPrompt string `json:"system_prompt,omitempty"` | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |||||
| "encoding/json" | ||||||
| "errors" | ||||||
| "fmt" | ||||||
| "io" | ||||||
| "net/http" | ||||||
| "one-api/common" | ||||||
| "one-api/dto" | ||||||
|
|
@@ -194,16 +195,39 @@ func GeminiHelper(c *gin.Context) (newAPIError *types.NewAPIError) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| requestBody, err := json.Marshal(req) | ||||||
| if err != nil { | ||||||
| return types.NewError(err, types.ErrorCodeConvertRequestFailed) | ||||||
| } | ||||||
| var requestBody io.Reader | ||||||
| if model_setting.GetGlobalSettings().PassThroughRequestEnabled || relayInfo.ChannelSetting.PassThroughBodyEnabled { | ||||||
| body, err := common.GetRequestBody(c) | ||||||
| if err != nil { | ||||||
| return types.NewErrorWithStatusCode(err, types.ErrorCodeReadRequestBodyFailed, http.StatusBadRequest) | ||||||
| } | ||||||
| requestBody = bytes.NewReader(body) | ||||||
| } else { | ||||||
| jsonData, err := json.Marshal(req) | ||||||
| if err != nil { | ||||||
| return types.NewError(err, types.ErrorCodeConvertRequestFailed) | ||||||
| } | ||||||
|
|
||||||
| // apply param override | ||||||
| if len(relayInfo.ParamOverride) > 0 { | ||||||
| reqMap := make(map[string]interface{}) | ||||||
| _ = common.Unmarshal(jsonData, &reqMap) | ||||||
| for key, value := range relayInfo.ParamOverride { | ||||||
| reqMap[key] = value | ||||||
| } | ||||||
| jsonData, err = common.Marshal(reqMap) | ||||||
| if err != nil { | ||||||
| return types.NewError(err, types.ErrorCodeChannelParamOverrideInvalid) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if common.DebugEnabled { | ||||||
| println("Gemini request body: %s", string(requestBody)) | ||||||
| if common.DebugEnabled { | ||||||
| println("Gemini request body: %s", string(jsonData)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect println usage. The - println("Gemini request body: %s", string(jsonData))
+ fmt.Printf("Gemini request body: %s\n", string(jsonData))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| requestBody = bytes.NewReader(jsonData) | ||||||
| } | ||||||
|
|
||||||
| resp, err := adaptor.DoRequest(c, relayInfo, bytes.NewReader(requestBody)) | ||||||
| resp, err := adaptor.DoRequest(c, relayInfo, requestBody) | ||||||
| if err != nil { | ||||||
| common.LogError(c, "Do gemini request failed: "+err.Error()) | ||||||
| return types.NewError(err, types.ErrorCodeDoRequestFailed) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify impact of removing database consistency check logic.
The commented out code was responsible for:
Removing this logic could result in:
Please confirm this logic is handled elsewhere or provide justification for its removal.
🏁 Script executed:
Length of output: 28269
Restore database consistency handling in distributor middleware
The commented-out block in middleware/distributor.go (lines 116–119) removed both the system error log and the generic user-friendly message without any replacement:
common.SysErrorcall means DB consistency breaches won’t be logged for adminserr.Error()detailschannel != nil && err != nilscenarioPlease re-introduce explicit consistency detection and logging, for example:
By restoring this block, you’ll ensure:
📝 Committable suggestion
🤖 Prompt for AI Agents