콘텐츠로 이동

고객문의사항 분류하기

필요한 모듈 설치하기

!pip install openai
!pip install gradio

고객 문의사항 분류하기

from openai import OpenAI
import gradio as gr

client = OpenAI()

def predict(message, history):

    history_openai_format = []
    history_openai_format.append({"role": "system", "content":"역할: 너는 이제 부품소재 회사의 고객지원 담당자야."})
    history_openai_format.append({"role": "system", "content":"지시사항: 고객이 질문한 내용을 아래의 항목으로 정리해줘."})
    history_openai_format.append({"role": "system", "content":"정리할 항목: '제목', '분야', '내용'으로 고객의 문의사항을 정리해줘."})
    history_openai_format.append({"role": "system", "content":"분류할 분야: '기술지원', '영업', '생산' 중에서 한 가지로 고객의 문의사항을 분류해줘."})

    for human, assistant in history:
        history_openai_format.append({"role": "user", "content": human })
        history_openai_format.append({"role": "assistant", "content":assistant})

    history_openai_format.append({"role": "user", "content": message})

    response = client.chat.completions.create(model='gpt-4o-mini',
    messages= history_openai_format,
    temperature=1.0,
    stream=True)

    partial_message = ""

    for chunk in response:
        if chunk.choices[0].delta.content is not None:
              partial_message = partial_message + chunk.choices[0].delta.content
              yield partial_message

with gr.Blocks() as demo:
    gr.Markdown(
    """
    # 한국전자 고객지원 챗봇
    한국전자의 제품에 대해서 궁금한 사항이 있으면 질문해 주세요.
    """)
    gr.ChatInterface(predict)

demo.launch()

청소기 전원이 켜지지 않아요