Refreshed notebooks, particularly with new Week 1
This commit is contained in:
@@ -21,17 +21,15 @@
|
||||
"source": [
|
||||
"## Setting up your keys\n",
|
||||
"\n",
|
||||
"If you haven't done so already, you'll need to create API keys from OpenAI, Anthropic and Google.\n",
|
||||
"If you haven't done so already, you could now create API keys for Anthropic and Google in addition to OpenAI.\n",
|
||||
"\n",
|
||||
"**Please note:** if you'd prefer to avoid extra API costs, feel free to skip setting up Anthopic and Google! You can see me do it, and focus on OpenAI for the course.\n",
|
||||
"**Please note:** if you'd prefer to avoid extra API costs, feel free to skip setting up Anthopic and Google! You can see me do it, and focus on OpenAI for the course. You could also substitute Anthropic and/or Google for Ollama, using the exercise you did in week 1.\n",
|
||||
"\n",
|
||||
"For OpenAI, visit https://openai.com/api/ \n",
|
||||
"For Anthropic, visit https://console.anthropic.com/ \n",
|
||||
"For Google, visit https://ai.google.dev/gemini-api \n",
|
||||
"\n",
|
||||
"When you get your API keys, you need to set them as environment variables.\n",
|
||||
"\n",
|
||||
"EITHER (recommended) create a file called `.env` in this project root directory, and set your keys there:\n",
|
||||
"When you get your API keys, you need to set them as environment variables by adding them to your `.env` file.\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"OPENAI_API_KEY=xxxx\n",
|
||||
@@ -39,9 +37,7 @@
|
||||
"GOOGLE_API_KEY=xxxx\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"OR enter the keys directly in the cells below.\n",
|
||||
"\n",
|
||||
"You may need to restart the Jupyter Notebook Kernel (the Python process) via the Kernel menu."
|
||||
"Afterwards, you may need to restart the Jupyter Lab Kernel (the Python process that sits behind this notebook) via the Kernel menu, and then rerun the cells from the top."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -56,11 +52,24 @@
|
||||
"import os\n",
|
||||
"from dotenv import load_dotenv\n",
|
||||
"from openai import OpenAI\n",
|
||||
"import google.generativeai\n",
|
||||
"import anthropic\n",
|
||||
"from IPython.display import Markdown, display, update_display"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f0a8ab2b-6134-4104-a1bc-c3cd7ea4cd36",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# import for google\n",
|
||||
"# in rare cases, this seems to give an error on some systems. Please reach out to me if this happens,\n",
|
||||
"# or you can feel free to skip Gemini - it's the lowest priority of the frontier models that we use\n",
|
||||
"\n",
|
||||
"import google.generativeai"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -69,11 +78,27 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load environment variables in a file called .env\n",
|
||||
"# Print the key prefixes to help with any debugging\n",
|
||||
"\n",
|
||||
"load_dotenv()\n",
|
||||
"os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY', 'your-key-if-not-using-env')\n",
|
||||
"os.environ['ANTHROPIC_API_KEY'] = os.getenv('ANTHROPIC_API_KEY', 'your-key-if-not-using-env')\n",
|
||||
"os.environ['GOOGLE_API_KEY'] = os.getenv('GOOGLE_API_KEY', 'your-key-if-not-using-env')"
|
||||
"openai_api_key = os.getenv('OPENAI_API_KEY')\n",
|
||||
"anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
|
||||
"google_api_key = os.getenv('GOOGLE_API_KEY')\n",
|
||||
"\n",
|
||||
"if openai_api_key:\n",
|
||||
" print(f\"OpenAI API Key exists and begins {openai_api_key[:8]}\")\n",
|
||||
"else:\n",
|
||||
" print(\"OpenAI API Key not set\")\n",
|
||||
" \n",
|
||||
"if anthropic_api_key:\n",
|
||||
" print(f\"Anthropic API Key exists and begins {anthropic_api_key[:7]}\")\n",
|
||||
"else:\n",
|
||||
" print(\"Anthropic API Key not set\")\n",
|
||||
"\n",
|
||||
"if google_api_key:\n",
|
||||
" print(f\"Google API Key exists and begins {google_api_key[:8]}\")\n",
|
||||
"else:\n",
|
||||
" print(\"Google API Key not set\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -447,7 +472,17 @@
|
||||
"source": [
|
||||
"# See the community-contributions folder\n",
|
||||
"\n",
|
||||
"For a great variation with a 3-way bringing Gemini into the conversation!"
|
||||
"For a great variation with a 3-way bringing Gemini into the conversation!\n",
|
||||
"\n",
|
||||
"Try doing this yourself before you look in the folder.\n",
|
||||
"\n",
|
||||
"## Additional exercise\n",
|
||||
"\n",
|
||||
"Try adding in an Ollama model in to the conversation.\n",
|
||||
"\n",
|
||||
"## Business relevance\n",
|
||||
"\n",
|
||||
"This structure of a conversation, as a list of messages, is fundamental to the way we build conversational AI assistants and how they are able to keep the context during a conversation. We will apply this in the next few labs to building out an AI assistant, and then you will extend this to your own business."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user