Update app.py
Browse files
app.py
CHANGED
|
@@ -55,15 +55,20 @@ 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 |
-
|
|
|
|
|
|
|
| 59 |
return
|
| 60 |
|
| 61 |
if not session_id:
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
return
|
| 64 |
|
| 65 |
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
|
| 66 |
-
history = history
|
|
|
|
| 67 |
yield history
|
| 68 |
|
| 69 |
# ์คํธ๋ฆฌ๋ฐ ์๋ต
|
|
@@ -90,14 +95,13 @@ def chat_streaming(message: str, user_email: str, session_id: str,
|
|
| 90 |
chunk = json.loads(data)
|
| 91 |
content = chunk.get("content", "")
|
| 92 |
full_response += content
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
{"role": "assistant", "content": full_response}
|
| 96 |
-
]
|
| 97 |
except json.JSONDecodeError:
|
| 98 |
continue
|
| 99 |
except Exception as e:
|
| 100 |
-
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
async def get_health_current(user_email: str) -> str:
|
|
@@ -181,7 +185,7 @@ async def delete_memory(memory_id: int, user_email: str) -> str:
|
|
| 181 |
try:
|
| 182 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 183 |
response = await client.delete(
|
| 184 |
-
f"{API_BASE_URL}/memory/{memory_id}",
|
| 185 |
params={"user_email": user_email}
|
| 186 |
)
|
| 187 |
result = response.json()
|
|
@@ -257,7 +261,7 @@ async def upload_file(file, session_id: str, user_email: str) -> str:
|
|
| 257 |
|
| 258 |
|
| 259 |
# Gradio UI ๊ตฌ์ฑ
|
| 260 |
-
with gr.Blocks(title="KT API ํ
์คํธ"
|
| 261 |
gr.Markdown("# ๐งช KT ์๋์ด AI ๋น์ API ํ
์คํธ")
|
| 262 |
gr.Markdown(f"**API URL:** `{API_BASE_URL}`")
|
| 263 |
|
|
@@ -279,7 +283,7 @@ with gr.Blocks(title="KT API ํ
์คํธ", theme=gr.themes.Soft()) as demo:
|
|
| 279 |
self_learning_check = gr.Checkbox(label="์๊ฐ ํ์ต ํ์ฑํ", value=True)
|
| 280 |
|
| 281 |
with gr.Column(scale=2):
|
| 282 |
-
chatbot = gr.Chatbot(label="๋ํ", height=400
|
| 283 |
msg_input = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
| 284 |
send_btn = gr.Button("์ ์ก", variant="primary")
|
| 285 |
|
|
|
|
| 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([message, ""])
|
| 72 |
yield history
|
| 73 |
|
| 74 |
# ์คํธ๋ฆฌ๋ฐ ์๋ต
|
|
|
|
| 95 |
chunk = json.loads(data)
|
| 96 |
content = chunk.get("content", "")
|
| 97 |
full_response += content
|
| 98 |
+
history[-1][1] = full_response
|
| 99 |
+
yield history
|
|
|
|
|
|
|
| 100 |
except json.JSONDecodeError:
|
| 101 |
continue
|
| 102 |
except Exception as e:
|
| 103 |
+
history[-1][1] = f"โ ์ค๋ฅ: {str(e)}"
|
| 104 |
+
yield history
|
| 105 |
|
| 106 |
|
| 107 |
async def get_health_current(user_email: str) -> str:
|
|
|
|
| 185 |
try:
|
| 186 |
async with httpx.AsyncClient(timeout=30.0) as client:
|
| 187 |
response = await client.delete(
|
| 188 |
+
f"{API_BASE_URL}/memory/{int(memory_id)}",
|
| 189 |
params={"user_email": user_email}
|
| 190 |
)
|
| 191 |
result = response.json()
|
|
|
|
| 261 |
|
| 262 |
|
| 263 |
# Gradio UI ๊ตฌ์ฑ
|
| 264 |
+
with gr.Blocks(title="KT API ํ
์คํธ") as demo:
|
| 265 |
gr.Markdown("# ๐งช KT ์๋์ด AI ๋น์ API ํ
์คํธ")
|
| 266 |
gr.Markdown(f"**API URL:** `{API_BASE_URL}`")
|
| 267 |
|
|
|
|
| 283 |
self_learning_check = gr.Checkbox(label="์๊ฐ ํ์ต ํ์ฑํ", value=True)
|
| 284 |
|
| 285 |
with gr.Column(scale=2):
|
| 286 |
+
chatbot = gr.Chatbot(label="๋ํ", height=400)
|
| 287 |
msg_input = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
| 288 |
send_btn = gr.Button("์ ์ก", variant="primary")
|
| 289 |
|