peterpeter8585 commited on
Commit
873bb2e
Β·
verified Β·
1 Parent(s): 295f49c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -425,40 +425,34 @@ def get_hf_user(token):
425
  return "guest"
426
  import re, json
427
 
428
- def chat(message, history, system_prompt):
429
  try:
430
  # μ‹œμŠ€ν…œ λ©”μ‹œμ§€ 포함 ν”„λ‘¬ν”„νŠΈ ꡬ성
431
- prompt = f"{system_prompt}\n\nμ‚¬μš©μž: {message}" if system_prompt else message
432
 
433
- raw_response = agent.invoke(prompt)
434
-
435
- # λ¬Έμžμ—΄ λ³€ν™˜
436
  text = str(raw_response)
437
 
438
- # βœ… JSON 블둝이 μžˆμ„ 경우 νŒŒμ‹±
 
439
  match = re.search(r"\{.*\}", text, re.DOTALL)
440
  if match:
441
  try:
442
  obj = json.loads(match.group(0))
443
- # "action_input" λ˜λŠ” "Final Answer" ν‚€ μš°μ„  좜λ ₯
444
- if "Final Answer" in obj:
445
- output = obj["Final Answer"]
446
- else:
447
- # ν˜Ήμ‹œ "output"μ΄λ‚˜ "content" 같은 ν‚€κ°€ 있으면 κ·Έκ±Έ μ‚¬μš©
448
- for k in ("output", "content", "answer"):
449
- if k in obj:
450
- output = obj[k]
451
- break
452
- else:
453
- output = text
454
  except Exception:
455
  output = text
456
- else:
457
- output = text
458
 
459
  except Exception as e:
460
  output = f"⚠️ 였λ₯˜: {e}"
461
 
 
462
  history = history + [(message, output)]
463
  return history, history, ""
464
  '''
 
425
  return "guest"
426
  import re, json
427
 
428
+ def chat(message, history,username="default_user"):
429
  try:
430
  # μ‹œμŠ€ν…œ λ©”μ‹œμ§€ 포함 ν”„λ‘¬ν”„νŠΈ ꡬ성
431
+ prompt=message
432
 
433
+ raw_response = agent.run(prompt)
 
 
434
  text = str(raw_response)
435
 
436
+ # βœ… JSON ν˜•νƒœλ‘œ 응닡 μ‹œ νŒŒμ‹±
437
+ output = text
438
  match = re.search(r"\{.*\}", text, re.DOTALL)
439
  if match:
440
  try:
441
  obj = json.loads(match.group(0))
442
+ output = (
443
+ obj.get("action_input")
444
+ or obj.get("Final Answer")
445
+ or obj.get("output")
446
+ or obj.get("content")
447
+ or text
448
+ )
 
 
 
 
449
  except Exception:
450
  output = text
 
 
451
 
452
  except Exception as e:
453
  output = f"⚠️ 였λ₯˜: {e}"
454
 
455
+ # βœ… Gradio용 μ±„νŒ… ν˜•μ‹ μ—…λ°μ΄νŠΈ
456
  history = history + [(message, output)]
457
  return history, history, ""
458
  '''