-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from infosatheesh2020/main
Updated ch06 with chat completion methods for newer models
- Loading branch information
Showing
7 changed files
with
130 additions
and
51 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
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
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,36 @@ | ||
from openai import AzureOpenAI | ||
import os | ||
import dotenv | ||
|
||
# import dotenv | ||
dotenv.load_dotenv() | ||
|
||
# configure Azure OpenAI service client | ||
client = AzureOpenAI( | ||
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"], | ||
api_key=os.environ['AZURE_OPENAI_KEY'], | ||
api_version = "2023-10-01-preview" | ||
) | ||
|
||
deployment=os.environ['AZURE_OPENAI_DEPLOYMENT'] | ||
|
||
# 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. |
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,39 @@ | ||
from openai import AzureOpenAI | ||
import os | ||
import dotenv | ||
|
||
# import dotenv | ||
dotenv.load_dotenv() | ||
|
||
# configure Azure OpenAI service client | ||
client = AzureOpenAI( | ||
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"], | ||
api_key=os.environ['AZURE_OPENAI_KEY'], | ||
api_version = "2023-10-01-preview" | ||
) | ||
|
||
deployment=os.environ['AZURE_OPENAI_DEPLOYMENT'] | ||
|
||
# add your completion code | ||
question = input("Ask your questions on python language to your study buddy: ") | ||
prompt = f""" | ||
You are an expert on the python language. | ||
Whenever certain questions are asked, you need to provide response in below format. | ||
- Concept | ||
- Example code showing the concept implementation | ||
- explanation of the example and how the concept is done for the user to understand better. | ||
Provide answer for the question: {question} | ||
""" | ||
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