콘텐츠로 이동

교내식당 안내

필요한 모듈 설치하기

!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":"라면은 5,000원, 돈가스는 10,000원, 떡복이는 1,000원, 육계장은 8,000이야."})
    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()

학교에서 주문 가능한 메뉴를 알려줘
학교에서 가장 맛있는 음식을 추천해줘
라면은 얼마야?
돈가스 1개와 라면 2개를 주문하면 얼마지?