Spaces:
Sleeping
Sleeping
JerameeUC commited on
Commit ·
844c960
1
Parent(s): a66fd30
11th Commit minor changes added a few functions in various files
Browse files- README.md +0 -10
- agenticcore/web_agentic.py +22 -6
- anon_bot/handler.py +18 -0
- backend/__init__.py +0 -0
- backend/app/__init__.py +0 -0
- backend/app/main.py +8 -0
- nlu/router.py +8 -5
- scripts/check_compliance.py +11 -0
README.md
CHANGED
|
@@ -108,14 +108,4 @@ pytest -q
|
|
| 108 |
|
| 109 |
---
|
| 110 |
|
| 111 |
-
## Project Context
|
| 112 |
-
|
| 113 |
-
This is the **unified storefront-chatbot bundle**. Earlier skeletons were merged and duplicates removed.
|
| 114 |
-
Priority order:
|
| 115 |
-
1. `storefront_chatbot_final_bundle`
|
| 116 |
-
2. `storefront_chatbot_merged_with_agentic`
|
| 117 |
-
3. `storefront_chatbot_skeleton`
|
| 118 |
-
|
| 119 |
-
---
|
| 120 |
-
|
| 121 |
_Developed for MSAI 631 – Human-Computer Interaction Group Project._
|
|
|
|
| 108 |
|
| 109 |
---
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
_Developed for MSAI 631 – Human-Computer Interaction Group Project._
|
agenticcore/web_agentic.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# /agenticcore/web_agentic.py
|
| 2 |
-
from fastapi import FastAPI, Query
|
| 3 |
-
from fastapi.responses import HTMLResponse, FileResponse
|
| 4 |
from fastapi.staticfiles import StaticFiles # <-- ADD THIS
|
| 5 |
from agenticcore.chatbot.services import ChatBot
|
| 6 |
import pathlib
|
|
@@ -44,8 +44,24 @@ app.mount("/static", StaticFiles(directory=assets_path_str), name="static")
|
|
| 44 |
# Serve /favicon.ico (browsers request this path)
|
| 45 |
@app.get("/favicon.ico", include_in_schema=False)
|
| 46 |
async def favicon():
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
if png.exists():
|
| 49 |
-
return FileResponse(str(
|
| 50 |
-
# Graceful fallback
|
| 51 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# /agenticcore/web_agentic.py
|
| 2 |
+
from fastapi import FastAPI, Query, Request
|
| 3 |
+
from fastapi.responses import HTMLResponse, JSONResponse, FileResponse, Response
|
| 4 |
from fastapi.staticfiles import StaticFiles # <-- ADD THIS
|
| 5 |
from agenticcore.chatbot.services import ChatBot
|
| 6 |
import pathlib
|
|
|
|
| 44 |
# Serve /favicon.ico (browsers request this path)
|
| 45 |
@app.get("/favicon.ico", include_in_schema=False)
|
| 46 |
async def favicon():
|
| 47 |
+
ico = assets_path / "favicon.ico"
|
| 48 |
+
png = assets_path / "favicon.png"
|
| 49 |
+
if ico.exists():
|
| 50 |
+
return FileResponse(str(ico), media_type="image/x-icon")
|
| 51 |
if png.exists():
|
| 52 |
+
return FileResponse(str(png), media_type="image/png")
|
| 53 |
+
# Graceful fallback if no icon present
|
| 54 |
+
return Response(status_code=204)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
@app.get("/health")
|
| 58 |
+
def health():
|
| 59 |
+
return {"status": "ok"}
|
| 60 |
+
|
| 61 |
+
@app.post("/chatbot/message")
|
| 62 |
+
async def chatbot_message(request: Request):
|
| 63 |
+
payload = await request.json()
|
| 64 |
+
msg = str(payload.get("message", "")).strip()
|
| 65 |
+
if not msg:
|
| 66 |
+
msg = "help"
|
| 67 |
+
return ChatBot().reply(msg)
|
anon_bot/handler.py
CHANGED
|
@@ -40,3 +40,21 @@ def handle_text(message: str, history: History | None = None) -> str:
|
|
| 40 |
new_hist = handle_turn(message, history, user=None)
|
| 41 |
# last item is bot reply
|
| 42 |
return new_hist[-1][1] if new_hist else ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
new_hist = handle_turn(message, history, user=None)
|
| 41 |
# last item is bot reply
|
| 42 |
return new_hist[-1][1] if new_hist else ""
|
| 43 |
+
|
| 44 |
+
def handle_logged_in_turn(message, history=None, user=None):
|
| 45 |
+
history = history or []
|
| 46 |
+
try:
|
| 47 |
+
res = _bot.reply(message)
|
| 48 |
+
reply = res.get("reply") or "Noted."
|
| 49 |
+
meta = {
|
| 50 |
+
"intent": res.get("intent", "general"),
|
| 51 |
+
"input_len": len(message or ""),
|
| 52 |
+
"redacted": res.get("redacted", False),
|
| 53 |
+
"sentiment": res.get("sentiment", "neutral"),
|
| 54 |
+
"confidence": float(res.get("confidence", 1.0)),
|
| 55 |
+
}
|
| 56 |
+
except Exception as e:
|
| 57 |
+
reply = f"Sorry—error in ChatBot: {type(e).__name__}."
|
| 58 |
+
meta = {"intent": "error", "input_len": len(message or ""), "redacted": False,
|
| 59 |
+
"sentiment": "neutral", "confidence": 0.0}
|
| 60 |
+
return {"reply": reply, "meta": meta}
|
backend/__init__.py
ADDED
|
File without changes
|
backend/app/__init__.py
ADDED
|
File without changes
|
backend/app/main.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /backend/app/app.py
|
| 2 |
+
# Compatibility shim so tests can import backend.app.main:create_app
|
| 3 |
+
# and still reuse your real AIOHTTP app factory.
|
| 4 |
+
|
| 5 |
+
from app.app import create_app as _create_app
|
| 6 |
+
|
| 7 |
+
def create_app():
|
| 8 |
+
return _create_app()
|
nlu/router.py
CHANGED
|
@@ -56,16 +56,19 @@ _DEFAULT_ACTION = ("GENERAL", "builtin.respond", {"mode": "base"})
|
|
| 56 |
# -----------------------------
|
| 57 |
# Routing
|
| 58 |
# -----------------------------
|
| 59 |
-
|
| 60 |
-
def route(text: str, ctx: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
| 61 |
-
"""
|
| 62 |
-
Decide which action/handler should process the utterance.
|
| 63 |
-
"""
|
| 64 |
nlu = analyze(text or "")
|
| 65 |
intent = nlu.get("intent", "general")
|
| 66 |
confidence = float(nlu.get("confidence", 0.0))
|
| 67 |
action, handler, params = _ACTION_TABLE.get(intent, _DEFAULT_ACTION)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# pass-through entities as params for downstream handlers
|
| 70 |
entities = nlu.get("entities") or []
|
| 71 |
if entities:
|
|
|
|
| 56 |
# -----------------------------
|
| 57 |
# Routing
|
| 58 |
# -----------------------------
|
| 59 |
+
def route(text: str, ctx=None) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
nlu = analyze(text or "")
|
| 61 |
intent = nlu.get("intent", "general")
|
| 62 |
confidence = float(nlu.get("confidence", 0.0))
|
| 63 |
action, handler, params = _ACTION_TABLE.get(intent, _DEFAULT_ACTION)
|
| 64 |
|
| 65 |
+
# Override with simple sentiment keywords
|
| 66 |
+
t = (text or "").lower()
|
| 67 |
+
if any(word in t for word in ["love", "great", "awesome", "amazing"]):
|
| 68 |
+
intent = "sentiment_positive"
|
| 69 |
+
elif any(word in t for word in ["hate", "awful", "terrible", "bad"]):
|
| 70 |
+
intent = "sentiment_negative"
|
| 71 |
+
|
| 72 |
# pass-through entities as params for downstream handlers
|
| 73 |
entities = nlu.get("entities") or []
|
| 74 |
if entities:
|
scripts/check_compliance.py
CHANGED
|
@@ -40,6 +40,17 @@ IMPORT_RE = re.compile(r"^\s*(?:import|from)\s+([a-zA-Z0-9_.]+)")
|
|
| 40 |
# Scan
|
| 41 |
# -----------------------------
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def scan_file(path: Path) -> list[str]:
|
| 44 |
bad = []
|
| 45 |
try:
|
|
|
|
| 40 |
# Scan
|
| 41 |
# -----------------------------
|
| 42 |
|
| 43 |
+
def _supports_utf8():
|
| 44 |
+
enc = (sys.stdout.encoding or "").lower()
|
| 45 |
+
return "utf-8" in enc
|
| 46 |
+
|
| 47 |
+
FAIL_MARK = "FAIL:" if not _supports_utf8() else "❌"
|
| 48 |
+
PASS_MARK = "OK:" if not _supports_utf8() else "✅"
|
| 49 |
+
|
| 50 |
+
# then use:
|
| 51 |
+
print(f"{FAIL_MARK} Compliance check failed:")
|
| 52 |
+
print(f"{PASS_MARK} Compliance check passed (no disallowed deps).")
|
| 53 |
+
|
| 54 |
def scan_file(path: Path) -> list[str]:
|
| 55 |
bad = []
|
| 56 |
try:
|