Skip to content

Commit

Permalink
feat: fix scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcguire1 committed Dec 14, 2023
1 parent 8f9dbf4 commit b4735a3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/dom/chatmodels/gemini_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)).
Expand All @@ -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.
Expand Down

0 comments on commit b4735a3

Please sign in to comment.