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

More documentation, Readme details and little improvements on quick_start #49

Merged
merged 17 commits into from
Sep 30, 2024
Merged
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ The following resources are available in this repository:

- [Quick Start](./quick_start/): A collection of notebooks where you can quickly start with using GPT.

- [Fundamentals](./fundamentals/): A collection of notebooks illustrating fundamental usage of GPT.

- [Use Cases](./use_cases/): A collection of notebooks illustrating examples on how to use GPT in various applications, such as chatbots, customer service, and content generation etc.

- [Sample Solutions](./solution_accelerators/): End-to-end solutions for various NLP tasks, such as question answering, text summarization, and sentiment analysis etc, in context of business applications specific to various industries, where GPT is part of the solution. *Require contributions!*

- [Langchain, Semantic Kernel and Prompt Flow Samples](./samples/)
- [Serverless SQL GPT](https://github.com/balakreshnan/Samples2023/blob/main/AzureML/serverlesssqlgpt.md) - Natural language processing (NLP) with GPT in Azure Synapse Analytics Serverless SQL using Azure Machine Learning.

## GPT Version
Expand Down
48 changes: 36 additions & 12 deletions quick_start/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
# Running Demos
# Quickstart - Running Demos

## Prepare Conda Environment
Use requirements.txt to install necessary packages

## Setup Environmental Variable
After creating Azure OPENAI service, setup 2 environmental variables for
- OPENAI_API_BASE
- OPENAI_API_KEY
- DEPLOYMENT_NAME = 'text-davinci-003'
## Demos Overview

Optional - Used for "OpenAI Large Language Model Chain of Thoughts Demo"
- AZURE_COGNITIVE_SEARCH_ENDPOINT
- AZURE_COGNITIVE_SEARCH_KEY
## Run Demo Code
| Name | Goal & Description | Use Cases & Topics |
|--------------------------------|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
| [01_OpenAI_getting_started](v1/01_OpenAI_getting_started.ipynb) | This "quick start" notebook introduces users to high-level LLM concepts like: "Summarize Text", "Classify Text", "Generate new product names", and "Embeddings". | Very good sample for beginners and to showcase in some simple examples what Azure OpenAI can do.|
| [02_Chat_Completion](v1/02_ChatCompletion_api.ipynb) | Shows chat completion examples using Chat Completion, Analyzes Customer Feedback and Extracting PII. | Data Privacy, Information Security, Customer Data Management |
| [03_Code_Generation](v1/03_Code_Generation.ipynb) | Shows how to generate code for SQL table statements. Furthermore, shows how AI can explain what code does. | Automated Query Generation, Code Assistance, Educational Tools for Developers, Code Documentation, Automated Code Review |
| [04_Tokens_And_Usage](v1/04_tokens_and_usage.ipynb) | Demonstrates the token system. How to tokenize a prompt and get information about words.| Cost Management, Performance Optimization, Quota Management, Optimize Prompts |
| [05_OpenAI_Parameters](v1/05_OpenAI_parameters.ipynb) | Shows what type of parameters there are and how they affect the result.| Compare Responses, Increase Diversity, Enhance Robustness, Best Practices|
| [06_Best_Practice](v1/06_best_practice.ipynb) | Shows overall best practices. | Best Practices overall for prompt engineering with OpenAI API. |
| [07_Prompt_Engineering](v1/07_prompt_engineering.ipynb) | Shows further best practices for optimizing prompting. | Best Practices overall for prompt engineering |
| [08_LLM_RAG](v1/08_LLM_RAG_demo.ipynb) | Demonstrates how to do RAG using Bing Search results as provided context. | Knowledge Management, Business intelligence & analytics, Legal and compliance |
| [09_Function_Calling](v1/09_Function_Calling.ipynb) | Shows how to integrate a custom function and have OpenAI call it to retrieve weather information. | Dynamic Calculations, Data fetching, Interactive Applications, Custom integrations |
| [10_GPT-4V](v1/10_GPT-4V.ipynb) | Great to show what can be done with image analysis. Generates text description for provided image. | Content Creation, Accessibility, Image Classification, E-commerce |
| [11_Assistant](v1/11_Assistant.ipynb) | Create AI assistant for Data Visualization using advanced tools like code interpreter. | Personalized Customer Service, Employee Onboarding and Training, Sales and Marketing Support |


## Prepare Environment
- [ ] Install [Python](https://www.python.org/downloads/)
- [ ] Install [Visual Studio Code](https://code.visualstudio.com/download)
- [ ] Install [VSC - Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
- [ ] Install [Jupyter Notebook for python](https://python.land/data-science/jupyter-notebook)
- [ ] Install necessary packages: `pip install -r requirements.txt`

## Setup Environmental Variables in `.env'`
After creating an Azure OpenAI service, setup the following environmental variables for
- AZURE_OPENAI_ENDPOINT
- AZURE_OPENAI_KEY
- CHAT_COMPLETION_NAME
- EMBEDDING_MODEL_NAME _(Required for 01_OpenAI_getting-started)_
- BING_SUBSCRIPTION_KEY _(Required for 08_LLM_RAG_demo)_
- AZURE_OPENAI_API_KEY_GPT4V _(Required for 10_GPT-4V)_
- AZURE_OPENAI_API_BASE_GPT4V _(Required for 10_GPT-4V)_
- AZURE_OPENAI_DEPLOYMENT_NAME_GPT4V _(Required for 10_GPT-4V)_
---
Feel free to use and copy `.env.sample` and rename to `.env`.
8 changes: 8 additions & 0 deletions quick_start/v1/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AZURE_OPENAI_ENDPOINT=https://<your service name>.openai.azure.com/
AZURE_OPENAI_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
AZURE_OPENAI_API_KEY_GPT4V=xxxxxxxxxxxxxxxxxxxxxxxx
AZURE_OPENAI_API_BASE_GPT4V=https://<your service name>.openai.azure.com/
AZURE_OPENAI_DEPLOYMENT_NAME_GPT4V=gpt-4-vision
CHAT_COMPLETION_NAME=gpt-4o
EMBEDDING_MODEL_NAME=text-embedding-ada-002
BING_SUBSCRIPTION_KEY=xxxxxxxxxxxxxxxxxxxxxxxx
121 changes: 112 additions & 9 deletions quick_start/v1/02_ChatCompletion_api.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# OpenAI Chat Completion"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Overview \n",
"OpenAI Chat Completion allows you to interact with language models in a conversational manner. \\\n",
"This feature enables you to create chatbots, virtual assistants, and other conversational AI applications by providing a series of messages as input and receiving a model-generated message as output.\n",
"\n",
"For more detailed examples, refer to the official [Azure OpenAI Chat Completion Documentation.](https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cpython-new&pivots=programming-language-python)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. Import helper libraries and instantiate credentials and model"
]
},
{
"cell_type": "code",
"execution_count": 2,
Expand All @@ -18,7 +43,19 @@
" azure_endpoint = os.getenv(\"AZURE_OPENAI_ENDPOINT\"), \n",
" api_key=os.getenv(\"AZURE_OPENAI_KEY\"), \n",
" api_version=\"2024-02-15-preview\"\n",
")"
")\n",
"\n",
"CHAT_COMPLETIONS_MODEL = os.getenv('CHAT_COMPLETION_NAME') # model = \"deployment_name\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using Chat Completion\n",
"To use the chat completion feature, you need to provide a sequence of messages as input. \\\n",
"Each message should have a role (either \"system\", \"user\", or \"assistant\") and content.\n",
"Here is a simple example to demonstrate how to use chat completion:"
]
},
{
Expand All @@ -45,13 +82,37 @@
"message_text = [{\"role\":\"system\",\"content\":prompt}]\n",
"\n",
"response = client.chat.completions.create(\n",
" model=os.getenv(\"CHAT_COMPLETION_NAME\"), # model = \"deployment_name\"\n",
" model = CHAT_COMPLETIONS_MODEL,\n",
" messages = message_text,\n",
")\n",
"\n",
"response.choices[0].message.content"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Use cases to explore\n",
"1. **Customer Support**\\\n",
"Create a virtual assistant to handle your queries.\n",
"\n",
"2. **Educational Tools** \\\n",
"Build an interactive tutor for various subjects like onboarding in your company.\n",
"\n",
"3. **Personal Assistant** \\\n",
"Develop a personal assistant for scheduling, reminders, and other tasks and integrate it later on with modern work solutions."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Analyzing Customer Feedback\n",
"This example demonstrates how to use the OpenAI Chat Completion feature to analyze customer feedback. \\\n",
"The task is to determine whether the provided feedback is positive or negative."
]
},
{
"cell_type": "code",
"execution_count": 6,
Expand All @@ -78,13 +139,47 @@
"message_text = [{\"role\":\"system\",\"content\":prompt}]\n",
"\n",
"response = client.chat.completions.create(\n",
" model=os.getenv(\"CHAT_COMPLETION_NAME\"), # model = \"deployment_name\"\n",
" model = CHAT_COMPLETIONS_MODEL,\n",
" messages = message_text,\n",
")\n",
"\n",
"response.choices[0].message.content"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Use cases to explore\n",
"\n",
"1. **Sentiment Analysis** \\\n",
"Use this approach to analyze customer feedback and categorize it into positive or negative sentiment.\n",
"\n",
"2. **Product Review Monitoring** \\\n",
"Monitor your product reviews to quickly identify and address negative feedback.\n",
"\n",
"3. **Customer Support** \\\n",
"Enhance customer support by automating the analysis of feedback and prioritizing responses to negative reviews."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extracting PII (Personally Identifiable Information) Data\n",
"\n",
"**Regulatory Compliance:** \\\n",
"With the rise of data privacy regulations such as GDPR, CCPA, and HIPAA, identifying and protecting PII has become critical. \\\n",
"Organizations must ensure that PII is handled appropriately to avoid legal repercussions and maintain customer trust.\n",
"\n",
"**Risk Management:** \\\n",
" Exposing PII can lead to identity theft, financial loss, and reputational damage. \\\n",
" Effective PII detection and protection are essential components of an organization's risk management strategy.\n",
"\n",
"This example demonstrates how to use the OpenAI Chat Completion feature to extract Personally Identifiable Information (PII) from a given text. \\\n",
"The task is to identify and list all PII data present in the provided statement.\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
Expand All @@ -109,19 +204,27 @@
"message_text = [{\"role\":\"system\",\"content\":prompt}]\n",
"\n",
"response = client.chat.completions.create(\n",
" model=os.getenv(\"CHAT_COMPLETION_NAME\"), # model = \"deployment_name\"\n",
" model = CHAT_COMPLETIONS_MODEL,\n",
" messages = message_text,\n",
")\n",
"\n",
"response.choices[0].message.content"
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": []
"source": [
"#### Use cases to explore\n",
"1. **Data Privacy** \\\n",
"Ensure compliance with data privacy regulations by identifying and protecting PII in text data.\n",
"\n",
"2. **Information Security** \\\n",
"Enhance information security by automatically detecting and handling PII in documents and communications.\n",
"\n",
"3. **Customer Data Management** \\\n",
"Manage customer data effectively by identifying and categorizing PII for secure storage and processing."
]
}
],
"metadata": {
Expand All @@ -140,7 +243,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "0.0.0"
"version": "3.11.9"
},
"orig_nbformat": 4
},
Expand Down
Loading