From b4735a3b584906adb77a7ee66cbd043751693ee4 Mon Sep 17 00:00:00 2001 From: jackmc Date: Thu, 14 Dec 2023 23:01:04 +0000 Subject: [PATCH] feat: fix scope --- internal/dom/chatmodels/gemini_api.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/dom/chatmodels/gemini_api.go b/internal/dom/chatmodels/gemini_api.go index bd5b7e5..1ad631f 100644 --- a/internal/dom/chatmodels/gemini_api.go +++ b/internal/dom/chatmodels/gemini_api.go @@ -7,6 +7,7 @@ import ( "github.com/google/generative-ai-go/genai" "github.com/sashabaranov/go-openai" + "golang.org/x/oauth2/google" "google.golang.org/api/option" ) @@ -16,15 +17,15 @@ type GeminiApiClient struct { } func NewGeminiApiClient(token string) *GeminiApiClient { - tkn, _ := base64.RawStdEncoding.DecodeString(token) - + tkn, _ := base64.StdEncoding.DecodeString(token) return &GeminiApiClient{ Token: tkn, } } func (api *GeminiApiClient) GeminiChat(ctx context.Context, prompt string) (*genai.GenerateContentResponse, error) { - client, err := genai.NewClient(ctx, option.WithCredentialsJSON(api.Token)) + creds, err := google.CredentialsFromJSON(ctx, api.Token, "https://www.googleapis.com/auth/generative-language") + client, err := genai.NewClient(ctx, option.WithCredentials(creds)) if err != nil { slog. With("token-json", string(api.Token)). @@ -33,8 +34,8 @@ func (api *GeminiApiClient) GeminiChat(ctx context.Context, prompt string) (*gen return nil, err } defer client.Close() - model := client.GenerativeModel("gemini-pro") + model := client.GenerativeModel("gemini-pro") res, err := model.GenerateContent(ctx, genai.Text(prompt)) if err != nil { slog.