Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genai: func NewClient does not use opts ...option.ClientOption param #9160

Closed
awenborar opened this issue Dec 13, 2023 · 1 comment · Fixed by #9163
Closed

genai: func NewClient does not use opts ...option.ClientOption param #9160

awenborar opened this issue Dec 13, 2023 · 1 comment · Fixed by #9163
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@awenborar
Copy link

Code
https://github.com/googleapis/google-cloud-go/blob/main/vertexai/genai/client.go#L47

func NewClient(ctx context.Context, projectID, location string, opts ...option.ClientOption) (*Client, error) {
	apiEndpoint := fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)
	c, err := aiplatform.NewPredictionClient(ctx, option.WithEndpoint(apiEndpoint))
	if err != nil {
		return nil, err
	}
	return &Client{
		c:         c,
		projectID: projectID,
		location:  location,
	}, nil
}

Implication
The following code does not generate valid authentication:

client, err := genai.NewClient(ctx, "project_id", "region", option.WithCredentialsFile("../cred.json"))

Solution
Use the opts param

func NewClient(ctx context.Context, projectID, location string, opts ...option.ClientOption) (*Client, error) {
	apiEndpoint := fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)
	opts = append(opts, option.WithEndpoint(apiEndpoint))
	c, err := aiplatform.NewPredictionClient(ctx, opts...)
	if err != nil {
		return nil, err
	}
	return &Client{
		c:         c,
		projectID: projectID,
		location:  location,
	}, nil
}
@awenborar awenborar added the triage me I really want to be triaged. label Dec 13, 2023
@codyoss codyoss added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed triage me I really want to be triaged. labels Dec 13, 2023
eliben added a commit to eliben/google-cloud-go that referenced this issue Dec 13, 2023
gcf-merge-on-green bot pushed a commit that referenced this issue Dec 13, 2023
@eliben
Copy link
Contributor

eliben commented Dec 13, 2023

Thanks for the report! This should roll out in a bugfix version soon - #9166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
4 participants