Skip to content

Commit

Permalink
update index and core nbs
Browse files Browse the repository at this point in the history
  • Loading branch information
algal committed Dec 5, 2024
1 parent 93657db commit 9617fe0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 32 deletions.
31 changes: 23 additions & 8 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"If you do not already have a Google CLoud Service Account Key File (SAKF), but you are already authenticated via Google cloud, these are the steps for getting a SAKF by using the Google Cloud API. "
"If you do not already have a Google CLoud Service Account Key File (SAKF), but you are already authenticated via Google cloud, these are the steps for getting a SAKF by using the Google Cloud API.\n",
"\n",
"If you already have a SAKF JSON file, from creating it via these steps, or from downloading it from the Google Cloud web UI, then you can skip forward to the section _Creating a Vertex Auth superkey_."
]
},
{
Expand Down Expand Up @@ -109,7 +111,6 @@
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"import google.auth\n",
"from google.cloud import iam_admin_v1\n",
"from google.cloud.iam_admin_v1 import types\n",
Expand Down Expand Up @@ -311,9 +312,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A vertexauth \"superkey\" is merely a SAKF file with a \"region\" key/value pair added so that it can be the only resource you need to install to use this library. If someone has given you a superkey, save it in `~/.config/vertexauth/default/superkey.json`.\n",
"A vertexauth \"superkey\" is merely a SAKF file with a \"region\" key/value pair added so that it can be the only resource needed in order to use this library.\n",
"\n",
"But if you only have a SAKF JSON file, as created above, you create and save a superkey by calling the following function:"
"If a colleague already gave you a superkey, save it in `~/.config/vertexauth/default/superkey.json`, and skip to the next section _Authenticating to Claudette_. But if you only have a SAKF JSON file, as created above, you create and save a superkey by calling the following function:"
]
},
{
Expand All @@ -322,10 +323,17 @@
"metadata": {},
"outputs": [],
"source": [
"#| default_exp core\n",
"\n",
"SUPERKEY_DEFAULT_PATH = Path.home() / \".config\" / \"vertexauth\" / \"default\" / \"superkey.json\"\n",
"#| export\n",
"\n",
"SUPERKEY_DEFAULT_PATH = Path.home() / \".config\" / \"vertexauth\" / \"default\" / \"superkey.json\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def save_superkey_file(SAKF_path, region) -> Path:\n",
" d = json.loads(Path(SAKF_path).read_text())\n",
" d[\"region\"] = region\n",
Expand Down Expand Up @@ -369,13 +377,20 @@
"## Authenticating to Claudette"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you have a superkey file (which is a JSON SKF plus a region key/value pair), you can use these functions to create a claudette client or an Anthropic client."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| default_exp core\n",
"#| export\n",
"\n",
"def get_anthropic_client(asink=False,anthropic_kwargs=None):\n",
" d = json.loads(SUPERKEY_DEFAULT_PATH.read_text())\n",
Expand Down
66 changes: 42 additions & 24 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
"source": [
"# vertexauth\n",
"\n",
"> A helper library for accessing Google Vertex AI models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This file will become your README and also the index of your documentation."
"> A helper library for accessing Google Vertex AI models, via `claudette` or `anthropic`"
]
},
{
Expand Down Expand Up @@ -137,7 +130,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Fill me in please! Don't forget code examples:"
"To use this library, you need install a \"superkey\" credential file in your `~/.config/vertexauth/default/superkey.json`.\n",
"\n",
"Then, you can do the following to get access to a `claudette.Client`, which is authenticated to use Anthropic's Sonnet 3.5 v2 model, hosted on Vertex AI and paid for by Google Cloud budget:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from vertexauth.core import get_claudette_client\n",
"cl = get_claudette_client()"
]
},
{
Expand All @@ -147,8 +152,24 @@
"outputs": [
{
"data": {
"text/markdown": [
"Hi! I'm happy to help. What would you like to discuss?\n",
"\n",
"<details>\n",
"\n",
"- id: `msg_vrtx_016Tu5UWnM6q6uzASTpr7BTV`\n",
"- content: `[{'text': \"Hi! I'm happy to help. What would you like to discuss?\", 'type': 'text'}]`\n",
"- model: `claude-3-5-sonnet-v2-20241022`\n",
"- role: `assistant`\n",
"- stop_reason: `end_turn`\n",
"- stop_sequence: `None`\n",
"- type: `message`\n",
"- usage: `{'input_tokens': 11, 'output_tokens': 18}`\n",
"\n",
"</details>"
],
"text/plain": [
"2"
"Message(id='msg_vrtx_016Tu5UWnM6q6uzASTpr7BTV', content=[TextBlock(text=\"Hi! I'm happy to help. What would you like to discuss?\", type='text')], model='claude-3-5-sonnet-v2-20241022', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=In: 11; Out: 18; Cache create: 0; Cache read: 0; Total: 29)"
]
},
"execution_count": null,
Expand All @@ -157,7 +178,16 @@
}
],
"source": [
"1+1"
"cl(\"Hi, Claude!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"What is a superkey? It is merely a Google Cloud Service Account Key File, encoded in JSON, with a `region` key/value pair added.\n",
"\n",
"Please consult the notebook `00_core.ipynb` for a working example of creating a service account, creating a service account key, downloading the key file, and saving a superkey file into the default location."
]
},
{
Expand All @@ -170,21 +200,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 9617fe0

Please sign in to comment.