|
|
@@ -6,6 +6,7 @@ import (
|
|
|
"io"
|
|
|
"net/http"
|
|
|
"one-api/common"
|
|
|
+ "one-api/constant"
|
|
|
"one-api/dto"
|
|
|
"one-api/logger"
|
|
|
"one-api/relay/channel/gemini"
|
|
|
@@ -94,6 +95,32 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ
|
|
|
|
|
|
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
|
|
|
if request.SystemInstructions != nil {
|
|
|
hasContent := false
|