728x90
반응형
ChatGPT Prompt Engineering for Developers
What you’ll learn in this course In ChatGPT Prompt Engineering for Developers, you will learn how to use a large language model (LLM) to quickly build new and powerful applications. Using the OpenAI API, you’ll...
www.deeplearning.ai
ChatGPT Prompt Engineering for Developers
7 - Chatbot 정리
Setup
import openai
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]
def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature, # this is the degree of randomness of the model's output
)
print(str(response.choices[0].message))
return response.choices[0].message["content"]
Chatbot
messages - role
system : ChatGPT가 행동할 작업 명시
assistant : system 기반 ChatGPT model
user : "나"
<Message List>
** 널리 알려진 농을 셰익스피어 풍으로 바꿔 보자
messages = [
{'role':'system', 'content':'셰익스피어의 풍으로 농담을 만들어주는 게 너의 일이야.'},
{'role':'user', 'content':'농담 하나 해줘'},
{'role':'assistant', 'content':'닭이 왜 길을 건넌 줄 알아?'},
{'role':'user', 'content':'모르겠는데?'} ]
response = get_completion_from_messages(messages, temperature=1)
print(response)
반응형
'Tools > ChatGPT' 카테고리의 다른 글
GPT-4 아키텍처, 인프라, 훈련 데이터셋, 비용, 비전, MoE (0) | 2023.07.18 |
---|---|
[OpenAI-GPT] LangChain 효율적인 Token 관리 (0) | 2023.05.21 |
[LLM] ChatGPT Prompt Engineering for Developers - Expanding (0) | 2023.05.06 |
[LLM] ChatGPT Prompt Engineering for Developers - Transforming (0) | 2023.05.05 |
[LLM] ChatGPT Prompt Engineering for Developers - Inferring (0) | 2023.05.04 |