forked from microsoft/generative-ai-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating classes 00, adding OpenAI samples to 06 and 09 to the course.
- Loading branch information
1 parent
c586374
commit 6d23659
Showing
12 changed files
with
1,313 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.