728x90
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 |