Skip to content

Commit

Permalink
gemini: Switch to Gemini 2.0 Flash Experimental and update doc links
Browse files Browse the repository at this point in the history
  • Loading branch information
Brawl345 committed Dec 11, 2024
1 parent 3c1c031 commit e96a42e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions plugin/gemini/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gemini
// Models: https://ai.google.dev/gemini-api/docs/models/gemini

const (
ApiUrlGemini = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent"
ApiUrlGemini = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent"
ApiUrlFileUpload = "https://generativelanguage.googleapis.com/upload/v1beta/files?key=%s"
RoleModel = "model"
RoleUser = "user"
Expand Down Expand Up @@ -41,15 +41,15 @@ type (
Parts []Part `json:"parts"`
}

// GenerateContentRequest - https://ai.google.dev/api/rest/v1beta/models/generateContent#request-body
// GenerateContentRequest - https://ai.google.dev/api/generate-content#request-body
GenerateContentRequest struct {
Contents []Content `json:"contents"`
SafetySettings []SafetySetting `json:"safetySettings"`
GenerationConfig GenerationConfig `json:"generationConfig"`
SystemInstruction SystemInstruction `json:"system_instruction"`
}

// GenerateContentResponse - https://ai.google.dev/api/rest/v1beta/GenerateContentResponse
// GenerateContentResponse - https://ai.google.dev/api/generate-content#generatecontentresponse
GenerateContentResponse struct {
Candidates []struct {
Content Content `json:"content"`
Expand All @@ -61,7 +61,7 @@ type (
} `json:"candidates"`
}

// FileUploadResponse - https://ai.google.dev/api/rest/v1beta/media/upload#response-body
// FileUploadResponse - https://ai.google.dev/api/files#response-body
FileUploadResponse struct {
File struct {
MimeType string `json:"mimeType"`
Expand Down
6 changes: 3 additions & 3 deletions plugin/gemini/gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
TopP = 1
MaxOutputTokens = 700
MaxInputCharacters = 250000 // Should be roughly 1 mio tokens, max input tokens are 1048576
TokensPerImage = 258 // https://ai.google.dev/gemini-api/docs/prompting_with_media?lang=python#video_formats
TokensPerImage = 258 // https://ai.google.dev/gemini-api/docs/tokens?lang=go#multimodal-tokens
DefaultSystemInstruction = "Antworte nur auf Deutsch. Nutze nur Standard-Text, da Markdown für den Nutzer nicht angezeigt wird. Verwende keine Emoji. Bilder-Analyse ist eingeschaltet."
)

Expand Down Expand Up @@ -67,7 +67,7 @@ func (p *Plugin) Commands() []gotgbot.BotCommand {
func (p *Plugin) Handlers(botInfo *gotgbot.User) []plugin.Handler {
return []plugin.Handler{
&plugin.CommandHandler{
Trigger: regexp.MustCompile(`(?i)^Bot,? ([\s\S]+)$`),
Trigger: regexp.MustCompile(`(?i)^Bot, ([\s\S]+)$`),
HandlerFunc: p.onGemini,
GroupOnly: true,
},
Expand Down Expand Up @@ -157,7 +157,7 @@ func (p *Plugin) onGemini(b *gotgbot.Bot, c plugin.GobotContext) error {

parts := []Part{{Text: inputText.String()}}

//Upload photo first: https://ai.google.dev/gemini-api/docs/prompting_with_media
//Upload photo first: https://ai.google.dev/gemini-api/docs/vision?lang=rest#image-input
if photo != nil {
_, _ = c.EffectiveChat.SendAction(b, gotgbot.ChatActionUploadPhoto, nil)

Expand Down
6 changes: 3 additions & 3 deletions plugin/gemini/gemini.http
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Chat prompt
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={{google_generative_language_api_key}}
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key={{google_generative_language_api_key}}
Content-Type: application/json

{
Expand Down Expand Up @@ -57,7 +57,7 @@ Content-Type: image/jpeg
###

# Vision prompt (edit fileUri below)
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key={{google_generative_language_api_key}}
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key={{google_generative_language_api_key}}
Content-Type: application/json

{
Expand All @@ -71,7 +71,7 @@ Content-Type: application/json
{
"fileData": {
"mimeType": "image/jpeg",
"fileUri": "https://generativelanguage.googleapis.com/v1beta/files/ihbunuo8sc77"
"fileUri": "https://generativelanguage.googleapis.com/v1beta/files/sdkqtahx67k4"
}
}
]
Expand Down

0 comments on commit e96a42e

Please sign in to comment.