Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -377,16 +377,40 @@ agent=initialize_agent(tools,llm,agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT
|
|
| 377 |
# ββββββββββββββββββββββββββββββ
|
| 378 |
def chat(message, history):
|
| 379 |
try:
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
except Exception as e:
|
| 387 |
response = f"β οΈ μ€λ₯: {e}"
|
| 388 |
-
|
|
|
|
| 389 |
return history, history
|
|
|
|
| 390 |
with gr.Blocks(theme=gr.themes.Soft(), title="PIXAL Assistant (LangChain + GitHub LLM)") as demo:
|
| 391 |
gr.Markdown("""
|
| 392 |
## π€ PIXAL Assistant
|
|
|
|
| 377 |
# ββββββββββββββββββββββββββββββ
|
| 378 |
def chat(message, history):
|
| 379 |
try:
|
| 380 |
+
response = agent.run(message)
|
| 381 |
+
|
| 382 |
+
# JSON ννλ‘ μΆλ ₯λ κ°λ₯μ±μ΄ μλ κ²½μ° μ²λ¦¬
|
| 383 |
+
if isinstance(response, dict):
|
| 384 |
+
if "action_input" in response:
|
| 385 |
+
response = response["action_input"]
|
| 386 |
+
elif "output" in response:
|
| 387 |
+
response = response["output"]
|
| 388 |
+
elif "text" in response:
|
| 389 |
+
response = response["text"]
|
| 390 |
+
else:
|
| 391 |
+
response = str(response)
|
| 392 |
+
elif isinstance(response, str):
|
| 393 |
+
# "Final Answer"κ° ν¬ν¨λ λ¬Έμμ΄μ΄λ©΄ κ·Έ λΆλΆλ§ μΆμΆ
|
| 394 |
+
if '"action_input":' in response:
|
| 395 |
+
import re, json
|
| 396 |
+
match = re.search(r'["\']action_input["\']\s*:\s*["\'](.*?)["\']', response)
|
| 397 |
+
if match:
|
| 398 |
+
response = match.group(1)
|
| 399 |
+
elif "Final Answer" in response:
|
| 400 |
+
# {"action": "Final Answer", "action_input": "..."} νμμΌ λ
|
| 401 |
+
try:
|
| 402 |
+
data = json.loads(response)
|
| 403 |
+
if isinstance(data, dict) and "action_input" in data:
|
| 404 |
+
response = data["action_input"]
|
| 405 |
+
except Exception:
|
| 406 |
+
response = response.replace("Final Answer", "").strip()
|
| 407 |
+
|
| 408 |
except Exception as e:
|
| 409 |
response = f"β οΈ μ€λ₯: {e}"
|
| 410 |
+
|
| 411 |
+
history = history + [(message, response)]
|
| 412 |
return history, history
|
| 413 |
+
|
| 414 |
with gr.Blocks(theme=gr.themes.Soft(), title="PIXAL Assistant (LangChain + GitHub LLM)") as demo:
|
| 415 |
gr.Markdown("""
|
| 416 |
## π€ PIXAL Assistant
|