openfree commited on
Commit
dde530a
ยท
verified ยท
1 Parent(s): 1c47de2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
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([message, ""])
 
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][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
 
@@ -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
- # โœ… ํ•ต์‹ฌ ์ˆ˜์ •: type="tuples" ์ถ”๊ฐ€
266
- chatbot = gr.Chatbot(label="๋Œ€ํ™”", height=400, type="tuples")
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