Update app.py
Browse files
app.py
CHANGED
|
@@ -53,22 +53,23 @@ async def end_session(session_id: str, user_email: str) -> str:
|
|
| 53 |
|
| 54 |
def chat_streaming(message: str, user_email: str, session_id: str,
|
| 55 |
web_search: bool, self_learning: bool, history: list) -> Generator:
|
| 56 |
-
"""์คํธ๋ฆฌ๋ฐ ์ฑํ
-
|
| 57 |
if not user_email:
|
| 58 |
history = history or []
|
| 59 |
-
history.append(
|
| 60 |
yield history
|
| 61 |
return
|
| 62 |
|
| 63 |
if not session_id:
|
| 64 |
history = history or []
|
| 65 |
-
history.append(
|
| 66 |
yield history
|
| 67 |
return
|
| 68 |
|
| 69 |
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
|
| 70 |
history = history or []
|
| 71 |
-
history.append(
|
|
|
|
| 72 |
yield history
|
| 73 |
|
| 74 |
# ์คํธ๋ฆฌ๋ฐ ์๋ต
|
|
@@ -95,12 +96,12 @@ def chat_streaming(message: str, user_email: str, session_id: str,
|
|
| 95 |
chunk = json.loads(data)
|
| 96 |
content = chunk.get("content", "")
|
| 97 |
full_response += content
|
| 98 |
-
history[-1][
|
| 99 |
yield history
|
| 100 |
except json.JSONDecodeError:
|
| 101 |
continue
|
| 102 |
except Exception as e:
|
| 103 |
-
history[-1][
|
| 104 |
yield history
|
| 105 |
|
| 106 |
|
|
@@ -262,8 +263,8 @@ with gr.Blocks(title="KT API ํ
์คํธ") as demo:
|
|
| 262 |
self_learning_check = gr.Checkbox(label="์๊ฐ ํ์ต ํ์ฑํ", value=True)
|
| 263 |
|
| 264 |
with gr.Column(scale=2):
|
| 265 |
-
#
|
| 266 |
-
chatbot = gr.Chatbot(label="๋ํ", height=400
|
| 267 |
msg_input = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
| 268 |
send_btn = gr.Button("์ ์ก", variant="primary")
|
| 269 |
|
|
|
|
| 53 |
|
| 54 |
def chat_streaming(message: str, user_email: str, session_id: str,
|
| 55 |
web_search: bool, self_learning: bool, history: list) -> Generator:
|
| 56 |
+
"""์คํธ๋ฆฌ๋ฐ ์ฑํ
- messages ํ์ ์ฌ์ฉ (๋์
๋๋ฆฌ)"""
|
| 57 |
if not user_email:
|
| 58 |
history = history or []
|
| 59 |
+
history.append({"role": "assistant", "content": "โ ์ด๋ฉ์ผ์ ๋จผ์ ์
๋ ฅํด์ฃผ์ธ์."})
|
| 60 |
yield history
|
| 61 |
return
|
| 62 |
|
| 63 |
if not session_id:
|
| 64 |
history = history or []
|
| 65 |
+
history.append({"role": "assistant", "content": "โ ์ธ์
์ ๋จผ์ ์์ฑํด์ฃผ์ธ์."})
|
| 66 |
yield history
|
| 67 |
return
|
| 68 |
|
| 69 |
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
|
| 70 |
history = history or []
|
| 71 |
+
history.append({"role": "user", "content": message})
|
| 72 |
+
history.append({"role": "assistant", "content": ""})
|
| 73 |
yield history
|
| 74 |
|
| 75 |
# ์คํธ๋ฆฌ๋ฐ ์๋ต
|
|
|
|
| 96 |
chunk = json.loads(data)
|
| 97 |
content = chunk.get("content", "")
|
| 98 |
full_response += content
|
| 99 |
+
history[-1]["content"] = full_response
|
| 100 |
yield history
|
| 101 |
except json.JSONDecodeError:
|
| 102 |
continue
|
| 103 |
except Exception as e:
|
| 104 |
+
history[-1]["content"] = f"โ ์ค๋ฅ: {str(e)}"
|
| 105 |
yield history
|
| 106 |
|
| 107 |
|
|
|
|
| 263 |
self_learning_check = gr.Checkbox(label="์๊ฐ ํ์ต ํ์ฑํ", value=True)
|
| 264 |
|
| 265 |
with gr.Column(scale=2):
|
| 266 |
+
# messages ํ์ ์ฌ์ฉ (๊ธฐ๋ณธ๊ฐ)
|
| 267 |
+
chatbot = gr.Chatbot(label="๋ํ", height=400)
|
| 268 |
msg_input = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
| 269 |
send_btn = gr.Button("์ ์ก", variant="primary")
|
| 270 |
|