Skip to content

Commit

Permalink
Updating classes 00, adding OpenAI samples to 06 and 09 to the course.
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloNunes committed Feb 9, 2024
1 parent c586374 commit 6d23659
Show file tree
Hide file tree
Showing 12 changed files with 1,313 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .env.copy
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Azure OpenAI configuration
AZURE_OPENAI_ENDPOINT='<add your endpoint here>'
AZURE_OPENAI_DEPLOYMENT='<add your deployment name here>'
AZURE_OPENAI_KEY='<add your key here>'
AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT='<add your deployment name here>'

# OpenAI Configuration
OPENAI_API_KEY='<add your OpenAI key here>'
4 changes: 4 additions & 0 deletions 00-course-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ While you wait for your application to be processed, each coding lesson also inc

If this is your first time working with the Azure OpenAI service, please follow this guide on how to [create and deploy an Azure OpenAI Service resource.](https://learn.microsoft.com/azure/ai-services/openai/how-to/create-resource?pivots=web-portal&WT.mc_id=academic-105485-koreyst)

## Using the OpenAI API for the First Time

If this is your first working with the OpenAI API, please follow the guide on how to [create and use the Interface.](https://platform.openai.com/docs/quickstart?context=pythont&WT.mc_id=academic-105485-koreyst)

## Meet Other Learners

We have created channels in our official [AI Community Discord server](https://aka.ms/genai-discord?WT.mc_id=academic-105485-koreyst) for meeting other learners. This is a great way to network with other like-minded entrepreneurs, builders, students, and anyone looking to level up in Generative AI.
Expand Down
41 changes: 41 additions & 0 deletions 06-text-generation-apps/openai/app-recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from openai import OpenAI
import os
import dotenv

# import dotenv
dotenv.load_dotenv()

# configure Azure OpenAI service client
client = OpenAI()

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

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

ingredients = input("List of ingredients (for example, chicken, potatoes, and carrots: ")

filter = input("Filter (for example, vegetarian, vegan, or gluten-free: ")

# interpolate the number of recipes into the prompt an ingredients
prompt = f"Show me {no_recipes} recipes for a dish with the following ingredients: {ingredients}. Per recipe, list all the ingredients used, no {filter}: "
messages = [{"role": "user", "content": prompt}]

completion = client.chat.completions.create(model=deployment, messages=messages, max_tokens=600, temperature = 0.1)


# print response
print("Recipes:")
print(completion.choices[0].message.content)

old_prompt_result = completion.choices[0].message.content
prompt_shopping = "Produce a shopping list, and please don't include ingredients that I already have at home: "

new_prompt = f"Given ingredients at home {ingredients} and these generated recipes: {old_prompt_result}, {prompt_shopping}"
messages = [{"role": "user", "content": new_prompt}]
completion = client.chat.completions.create(model=deployment, messages=messages, max_tokens=600, temperature=0)

# print response
print("\n=====Shopping list ======= \n")
print(completion.choices[0].message.content)

25 changes: 25 additions & 0 deletions 06-text-generation-apps/openai/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from openai import OpenAI
import os
import dotenv

# import dotenv
dotenv.load_dotenv()

# configure OpenAI service client
client = OpenAI()

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

# add your completion code
prompt = "Complete the following: Once upon a time there was a"
messages = [{"role": "user", "content": prompt}]
# make completion
completion = client.chat.completions.create(model=deployment, messages=messages)

# print response
print(completion.choices[0].message.content)

# very unhappy _____.

# Once upon a time there was a very unhappy mermaid.
31 changes: 31 additions & 0 deletions 06-text-generation-apps/openai/history-bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from openai import OpenAI
import os
import dotenv

# import dotenv
dotenv.load_dotenv()

# configure Azure OpenAI service client
client = OpenAI()
deployment="gpt-3.5-turbo"

# add your completion code
persona = input("Tell me the historical character I want to be: ")
question = input("Ask your question about the historical character: ")
prompt = f"""
You are going to play as a historical character {persona}.
Whenever certain questions are asked, you need to remember facts about the timelines and incidents and respond the accurate answer only. Don't create content yourself. If you don't know something, tell that you don't remember.
Provide answer for the question: {question}
"""
messages = [{"role": "user", "content": prompt}]
# make completion
completion = client.chat.completions.create(model=deployment, messages=messages, temperature=0)

# print response
print(completion.choices[0].message.content)

# very unhappy _____.

# Once upon a time there was a very unhappy mermaid.
Loading

0 comments on commit 6d23659

Please sign in to comment.