Skip to content

Commit

Permalink
feat: use json direct
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmcguire1 committed Dec 14, 2023
1 parent b2308fd commit 6cac215
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions internal/dom/chatmodels/gemini_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package chatmodels
import (
"context"
"encoding/base64"
"log"
"log/slog"

"github.com/google/generative-ai-go/genai"
"github.com/sashabaranov/go-openai"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
)

Expand All @@ -25,18 +24,23 @@ func NewGeminiApiClient(token string) *GeminiApiClient {
}

func (api *GeminiApiClient) GeminiChat(ctx context.Context, prompt string) (*genai.GenerateContentResponse, error) {
creds, err := google.CredentialsFromJSON(ctx, api.Token)
client, err := genai.NewClient(ctx, option.WithCredentialsJSON(api.Token))
if err != nil {
log.Printf("got token %s err:%s \n", string(api.Token), err)
return nil, err
}
slog.
With("token-json", string(api.Token)).
Error("failed to process gemini generative req")

client, err := genai.NewClient(ctx, option.WithCredentials(creds))
if err != nil {
return nil, err
}
defer client.Close()
model := client.GenerativeModel("gemini-pro")

return model.GenerateContent(ctx, genai.Text(prompt))
res, err := model.GenerateContent(ctx, genai.Text(prompt))
if err != nil {
slog.
With("prompt", prompt).
With("token-json", string(api.Token)).
Error("failed to process gemini generative req")
}
return res, err
}

0 comments on commit 6cac215

Please sign in to comment.