Skip to content

Commit

Permalink
feat: use SystemInstructions and remove gemini dummy message
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdlzg committed Dec 23, 2024
1 parent ba50a13 commit ad56898
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions relay/adaptor/gemini/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
}
}
}
shouldAddDummyModelMessage := false
for _, message := range textRequest.Messages {
content := ChatContent{
Role: message.Role,
Expand Down Expand Up @@ -154,25 +153,12 @@ func ConvertRequest(textRequest model.GeneralOpenAIRequest) *ChatRequest {
if content.Role == "assistant" {
content.Role = "model"
}
// Converting system prompt to prompt from user for the same reason
// Converting system prompt to SystemInstructions
if content.Role == "system" {
content.Role = "user"
shouldAddDummyModelMessage = true
geminiRequest.SystemInstruction = &content
continue

Check warning on line 159 in relay/adaptor/gemini/main.go

View check run for this annotation

Codecov / codecov/patch

relay/adaptor/gemini/main.go#L158-L159

Added lines #L158 - L159 were not covered by tests
}
geminiRequest.Contents = append(geminiRequest.Contents, content)

// If a system message is the last message, we need to add a dummy model message to make gemini happy
if shouldAddDummyModelMessage {
geminiRequest.Contents = append(geminiRequest.Contents, ChatContent{
Role: "model",
Parts: []Part{
{
Text: "Okay",
},
},
})
shouldAddDummyModelMessage = false
}
}

return &geminiRequest
Expand Down

0 comments on commit ad56898

Please # to comment.