Skip to content

Commit

Permalink
fix: fix gemini generate error
Browse files Browse the repository at this point in the history
  • Loading branch information
namwoam committed Jul 3, 2024
1 parent 4fcea03 commit c645256
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ai/vertexai/v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ var (
setupJSON []byte
//go:embed config/tasks.json
tasksJSON []byte
// This is a temporary location for the credential file. This will be moved to a more secure location.
//go:embed tmp/cred.json
//go:embed config/cred.json

Check failure on line 31 in ai/vertexai/v0/main.go

View workflow job for this annotation

GitHub Actions / codecov

pattern config/cred.json: no matching files found

Check failure on line 31 in ai/vertexai/v0/main.go

View workflow job for this annotation

GitHub Actions / lint

pattern config/cred.json: no matching files found (typecheck)
credJSON []byte

once sync.Once
Expand Down Expand Up @@ -104,22 +103,25 @@ func concateResponse(resp *genai.GenerateContentResponse) string {
func (e *execution) generateText(in *structpb.Struct) (*structpb.Struct, error) {
prompt := in.Fields["prompt"].GetStringValue()
modelName := "gemini-1.5-flash-001"
projectID := in.Fields["project-id"].GetStringValue()
location := "us-central1" // London, check: https://cloud.google.com/vertex-ai/docs/general/locations#europe
projectID := "prj-c-connector-879a"
location := "us-central1"

ctx := context.Background()
// Temporary way to get the credential. It should be migrated to a more secure implementation.
client, err := genai.NewClient(ctx, projectID, location, option.WithCredentialsJSON(credJSON))

if err != nil {
return nil, err
return nil, fmt.Errorf("error creating client: %w", err)
}

defer client.Close()

model := client.GenerativeModel(modelName)
model.SetTemperature(0.9)
resp, err := model.GenerateContent(ctx, genai.Text(prompt))
promptPart := genai.Text(prompt)
resp, err := model.GenerateContent(ctx, promptPart)
if err != nil {
return nil, err
return nil, fmt.Errorf("error generating content: %w", err)
}

outputStruct := messagesOutput{
Expand Down

0 comments on commit c645256

Please sign in to comment.