Name | vertexauth JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | Helper for authenticating with VertexAI |
upload_time | 2024-12-03 19:31:43 |
maintainer | None |
docs_url | None |
author | Alexis Gallagher |
requires_python | >=3.10 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# VertexAuth
This is a helper library for accessing Google Vertex AI models
To use it, get a GCloud _Service Account Key File_ (SAKF), then save a default "superkey" file into your `.config` dir, like so:
``` python
from vertexauth import create_superkey_file
path=create_superkey_file(SAKF_path='/path/to/gcloud/service_auth_key_file.json',
region='us-east5',
save_as_default=True)
```
The superkey file is just the SAKF file with region information added.
Then later, you can create a [claudette](https://claudette.answer.ai/) client or [AnthropicVertex](https://docs.anthropic.com/en/api/claude-on-vertex-ai) client object like so:
``` python
from vertexauth import get_anthropic_client, get_claudette_client, load_vertex_vals
from claudette import Chat
# AnthropicVertex
anthropic_client = get_anthropic_client()
# claudette.Client
claudette_client = get_claudette_client()
cl_chat = Chat(cli=claudette_client)
cl_chat("Hi, there!")
# just read the vals
val_dict = load_vertex_vals()
```
These functions also let you pass a path to a specific superkey, instad of loading the default one.
Alternatively, they can read an env var, `VERTEXAUTH_SUPERKEY`, which contains a superkey as a string. This lets you share it and use it like a normal API key. However, it's a bit long -- around 2,500 characters, since it's simply the gzipped, base64-encoded contents of the file. Use `create_superkey_env_value` to create one.
## Huh, what's a Service Account Key File?
Yes it would be easier of course if Google just gave us a single API key value. But they don't.
afaict the closest you can get to this with Google Vertex AI is to generate a "Service Account Key File" (SAKF), a JSON file with embedded credentials. But even once you have this, you need to supply it along with other coordinated pieces of information (like project ID and region) in order to make an API request against a VertexAI model. So it's a bit of a hassle., and that's what this library helps with. That's all.
## But how do I get this blessed Service Account Key File from Google
It's not pretty. Here's approximately what you need to do:
- Go to Google Cloud console
- Select a project
- Go to APIs & Services
- Go to Enabled APIs and Services
- Select "Vertex AI API" from the list and ensure that it is Enabled"
- Within that panel, select "Quotas and System Limits"
- In the filter control, enter the property name "Online
prediction requests per base model per minute per region per
base_model" to find that row.
- Scope to a particular `region` (e.g., "us-east5") and and
`base_model` (e.g., "anthropic-claude-3-5-sonnet-v2")
- Use "Edit Quota" to ensure that you have a non-zero quote for it
- Also, within that same panel, select "Credentials"
- Click "+ Create Credentials"
- Select "Service Account"
- Enter a name like "vertexaiserviceaccount" etc for the account,
- For permissions, give it the "Vertex AI Service Agent" role.
- Go to keys, select "Add key" and select "JSON"
Raw data
{
"_id": null,
"home_page": null,
"name": "vertexauth",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Alexis Gallagher",
"author_email": "alexis@alexisgallagher.com",
"download_url": "https://files.pythonhosted.org/packages/b8/33/11b97afe617f5694d2458323ca516dbf8164066dabea0593adc8579f76c8/vertexauth-0.2.0.tar.gz",
"platform": null,
"description": "# VertexAuth\n\nThis is a helper library for accessing Google Vertex AI models\n\nTo use it, get a GCloud _Service Account Key File_ (SAKF), then save a default \"superkey\" file into your `.config` dir, like so:\n\n``` python\nfrom vertexauth import create_superkey_file\npath=create_superkey_file(SAKF_path='/path/to/gcloud/service_auth_key_file.json',\n region='us-east5',\n save_as_default=True)\n```\n\nThe superkey file is just the SAKF file with region information added.\n\nThen later, you can create a [claudette](https://claudette.answer.ai/) client or [AnthropicVertex](https://docs.anthropic.com/en/api/claude-on-vertex-ai) client object like so:\n\n``` python\nfrom vertexauth import get_anthropic_client, get_claudette_client, load_vertex_vals\nfrom claudette import Chat\n\n# AnthropicVertex\nanthropic_client = get_anthropic_client()\n\n# claudette.Client\nclaudette_client = get_claudette_client()\ncl_chat = Chat(cli=claudette_client)\ncl_chat(\"Hi, there!\")\n\n# just read the vals\nval_dict = load_vertex_vals()\n```\n\nThese functions also let you pass a path to a specific superkey, instad of loading the default one.\n\nAlternatively, they can read an env var, `VERTEXAUTH_SUPERKEY`, which contains a superkey as a string. This lets you share it and use it like a normal API key. However, it's a bit long -- around 2,500 characters, since it's simply the gzipped, base64-encoded contents of the file. Use `create_superkey_env_value` to create one.\n\n## Huh, what's a Service Account Key File?\n\nYes it would be easier of course if Google just gave us a single API key value. But they don't.\n\nafaict the closest you can get to this with Google Vertex AI is to generate a \"Service Account Key File\" (SAKF), a JSON file with embedded credentials. But even once you have this, you need to supply it along with other coordinated pieces of information (like project ID and region) in order to make an API request against a VertexAI model. So it's a bit of a hassle., and that's what this library helps with. That's all.\n\n## But how do I get this blessed Service Account Key File from Google\n\nIt's not pretty. Here's approximately what you need to do:\n\n- Go to Google Cloud console\n- Select a project\n- Go to APIs & Services\n- Go to Enabled APIs and Services\n- Select \"Vertex AI API\" from the list and ensure that it is Enabled\"\n- Within that panel, select \"Quotas and System Limits\"\n - In the filter control, enter the property name \"Online\n prediction requests per base model per minute per region per\n base_model\" to find that row.\n - Scope to a particular `region` (e.g., \"us-east5\") and and\n `base_model` (e.g., \"anthropic-claude-3-5-sonnet-v2\")\n - Use \"Edit Quota\" to ensure that you have a non-zero quote for it\n- Also, within that same panel, select \"Credentials\"\n - Click \"+ Create Credentials\"\n - Select \"Service Account\" \n - Enter a name like \"vertexaiserviceaccount\" etc for the account, \n - For permissions, give it the \"Vertex AI Service Agent\" role.\n - Go to keys, select \"Add key\" and select \"JSON\"\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Helper for authenticating with VertexAI",
"version": "0.2.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dba2120842be4e921492126e99bf89cb9f4b07a286a00b8d89263c74827d1ab5",
"md5": "a5e834c24eb2a8d373d33c0c00603c1c",
"sha256": "ef644ad0abe5bf50add15c78486d50f78d659584f961b0e2dbd4ca7101eb1f0c"
},
"downloads": -1,
"filename": "vertexauth-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a5e834c24eb2a8d373d33c0c00603c1c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 5562,
"upload_time": "2024-12-03T19:31:42",
"upload_time_iso_8601": "2024-12-03T19:31:42.862836Z",
"url": "https://files.pythonhosted.org/packages/db/a2/120842be4e921492126e99bf89cb9f4b07a286a00b8d89263c74827d1ab5/vertexauth-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b83311b97afe617f5694d2458323ca516dbf8164066dabea0593adc8579f76c8",
"md5": "fa17aaaef5bc012c3a2d79656e9f1190",
"sha256": "325bd8df5e0e84044040938de0a428b078ad7b08a51fe5c0a211e56db76aaf0f"
},
"downloads": -1,
"filename": "vertexauth-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "fa17aaaef5bc012c3a2d79656e9f1190",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 4277,
"upload_time": "2024-12-03T19:31:43",
"upload_time_iso_8601": "2024-12-03T19:31:43.742361Z",
"url": "https://files.pythonhosted.org/packages/b8/33/11b97afe617f5694d2458323ca516dbf8164066dabea0593adc8579f76c8/vertexauth-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-03 19:31:43",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "vertexauth"
}