Skip to content

Commit

Permalink
Add support for "thought" generation config in Gemini payload
Browse files Browse the repository at this point in the history
- Introduced `GenerationConfig` struct with `Thought` field in Gemini payload.
- Modified `GenGemminPayload` to accept `thought` parameter and include it in the payload.
- Added logic in `chatStreamGemini` to set `thought` based on the model name.
  • Loading branch information
swuecho committed Feb 2, 2025
1 parent 4112fe7 commit 623fd5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion api/chat_main_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,11 @@ func (h *ChatHandler) chatStreamGemini(w http.ResponseWriter, chatSession sqlc_q
RespondWithError(w, http.StatusInternalServerError, eris.Wrap(err, "Error getting chat files").Error(), err)
return "", "", true
}
payloadBytes, err := gemini.GenGemminPayload(chat_compeletion_messages, chatFiles)
thought := false
if strings.Contains(chatSession.Model, "thinking") {
thought = true
}
payloadBytes, err := gemini.GenGemminPayload(chat_compeletion_messages, chatFiles, thought)
if err != nil {
RespondWithError(w, http.StatusInternalServerError, eris.Wrap(err, "Error generating gemmi payload").Error(), err)
return "", "", true
Expand Down
16 changes: 15 additions & 1 deletion api/llm/gemini/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,20 @@ func ImageData(mimeType string, data []byte) Blob {
type GeminiMessage struct {
Role string `json:"role"`
Parts []Part `json:"parts"`

}

type GenerationConfig struct {
Thought bool `json:"thought"`
// Temperature float64 `json:"temperature"`
// TopP float64 `json:"topP"`
// TopK int `json:"topK"`
// MaxOutputTokens int `json:"maxOutputTokens"`
}

type GeminPayload struct {
Contents []GeminiMessage `json:"contents"`
GenerationConfig GenerationConfig `json:"generationConfig"`
}

type Content struct {
Expand Down Expand Up @@ -104,6 +114,7 @@ type ResponseBody struct {

func ParseRespLine(line []byte, answer string) string {
var resp ResponseBody
log.Println(string(line))
if err := json.Unmarshal(line, &resp); err != nil {
fmt.Println("Failed to parse request body:", err)
}
Expand Down Expand Up @@ -149,9 +160,12 @@ func SupportedMimeTypes() mapset.Set[string] {
)
}

func GenGemminPayload(chat_compeletion_messages []models.Message, chatFiles []sqlc_queries.ChatFile) ([]byte, error) {
func GenGemminPayload(chat_compeletion_messages []models.Message, chatFiles []sqlc_queries.ChatFile, thought bool) ([]byte, error) {
payload := GeminPayload{
Contents: make([]GeminiMessage, len(chat_compeletion_messages)),
// GenerationConfig: GenerationConfig{
// Thought: thought,
// },
}
for i, message := range chat_compeletion_messages {
geminiMessage := GeminiMessage{
Expand Down

0 comments on commit 623fd5f

Please sign in to comment.