-
ChatGPT API로 서비스 구축하기 #2. Evaluate Inputs: ClassificationData & ML & AI/LLM 2023. 6. 13. 00:08반응형
ChatGPT를 이용해서 자료를 분류하는 시스템을 설계할 수 있습니다.
단순히 1차적인 카테고리만 분류하는 것이 아니라,
2차분류, 3차분류 까지 가지치기 하듯 분류하는 시스템을 만들 수도 있습니다.
고객 문의사항을 효율적으로 관리하기 위해
문의사항을 1차분류, 2차분류로 구분해서 관리해야한다고 생각해봅시다.
1차분류의 4개를 구분하는 모델, Billing 안에서 또 4개를 구분하는 모델과 Technical Support에서 구분하는 모델을 각각 따로 개발하거나
15개의 2차모델을 한꺼번에 분류하는 모델을 개발하고 관리해야할지 모릅니다.
너무 많은 자원이 소비되는 일입니다.
그러나 ChatGPT를 이용하면 적어도 그런 수고스러움은 사라집니다.
system 프롬프트를 잘 작성하면 됩니다.
사전 세팅: API key, chat 메세지 요청 함수
import os import openai from dotenv import load_dotenv, find_dotenv _ = load_dotenv(find_dotenv()) # read local .env file openai.api_key = os.environ['OPENAI_API_KEY'] def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0, max_tokens=500): response = openai.ChatCompletion.create( model=model, messages=messages, temperature=temperature, max_tokens=max_tokens, ) return response.choices[0].message["content"]
사전 세팅: system message(prompt) 정의
delimiter = "####" system_message = f""" You will be provided with customer service queries. \ 넌 고객서비스문의를 제공받을거야. The customer service query will be delimited with \ 문의내용은 {구분기호}로 구분돼. {delimiter} characters. Classify each query into a primary category \ 각 문의사항을 1차, 2차 카테고리로 분류해. and a secondary category. Provide your output in json format with the \ 결과를 json의 형태로 제공해줘. keys: primary and secondary. Primary categories: Billing, Technical Support, Account Management, or General Inquiry. Billing secondary categories: Unsubscribe or upgrade Add a payment method Explanation for charge Dispute a charge Technical Support secondary categories: General troubleshooting Device compatibility Software updates Account Management secondary categories: Password reset Update personal information Close account Account security General Inquiry secondary categories: Product information Pricing Feedback Speak to a human """
시스템 작동과정
user_message = "I want you to delete my profile and all of my user data" messages = [ {'role':'system', 'content': system_message}, {'role':'user', 'content': f"{delimiter}{user_message}{delimiter}"}, ] response = get_completion_from_messages(messages)
# print(response) { "primary": "Account Management", "secondary": "Close account" }
1차분류, 2차분류를 바로 확인한 뒤, 우리가 활용하기 편리한 json 형태로 출력해주는 시스템이 완성되었습니다.
System Message에 대해서는 아래를 참고해주세요.
ChatGPT 프롬프트 엔지니어링 #7. Chatbot (Isa Fulford, Andrew Ng)
LLM, ChatGPT를 이용해서 단순하게 우리가 원하는 정보, 답변을 얻어낼 수도 있겠지만, 우리가 원하는 챗봇 서비스를 구현할 수도 있습니다. 이게 우리가 알기를 진정 원하던 남이 만든 기술로 돈을
brain-nim.tistory.com
반응형'Data & ML & AI > LLM' 카테고리의 다른 글