ChatGPT Prompt Engineering for Developers
6 - Expanding ์ ๋ฆฌ
Setup
import openai
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.getenv('OPENAI_API_KEY')
def get_completion(prompt, model="gpt-3.5-turbo",temperature=0): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]
Expanding
1) ๊ณ ๊ฐ ๋ฆฌ๋ทฐ ์๋์๋ต
์ฃผ์ด์ง Sentiment(๊ฐ์ positive/negative)์ ํ์ฉํ์ฌ ๊ณ ๊ฐ ๋ฆฌ๋ทฐ ์์ฑ
<prompt task>
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for their review.
If the sentiment is negative, apologize and suggest that they can reach out to customer service.
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
translate in korean.
Customer review: ```{review}```
Review sentiment: {sentiment}
+ Model์ Exploration(์์ ๋) Expanding / Temperature Randomness
Temperature๋ฅผ ๋์ฌ ํน์ ํค์๋์ ๋ํ ์ธ๊ธ ๋น๋๋ฅผ ๋๋ค์ฑ์ผ๋ก ์ถ๊ฐํ๋ค.
prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service.
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
translate in korean.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt, temperature=0.7)
print(response)
Temperature์ ์ ๋์ ๋ฐ๋ผ ๊ฐ์ parameter๋ผ๋ ๋ค๋ฅธ ๊ฐ์ด ๋์ค๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค.
'๐ ๏ธ Tools > ๐ค ChatGPT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[OpenAI-GPT] LangChain ํจ์จ์ ์ธ Token ๊ด๋ฆฌ (0) | 2023.05.21 |
---|---|
[LLM] ChatGPT Prompt Engineering for Developers - Chatbot (0) | 2023.05.07 |
[LLM] ChatGPT Prompt Engineering for Developers - Transforming (0) | 2023.05.05 |
[LLM] ChatGPT Prompt Engineering for Developers - Inferring (0) | 2023.05.04 |
[LLM] ChatGPT Prompt Engineering for Developers - Summarizing (0) | 2023.05.04 |