ginipick commited on
Commit
2c18e26
ยท
verified ยท
1 Parent(s): 1a773fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -181,7 +181,7 @@ def explain_usage(app_content: str):
181
  "You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. "
182
  "๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋ฒ•์„ ์ƒ์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”. Markdown ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”."
183
  )
184
- user_msg = f"๋‹ค์Œ Python ์ฝ”๋“œ์˜ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
185
  try:
186
  return gemini_chat_completion(system_msg, user_msg, max_tokens=800, temperature=0.7)
187
  except Exception as e:
@@ -189,12 +189,19 @@ def explain_usage(app_content: str):
189
 
190
  def stream_gemini_response(user_message: str, conversation_state: List[ChatMessage]) -> Iterator[List[ChatMessage]]:
191
  """
192
- Gemini์— ์ŠคํŠธ๋ฆฌ๋ฐ ์š”์ฒญ.
193
- user_message๊ฐ€ ๋น„์–ด ์žˆ์œผ๋ฉด, ์•„๋ฌด๊ฒƒ๋„ ํ•˜์ง€ ์•Š๊ณ  return.
194
  """
195
  if not user_message.strip():
196
- # ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€๊ฐ€ ๋นˆ ๊ฒฝ์šฐ: ์•„๋ฌด ๋ฉ”์‹œ์ง€๋„ ์ถ”๊ฐ€ ์•ˆ ํ•จ, LLM ํ˜ธ์ถœ๋„ ์•ˆ ํ•จ.
197
- return # yield๋„ ์—†์ด ๊ทธ๋ƒฅ ์ข…๋ฃŒ
 
 
 
 
 
 
 
198
 
199
  print(f"\n=== New Request ===\nUser message: {user_message}")
200
  chat_history = format_chat_history(conversation_state)
@@ -266,7 +273,7 @@ def stream_gemini_response(user_message: str, conversation_state: List[ChatMessa
266
 
267
  def convert_for_messages_format(messages: List[ChatMessage]) -> List[Dict[str, str]]:
268
  """
269
- ChatMessage ๋ฆฌ์ŠคํŠธ -> [{"role":"...", "content":"..."}] ๋ชฉ๋ก
270
  """
271
  output = []
272
  for msg in messages:
@@ -275,7 +282,6 @@ def convert_for_messages_format(messages: List[ChatMessage]) -> List[Dict[str, s
275
 
276
  def user_submit_message(msg: str, conversation_state: List[ChatMessage]):
277
  conversation_state.append(ChatMessage(role="user", content=msg))
278
- # ์ž…๋ ฅ์ฐฝ ๋น„์›€
279
  return "", conversation_state
280
 
281
  def respond_wrapper(message: str, conversation_state: List[ChatMessage], max_tokens, temperature, top_p):
@@ -321,10 +327,11 @@ def create_ui():
321
  with gr.TabItem("AI ์ฝ”๋“œ์ฑ—"):
322
  gr.Markdown("## ์˜ˆ์ œ๋ฅผ ์ž…๋ ฅ ๋˜๋Š” ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ณ  ์งˆ๋ฌธํ•˜์„ธ์š”")
323
 
 
324
  chatbot = gr.Chatbot(
325
  label="๋Œ€ํ™”",
326
  height=400,
327
- type="messages"
328
  )
329
 
330
  msg = gr.Textbox(
 
181
  "You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. "
182
  "๋‹น์‹ ์€ Python ์ฝ”๋“œ๋ฅผ ๋ถ„์„ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•˜๋Š” AI ์กฐ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋งˆ์น˜ ํ™”๋ฉด์„ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์‚ฌ์šฉ๋ฒ•์„ ์ƒ์„ธํžˆ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”. Markdown ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”."
183
  )
184
+ user_msg = f"๋‹ค์Œ Python ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉ๋ฒ•์„ ์„ค๋ช…ํ•ด์ฃผ์„ธ์š”:\n\n{app_content}"
185
  try:
186
  return gemini_chat_completion(system_msg, user_msg, max_tokens=800, temperature=0.7)
187
  except Exception as e:
 
189
 
190
  def stream_gemini_response(user_message: str, conversation_state: List[ChatMessage]) -> Iterator[List[ChatMessage]]:
191
  """
192
+ Gemini์— ์ŠคํŠธ๋ฆฌ๋ฐ ์š”์ฒญ.
193
+ - user_message๊ฐ€ ๋น„์–ด ์žˆ์œผ๋ฉด, ์ตœ์†Œํ•œ์˜ ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€๋ฅผ assistant๋กœ ์ถ”๊ฐ€ํ•˜๊ณ  yield ํ›„ ์ข…๋ฃŒ
194
  """
195
  if not user_message.strip():
196
+ # ๋นˆ ์ž…๋ ฅ ์ฒ˜๋ฆฌ: ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
197
+ conversation_state.append(
198
+ ChatMessage(
199
+ role="assistant",
200
+ content="์ž…๋ ฅ์ด ์—†์Šต๋‹ˆ๋‹ค. ์งˆ๋ฌธ์„ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”!"
201
+ )
202
+ )
203
+ yield conversation_state
204
+ return
205
 
206
  print(f"\n=== New Request ===\nUser message: {user_message}")
207
  chat_history = format_chat_history(conversation_state)
 
273
 
274
  def convert_for_messages_format(messages: List[ChatMessage]) -> List[Dict[str, str]]:
275
  """
276
+ ChatMessage ๋ฆฌ์ŠคํŠธ -> [{"role":"assistant"/"user", "content":"..."}]
277
  """
278
  output = []
279
  for msg in messages:
 
282
 
283
  def user_submit_message(msg: str, conversation_state: List[ChatMessage]):
284
  conversation_state.append(ChatMessage(role="user", content=msg))
 
285
  return "", conversation_state
286
 
287
  def respond_wrapper(message: str, conversation_state: List[ChatMessage], max_tokens, temperature, top_p):
 
327
  with gr.TabItem("AI ์ฝ”๋“œ์ฑ—"):
328
  gr.Markdown("## ์˜ˆ์ œ๋ฅผ ์ž…๋ ฅ ๋˜๋Š” ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ๋„ฃ๊ณ  ์งˆ๋ฌธํ•˜์„ธ์š”")
329
 
330
+ # Chatbot: type="messages"
331
  chatbot = gr.Chatbot(
332
  label="๋Œ€ํ™”",
333
  height=400,
334
+ type="messages"
335
  )
336
 
337
  msg = gr.Textbox(