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

- oia examples only contain OpenAI imports+calls #648

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 06-text-generation-apps/python/aoai-app-recipe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from openai import AzureOpenAI

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a changed imports and comment

import os
import dotenv
from dotenv import load_dotenv

# import dotenv
dotenv.load_dotenv()
# load environment variables from .env file
load_dotenv()

# configure Azure OpenAI service client
client = AzureOpenAI(
Expand Down
6 changes: 3 additions & 3 deletions 06-text-generation-apps/python/aoai-app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=all
from openai import AzureOpenAI
import os
import dotenv
from dotenv import load_dotenv

# import dotenv
dotenv.load_dotenv()
# load environment variables from .env file
load_dotenv()

# configure Azure OpenAI service client
client = AzureOpenAI(
Expand Down
28 changes: 17 additions & 11 deletions 06-text-generation-apps/python/aoai-assignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
" azure_endpoint = os.environ('AZURE_OPENAI_ENDPOINT')\n",
" )\n",
"\n",
"deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"deployment = os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"```\n",
"\n",
"Above we're setting the following:\n",
Expand Down Expand Up @@ -163,7 +163,7 @@
" api_version = \"2023-05-15\"\n",
" )\n",
"\n",
"deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"deployment = os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"\n",
"completion = client.chat.completions.create(model=deployment, messages=[{\"role\": \"user\", \"content\": \"Hello world\"}])\n",
"print(completion.choices[0].message.content)\n",
Expand Down Expand Up @@ -197,8 +197,7 @@
"# Activate virtual environment\n",
"! source venv/bin/activate\n",
"# Install openai package\n",
"! pip install openai\n",
" "
"! pip install openai"
]
},
{
Expand Down Expand Up @@ -236,7 +235,7 @@
" api_version = \"2023-10-01-preview\"\n",
" )\n",
"\n",
"deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"deployment = os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"\n",
"# add your completion code\n",
"prompt = \"Complete the following: Once upon a time there was a\"\n",
Expand Down Expand Up @@ -448,14 +447,18 @@
"source": [
"import os\n",
"from openai import AzureOpenAI\n",
"from dotenv import load_dotenv\n",
"\n",
"# load environment variables from .env file\n",
"load_dotenv()\n",
"\n",
"client = AzureOpenAI(\n",
" azure_endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"], \n",
" api_key=os.environ['AZURE_OPENAI_API_KEY'], \n",
" api_version = \"2023-10-01-preview\"\n",
" )\n",
"\n",
"deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"deployment = os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"\n",
"prompt = \"Show me 5 recipes for a dish with the following ingredients: chicken, potatoes, and carrots. Per recipe, list all the ingredients used\"\n",
"messages = [{\"role\": \"user\", \"content\": prompt}] \n",
Expand Down Expand Up @@ -503,14 +506,18 @@
"source": [
"import os\n",
"from openai import AzureOpenAI\n",
"from dotenv import load_dotenv\n",
"\n",
"# load environment variables from .env file\n",
"load_dotenv()\n",
"\n",
"client = AzureOpenAI(\n",
" azure_endpoint = os.environ[\"AZURE_OPENAI_ENDPOINT\"], \n",
" api_key=os.environ['AZURE_OPENAI_API_KEY'], \n",
" api_version = \"2023-10-01-preview\"\n",
" )\n",
"\n",
"deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"deployment = os.environ['AZURE_OPENAI_DEPLOYMENT']\n",
"\n",
"no_recipes = input(\"No of recipes (for example, 5: \")\n",
"\n",
Expand Down Expand Up @@ -755,7 +762,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -769,9 +776,8 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
},
"orig_nbformat": 4
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
6 changes: 3 additions & 3 deletions 06-text-generation-apps/python/aoai-history-bot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from openai import AzureOpenAI
import os
import dotenv
from dotenv import load_dotenv

# import dotenv
dotenv.load_dotenv()
# load environment variables from .env file
load_dotenv()

# configure Azure OpenAI service client
client = AzureOpenAI(
Expand Down
6 changes: 3 additions & 3 deletions 06-text-generation-apps/python/aoai-study-buddy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from openai import AzureOpenAI
import os
import dotenv
from dotenv import load_dotenv

# import dotenv
dotenv.load_dotenv()
# load environment variables from .env file
load_dotenv()

# configure Azure OpenAI service client
client = AzureOpenAI(
Expand Down
21 changes: 4 additions & 17 deletions 06-text-generation-apps/python/githubmodels-assignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -364,21 +364,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'azure'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mos\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mazure\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01minference\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ChatCompletionsClient\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mazure\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01minference\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m SystemMessage, UserMessage\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mazure\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcore\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcredentials\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m AzureKeyCredential\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'azure'"
]
}
],
"outputs": [],
"source": [
"import os\n",
"from azure.ai.inference import ChatCompletionsClient\n",
Expand Down Expand Up @@ -840,7 +828,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -855,8 +843,7 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
},
"orig_nbformat": 4
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
10 changes: 4 additions & 6 deletions 06-text-generation-apps/python/oai-app-recipe.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from openai import OpenAI
import os
import dotenv
from dotenv import load_dotenv

# import dotenv
dotenv.load_dotenv()
# load environment variables from .env file
load_dotenv()

# configure Azure OpenAI service client
client = OpenAI()

#deployment=os.environ['OPENAI_DEPLOYMENT']
deployment="gpt-3.5-turbo"
deployment = "gpt-3.5-turbo"

no_recipes = input("No of recipes (for example, 5: ")

Expand Down
10 changes: 4 additions & 6 deletions 06-text-generation-apps/python/oai-app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from openai import OpenAI
import os
import dotenv
from dotenv import load_dotenv

# import dotenv
dotenv.load_dotenv()
# load environment variables from .env file
load_dotenv()

# configure OpenAI service client
client = OpenAI()

#deployment=os.environ['OPENAI_DEPLOYMENT']
deployment="gpt-3.5-turbo"
deployment = "gpt-3.5-turbo"

# add your completion code
prompt = "Complete the following: Once upon a time there was a"
Expand Down
74 changes: 41 additions & 33 deletions 06-text-generation-apps/python/oai-assigment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,25 @@
"> - It is important to note that the API Key will only be accessible once. Therefore, it is imperative to verify that it has been copied correctly. In the event that it does not function as intended, it is recommended to delete the key and generate a new one.\n",
"\n",
"\n",
"### Setup configuration Azure\n",
"### Setup configuration OpenAI\n",
"\n",
"If you're using Open AI, here's how you setup configuration:\n",
"If you're using OpenAI, here's how you setup configuration:\n",
"\n",
"```python\n",
"client = AzureOpenAI(\n",
" api_key=os.environ['OPENAI_API_KEY']\n",
"client = OpenAI(\n",
" api_key = os.environ['OPENAI_API_KEY']\n",
" )\n",
"\n",
"deployment=os.environ['OPENAI_DEPLOYMENT']\n",
"deployment = \"gpt-3.5-turbo\"\n",
"```\n",
"\n",
"Above we're setting the following:\n",
"\n",
"- `api_key`, this is your API key found in THE OpenAI dashboard.\n",
"- `api_key`, this is your API key found in the OpenAI dashboard.\n",
"- `deployment`, this is your GPT version.\n",
"\n",
"> [!NOTE]\n",
"> `os.environ` is a function that reads environment variables. You can use it to read environment variables like `AZURE_OPENAI_API_KEY` and `AZURE_OPENAI_ENDPOINT`.\n",
"> `os.environ` is a function that reads environment variables. You can use it to read environment variables like `OPENAI_API_KEY`.\n",
"\n",
"## Generate text\n",
"\n",
Expand All @@ -141,11 +141,11 @@
"So far, you've seen how we've been using `Completion` to generate text. But there's another class called `ChatCompletion` that is more suited for chatbots. Here's an example of using it:\n",
"\n",
"```python\n",
"client = AzureOpenAI(\n",
" api_key=os.environ['OPENAI_API_KEY']\n",
"client = OpenAI(\n",
" api_key = os.environ['OPENAI_API_KEY']\n",
" )\n",
"\n",
"deployment=os.environ['OPENAI_DEPLOYMENT']\n",
"deployment = \"gpt-3.5-turbo\"\n",
"\n",
"completion = client.chat.completions.create(model=deployment, messages=[{\"role\": \"user\", \"content\": \"Hello world\"}])\n",
"print(completion.choices[0].message.content)\n",
Expand All @@ -155,7 +155,7 @@
"\n",
"## Exercise - your first text generation app\n",
"\n",
"Now that we learned how to set up and configure Azure OpenAI service, it's time to build your first text generation app. To build your app, follow these steps:\n",
"Now that we learned how to set up and configure OpenAI service, it's time to build your first text generation app. To build your app, follow these steps:\n",
"\n"
]
},
Expand All @@ -179,8 +179,7 @@
"# Activate virtual environment\n",
"! source venv/bin/activate\n",
"# Install openai package\n",
"! pip install openai\n",
" "
"! pip install openai"
]
},
{
Expand All @@ -191,7 +190,7 @@
"> If you're using Windows type `venv\\Scripts\\activate` instead of `source venv/bin/activate`. \n",
"\n",
"> [!NOTE]\n",
"> Locate your Azure Open AI key by going to https://portal.azure.com/ and search for `Open AI` and select the `Open AI resource` and then select `Keys and Endpoint` and copy the `Key 1` value."
"> Locate your OpenAI key by going to https://platform.openai.com/settings/organization/api-keys and search for `API keys`. You can create a new key there and immediate copy the value."
]
},
{
Expand All @@ -208,15 +207,17 @@
"outputs": [],
"source": [
"import os\n",
"from openai import AzureOpenAI\n",
"from openai import OpenAI\n",
"from dotenv import load_dotenv\n",
"\n",
"# load environment variables from .env file\n",
"load_dotenv()\n",
"\n",
"client = AzureOpenAI(\n",
" api_key=os.environ['OPENAI_API_KEY']\n",
" )\n",
"client = OpenAI(\n",
" api_key = os.environ['OPENAI_API_KEY']\n",
")\n",
"\n",
"deployment=os.environ['OPENAI_DEPLOYMENT']\n",
"deployment = \"gpt-3.5-turbo\"\n",
"\n",
"# add your completion code\n",
"prompt = \"Complete the following: Once upon a time there was a\"\n",
Expand Down Expand Up @@ -427,13 +428,17 @@
"outputs": [],
"source": [
"import os\n",
"from openai import AzureOpenAI\n",
"from openai import OpenAI\n",
"from dotenv import load_dotenv\n",
"\n",
"client = AzureOpenAI(\n",
" api_key=os.environ['OPENAI_API_KEY']\n",
" )\n",
"# load environment variables from .env file\n",
"load_dotenv()\n",
"\n",
"client = OpenAI(\n",
" api_key = os.environ['OPENAI_API_KEY']\n",
")\n",
"\n",
"deployment=os.environ['OPENAI_DEPLOYMENT']\n",
"deployment = \"gpt-3.5-turbo\"\n",
"\n",
"prompt = \"Show me 5 recipes for a dish with the following ingredients: chicken, potatoes, and carrots. Per recipe, list all the ingredients used\"\n",
"messages = [{\"role\": \"user\", \"content\": prompt}] \n",
Expand Down Expand Up @@ -480,13 +485,17 @@
"outputs": [],
"source": [
"import os\n",
"from openai import AzureOpenAI\n",
"from openai import OpenAI\n",
"from dotenv import load_dotenv\n",
"\n",
"client = AzureOpenAI(\n",
" api_key=os.environ['OPENAI_API_KEY']\n",
" )\n",
"# load environment variables from .env file\n",
"load_dotenv()\n",
"\n",
"deployment=os.environ['OPENAI_DEPLOYMENT']\n",
"client = OpenAI(\n",
" api_key = os.environ['OPENAI_API_KEY']\n",
")\n",
"\n",
"deployment = \"gpt-3.5-turbo\"\n",
"\n",
"no_recipes = input(\"No of recipes (for example, 5: \")\n",
"\n",
Expand Down Expand Up @@ -731,7 +740,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "venv",
"language": "python",
"name": "python3"
},
Expand All @@ -745,9 +754,8 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
},
"orig_nbformat": 4
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
Loading
Loading