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)

 

 

๋ฐ˜์‘ํ˜•
๋‹คํ–ˆ๋‹ค