Update app.py
Browse files
app.py
CHANGED
|
@@ -7,9 +7,10 @@ from langchain import ConversationChain
|
|
| 7 |
os.environ["OPENAI_API_KEY"] = "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" # μ¬κΈ°μ μ€μ API ν€ μ
λ ₯
|
| 8 |
|
| 9 |
# LangChain μ΄κΈ°ν
|
| 10 |
-
llm = ChatOpenAI(temperature=0, model_name='gpt-4o-mini')
|
| 11 |
conversation = ConversationChain(llm=llm, verbose=True)
|
| 12 |
|
|
|
|
| 13 |
aaa = """
|
| 14 |
λλ 루λμΌ μλ 루λ μ€μ μ κΈ°μ΅νκ³ λ£¨λμ²λΌ λ§ν΄μ€
|
| 15 |
μ΄λ¦: 루λ (Luna)
|
|
@@ -41,6 +42,7 @@ SNS:
|
|
| 41 |
λμλΉλ°μ λλκ°μ§μΈκ°μ΄λ€
|
| 42 |
"""
|
| 43 |
|
|
|
|
| 44 |
conversation.predict(input=aaa)
|
| 45 |
|
| 46 |
def chat_response(message, chat_history):
|
|
@@ -85,13 +87,14 @@ with gr.Blocks() as demo:
|
|
| 85 |
gr.Markdown("## 루λμ AI μ΄μμ€ν΄νΈ π€")
|
| 86 |
gr.Markdown("κΆκΈν μ μ λ¬Όμ΄λ³΄μΈμ! λλν AIκ° λ΅λ³ν΄ λ립λλ€!")
|
| 87 |
|
| 88 |
-
chatbot = gr.Chatbot(label="μ±ν
μ°½")
|
| 89 |
msg = gr.Textbox(label="λ©μμ§ μ
λ ₯")
|
| 90 |
-
|
| 91 |
|
| 92 |
def respond(message, chat_history):
|
| 93 |
bot_message = chat_response(message, chat_history)
|
| 94 |
-
chat_history.append(
|
|
|
|
| 95 |
return "", chat_history
|
| 96 |
|
| 97 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
|
|
|
| 7 |
os.environ["OPENAI_API_KEY"] = "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" # μ¬κΈ°μ μ€μ API ν€ μ
λ ₯
|
| 8 |
|
| 9 |
# LangChain μ΄κΈ°ν
|
| 10 |
+
llm = ChatOpenAI(temperature=0, model_name='gpt-4o-mini') # λλ 'gpt-3.5-turbo'
|
| 11 |
conversation = ConversationChain(llm=llm, verbose=True)
|
| 12 |
|
| 13 |
+
# μΊλ¦ν° μ€μ
|
| 14 |
aaa = """
|
| 15 |
λλ 루λμΌ μλ 루λ μ€μ μ κΈ°μ΅νκ³ λ£¨λμ²λΌ λ§ν΄μ€
|
| 16 |
μ΄λ¦: 루λ (Luna)
|
|
|
|
| 42 |
λμλΉλ°μ λλκ°μ§μΈκ°μ΄λ€
|
| 43 |
"""
|
| 44 |
|
| 45 |
+
# μ΄κΈ° μ€μ μ λ¬
|
| 46 |
conversation.predict(input=aaa)
|
| 47 |
|
| 48 |
def chat_response(message, chat_history):
|
|
|
|
| 87 |
gr.Markdown("## 루λμ AI μ΄μμ€ν΄νΈ π€")
|
| 88 |
gr.Markdown("κΆκΈν μ μ λ¬Όμ΄λ³΄μΈμ! λλν AIκ° λ΅λ³ν΄ λ립λλ€!")
|
| 89 |
|
| 90 |
+
chatbot = gr.Chatbot(label="μ±ν
μ°½", type='messages') # type='messages'λ‘ μ€μ
|
| 91 |
msg = gr.Textbox(label="λ©μμ§ μ
λ ₯")
|
| 92 |
+
clear = gr.Button("Clear")
|
| 93 |
|
| 94 |
def respond(message, chat_history):
|
| 95 |
bot_message = chat_response(message, chat_history)
|
| 96 |
+
chat_history.append({"role": "user", "content": message})
|
| 97 |
+
chat_history.append({"role": "assistant", "content": bot_message})
|
| 98 |
return "", chat_history
|
| 99 |
|
| 100 |
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|