Skip to content

Commit

Permalink
Merge pull request #68 from Azure/jan24
Browse files Browse the repository at this point in the history
Significant update - latest packages and libraries, multiple changes
  • Loading branch information
denniszielke authored Jan 23, 2024
2 parents d277e84 + 4a6788c commit 24bbb1a
Show file tree
Hide file tree
Showing 17 changed files with 1,833 additions and 2,000 deletions.
18 changes: 8 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
OPENAI_API_TYPE = "Set this to "azure" for API key authentication or "azure_ad" for Azure AD authentication>"
OPENAI_API_KEY = "<YOUR AZURE OPENAI API KEY - If using Azure AD auth, this can be left empty>"
OPENAI_API_BASE = "<YOUR AZURE OPENAI ENDPOINT>"
OPENAI_API_VERSION = "2023-05-15"
OPENAI_COMPLETION_MODEL = "<YOUR OPENAI COMPLETIONS MODEL NAME - e.g. gpt-35-turbo>"
AZURE_TENANT_ID = "<AZURE AD TENANT ID - Only used if you are using Azure AD to authentication>"
OPENAI_API_VERSION = "2023-09-01-preview"
AZURE_OPENAI_API_KEY = "<YOUR AZURE OPENAI API KEY - If using Azure AD auth, this can be left empty>"
AZURE_OPENAI_ENDPOINT = "<YOUR AZURE OPENAI ENDPOINT>"
AZURE_OPENAI_COMPLETION_MODEL = "<YOUR OPENAI COMPLETIONS MODEL NAME - e.g. gpt-35-turbo>"
AZURE_OPENAI_COMPLETION_DEPLOYMENT_NAME = "<YOUR AZURE OPENAI COMPLETIONS DEPLOYMENT NAME - e.g. gpt-35-turbo>"
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME = "<YOUR AZURE OPENAI EMBEDDINGS DEPLOYMENT NAME - e.g. text-embedding-ada-002>"
AZURE_COGNITIVE_SEARCH_SERVICE_NAME = "<YOUR AZURE COGNITIVE SEARCH SERVICE NAME - e.g. cognitive-search-service>"
AZURE_COGNITIVE_SEARCH_ENDPOINT_NAME = "<YOUR AZURE COGNITIVE SEARCH ENDPOINT NAME - e.g. https://cognitive-search-service.search.windows.net"
AZURE_COGNITIVE_SEARCH_INDEX_NAME = "<YOUR AZURE COGNITIVE SEARCH INDEX NAME - e.g. cognitive-search-index>"
AZURE_COGNITIVE_SEARCH_API_KEY = "<YOUR AZURE COGNITIVE SEARCH ADMIN API KEY - e.g. cognitive-search-admin-api-key>"
AZURE_AI_SEARCH_SERVICE_NAME = "<YOUR AZURE AI SEARCH SERVICE NAME - e.g. ai-vectorstore-xyz>"
AZURE_AI_SEARCH_ENDPOINT = "<YOUR AZURE AI SEARCH ENDPOINT NAME - e.g. https://ai-vectorstore-xyz.search.windows.net"
AZURE_AI_SEARCH_INDEX_NAME = "<YOUR AZURE AI SEARCH INDEX NAME - e.g. ai-search-index>"
AZURE_AI_SEARCH_API_KEY = "<YOUR AZURE AI SEARCH ADMIN API KEY - get this value from the Azure portal>"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ This repository introduces and helps organizations get started with building AI

## Workshop Agenda

The objective of this workshop is to practice realistic AI orchestration scenarios towards learning how to build intelligent apps.
The objective of this workshop is to practice realistic AI orchestration scenarios and to learn how to build intelligent apps.
At the end of the workshop you will:
* Know how to use prompt engineering techniques for effective generative AI responses on OpenAI
* Understand the implications of the usage of tokens and embeddings when interacting with an LLM
* Have experience in leveraging AI orchestrators like Langchain/ Semantic Kernel with Azure OpenAI
* Have evaluated different Vectorstores like Qdrant/ Azure Cognitive Search to enhance LLM responses with your data and context
* Have evaluated different vector stores like Qdrant or Azure AI Search to enhance LLM responses with your data and context
* Know how to turn a business scenario with data, context and user input into an intelligent application on Azure

### 🌅 Morning (9:00 – 12:15)
Expand Down
2 changes: 1 addition & 1 deletion labs/00-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Here's a detailed walkthrough of what you need to get started with the labs.

## OpenAI Model Deployments

During these labs, we'll make use of a *Completions* model and an *Embeddings* model, so you'll need access to at least one of each of these. Grant the participants access to Azure OpenAI Service service be assigning the `Cognitive Service OpenAI user`. If the participant is a `Cognitive Service OpenAI contributor`, they can create the following deployments themselves.
During these labs, we'll make use of a *Completions* model and an *Embeddings* model, so you'll need access to at least one of each of these. Grant the participants access to Azure OpenAI Service service by assigning the `Cognitive Service OpenAI user`. If the participant is a `Cognitive Service OpenAI contributor`, they can create the following deployments themselves.

**NOTE:** Please take extra care to make sure the correct version of each model is deployed.

Expand Down
4 changes: 2 additions & 2 deletions labs/02-integrating-ai/00-PythonModules/pythonmodules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"source": [
"# Python Modules\n",
"\n",
"A handful of Python modules are necessary to use the labs in this repo. The module names are listed in the `requirements.txt` file which can be found in the `labs` folder.\n",
"A handful of Python modules are necessary to use the labs in this repo. The module names are listed in the `requirements.txt` file which can be found in the root of this repository.\n",
"\n",
"Run the below to install the required packages.\n",
"\n",
Expand Down Expand Up @@ -55,7 +55,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.7"
},
"orig_nbformat": 4
},
Expand Down
110 changes: 19 additions & 91 deletions labs/02-integrating-ai/01-AzureOpenAIAPI/azureopenaiapi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,87 +31,13 @@
"\n",
"# Load environment variables\n",
"if load_dotenv():\n",
" print(\"Found OpenAI API Base Endpoint: \" + os.getenv(\"OPENAI_API_BASE\"))\n",
" print(\"Found Azure OpenAI API Base Endpoint: \" + os.getenv(\"AZURE_OPENAI_ENDPOINT\"))\n",
"else: \n",
" print(\"OpenAI API Base Endpoint not found. Have you configured the .env file?\")\n",
" print(\"Azure OpenAI API Base Endpoint not found. Have you configured the .env file?\")\n",
" \n",
"API_KEY = os.getenv(\"OPENAI_API_KEY\")\n",
"# This version of the API is needed to properly retrieve the list of model deployments.\n",
"API_VERSION = \"2023-03-15-preview\"\n",
"RESOURCE_ENDPOINT = os.getenv(\"OPENAI_API_BASE\")"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we'll set the endpoint that we're going to call. This endpoint will return a list of available model deployments."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = RESOURCE_ENDPOINT + \"/openai/deployments?api-version=\" + API_VERSION\n",
"\n",
"print (url)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Above you will see the full URL that we are going to be calling."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get the list of available Model Deployments\n",
"\n",
"Now let's call that Azure OpenAI endpoint and see what it returns. We pass the API key in the HTTP header."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(url, headers={\"api-key\": API_KEY})\n",
"\n",
"print(r.text)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Above, there should now be a JSON formatted list of model deployments. The output will contain one or more sections similar to the following\n",
"\n",
"```\n",
" {\n",
" \"scale_settings\": {\n",
" \"scale_type\": \"standard\"\n",
" },\n",
" \"model\": \"gpt-35-turbo\",\n",
" \"owner\": \"organization-owner\",\n",
" \"id\": \"gpt35turbo\",\n",
" \"status\": \"succeeded\",\n",
" \"created_at\": 1684150536,\n",
" \"updated_at\": 1684150536,\n",
" \"object\": \"deployment\"\n",
" }\n",
"```\n",
"\n",
"In the output, you'll see the **Model Name** as the `model` value and the **Deployment Name** as the `id` value. We'll be using an `id` value for the next section."
"API_KEY = os.getenv(\"AZURE_OPENAI_API_KEY\")\n",
"API_VERSION = os.getenv(\"OPENAI_API_VERSION\")\n",
"RESOURCE_ENDPOINT = os.getenv(\"AZURE_OPENAI_ENDPOINT\")"
]
},
{
Expand All @@ -121,9 +47,7 @@
"source": [
"## Send a prompt to Azure OpenAI using the API\n",
"\n",
"Next, let's call the Azure OpenAI API with a prompt. To do this, we'll need the `id` of our completion model deployment.\n",
"\n",
"We've already setup this value in the `.env` file, but you should see a matching value in the list that was output above."
"Now let's call the Azure OpenAI API with a prompt. To do this, we'll need the `id` of the Azure OpenAI deployment that contains our completion model. This should already be setup in the `.env` file."
]
},
{
Expand All @@ -132,8 +56,6 @@
"metadata": {},
"outputs": [],
"source": [
"# Grab API Version in the .env file.\n",
"API_VERSION = os.getenv(\"OPENAI_API_VERSION\")\n",
"DEPLOYMENT_ID = os.getenv(\"AZURE_OPENAI_COMPLETION_DEPLOYMENT_NAME\")"
]
},
Expand All @@ -142,7 +64,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As before, we'll construct a URL to call. This time, we'll also be creating a payload."
"We'll construct a URL to call so that you can see what it looks like."
]
},
{
Expand All @@ -161,9 +83,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Again, you will see the full URL that we are going to call. This URL will use the specified deployment to call the **chat completions** API.\n",
"You will see the full URL that we are going to call. This URL will use the specified deployment to call the **chat completions** API.\n",
"\n",
"Next, we will call the Azure OpenAI API using the URL above. Just like last time, we pass the API key in the HTTP header. We also send a JSON formatted body as part of the request which contains the *prompt* that we want to use to get a response from the OpenAI model. In this case, our prompt is \"Once upon a time\", which should cause the model to complete the prompt by generating a story."
"Next, we will call the Azure OpenAI API using the URL above. We pass the API key in the HTTP header. We also send a JSON formatted body as part of the request which contains the *prompt* that we want to use to get a response from the OpenAI model. In this case, our prompt is \"Once upon a time\", which should cause the model to complete the prompt by generating a story."
]
},
{
Expand All @@ -182,14 +104,20 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"As before, the result of the API call will be JSON data similar to the below example.\n",
"The result of the API call will be JSON data similar to the below example. Note that the response has been edited to make it easier to read.\n",
"\n",
"```\n",
"{\n",
" \"id\": \"chatcmpl-7wVxE2LNxaY6ZoxcWAmhiyrqaLZgf\",\n",
" \"object\": \"chat.completion\",\n",
" \"created\": 1694180212,\n",
" \"model\": \"gpt-35-turbo\",\n",
" \"prompt_filter_results\": [\n",
" {\n",
" \"prompt_index\": 0,\n",
" (content filter results removed for brevity)\n",
" }\n",
" ],\n",
" \"choices\": [\n",
" {\n",
" \"index\": 0,\n",
Expand All @@ -208,7 +136,7 @@
"}\n",
"```\n",
"\n",
"Here's some more information about some of the data contained in that response.\n",
"Here's some information about some of the more interesting pieces of data contained in that response.\n",
"\n",
"Key | Description\n",
"--- | ---\n",
Expand All @@ -227,7 +155,7 @@
"source": [
"## Summary\n",
"\n",
"In this lab, we used the Azure OpenAI API directly to query information about our instance of the Azure OpenAI service and to send a prompt to an OpenAI model."
"In this lab, we used the Azure OpenAI API directly to send a prompt to an OpenAI model."
]
},
{
Expand Down Expand Up @@ -266,7 +194,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.7"
},
"orig_nbformat": 4
},
Expand Down
Loading

0 comments on commit 24bbb1a

Please sign in to comment.