fix: gemini system prompt overwrite
This commit is contained in:
@@ -70,7 +70,7 @@ func ClaudeHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
|
|||||||
info.UpstreamModelName = request.Model
|
info.UpstreamModelName = request.Model
|
||||||
}
|
}
|
||||||
|
|
||||||
if info.ChannelSetting.SystemPrompt != "" && info.ChannelSetting.SystemPromptOverride {
|
if info.ChannelSetting.SystemPrompt != "" {
|
||||||
if request.System == nil {
|
if request.System == nil {
|
||||||
request.SetStringSystem(info.ChannelSetting.SystemPrompt)
|
request.SetStringSystem(info.ChannelSetting.SystemPrompt)
|
||||||
} else if info.ChannelSetting.SystemPromptOverride {
|
} else if info.ChannelSetting.SystemPromptOverride {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"one-api/common"
|
"one-api/common"
|
||||||
|
"one-api/constant"
|
||||||
"one-api/dto"
|
"one-api/dto"
|
||||||
"one-api/logger"
|
"one-api/logger"
|
||||||
"one-api/relay/channel/gemini"
|
"one-api/relay/channel/gemini"
|
||||||
@@ -94,6 +95,32 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
|
|||||||
|
|
||||||
adaptor.Init(info)
|
adaptor.Init(info)
|
||||||
|
|
||||||
|
if info.ChannelSetting.SystemPrompt != "" {
|
||||||
|
if request.SystemInstructions == nil {
|
||||||
|
request.SystemInstructions = &dto.GeminiChatContent{
|
||||||
|
Parts: []dto.GeminiPart{
|
||||||
|
{Text: info.ChannelSetting.SystemPrompt},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else if len(request.SystemInstructions.Parts) == 0 {
|
||||||
|
request.SystemInstructions.Parts = []dto.GeminiPart{{Text: info.ChannelSetting.SystemPrompt}}
|
||||||
|
} else if info.ChannelSetting.SystemPromptOverride {
|
||||||
|
common.SetContextKey(c, constant.ContextKeySystemPromptOverride, true)
|
||||||
|
merged := false
|
||||||
|
for i := range request.SystemInstructions.Parts {
|
||||||
|
if request.SystemInstructions.Parts[i].Text == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
request.SystemInstructions.Parts[i].Text = info.ChannelSetting.SystemPrompt + "\n" + request.SystemInstructions.Parts[i].Text
|
||||||
|
merged = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !merged {
|
||||||
|
request.SystemInstructions.Parts = append([]dto.GeminiPart{{Text: info.ChannelSetting.SystemPrompt}}, request.SystemInstructions.Parts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up empty system instruction
|
// Clean up empty system instruction
|
||||||
if request.SystemInstructions != nil {
|
if request.SystemInstructions != nil {
|
||||||
hasContent := false
|
hasContent := false
|
||||||
|
|||||||
Reference in New Issue
Block a user