JerameeUC commited on
Commit
a66fd30
·
1 Parent(s): ef31fc1

10th Commit, favicon added, FastAPI back-end partially up.

Browse files
README.md CHANGED
@@ -1,43 +1,121 @@
1
  <!-- README.md -->
2
- # Agentic-Chat-bot-
3
- Agentic Chat-bot with RAG, Memory, and Privacy Considerations.
4
 
5
- # Storefront Chatbot
 
 
 
 
 
 
6
 
7
- This repo follows a modular layout with a Gradio UI, NLU pipeline, anonymous and logged-in flows,
8
- guardrails, and optional Azure sentiment.
9
 
10
  ## Quickstart
 
 
 
 
 
 
 
 
 
 
11
  ```bash
12
  make dev
13
  make run
14
- # open http://localhost:7860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  ```
16
 
 
 
17
  ## Agentic Integration
18
- - Core bot: `agenticcore/chatbot/services.py`
19
- - Providers: `agenticcore/providers_unified.py`
20
- - CLI: `python -m agenticcore.cli agentic "hello"` (loads .env)
21
- - FastAPI demo: `uvicorn integrations.web.fastapi.web_agentic:app --reload`
22
-
23
- ## Added Samples & Tests
24
- - chat.html `app/assets/html/chat.html`
25
- - echo_bot.py → `integrations/botframework/bots/echo_bot.py`
26
- - ChatbotIntegration.ipynb → `notebooks/ChatbotIntegration.ipynb`
27
- - SimpleTraditionalChatbot.ipynb → `notebooks/SimpleTraditionalChatbot.ipynb`
28
- - smoke_test.py → `tests/smoke_test.py`
29
- - test_routes.py → `tests/test_routes.py`
30
- - quick_sanity.py → `tools/quick_sanity.py`
31
- - example.py `examples/example.py`
32
- - service.py → `samples/service.py`
33
- - DEV_DOC.md `docs/DEV_DOC.md`
34
-
35
- Run `pytest -q` for tests; open HTML in `app/assets/html/` to try local UIs.
36
-
37
-
38
- ---
39
- This is the **unified** storefront-chatbot bundle.
40
- Duplicates from earlier skeletons were removed; priority order was:
41
- 1) storefront_chatbot_final_bundle
42
- 2) storefront_chatbot_merged_with_agentic
43
- 3) storefront_chatbot_skeleton
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <!-- README.md -->
2
+ # Agentic Chatbot
 
3
 
4
+ Agentic Chatbot with Retrieval-Augmented Generation (RAG), session memory, and privacy guardrails.
5
+ The project follows a **modular architecture** with:
6
+ - Gradio UI for interactive demos
7
+ - AIOHTTP backend with lightweight routes
8
+ - Anonymous and logged-in flows
9
+ - Guardrails for safety and PII redaction
10
+ - Optional cloud providers (Azure, Hugging Face, OpenAI, Cohere, DeepAI)
11
 
12
+ ---
 
13
 
14
  ## Quickstart
15
+
16
+ Clone the repo, set up a venv, and install dependencies:
17
+
18
+ ```bash
19
+ python -m venv .venv && source .venv/bin/activate
20
+ pip install -r requirements.txt
21
+ ```
22
+
23
+ Run in dev mode:
24
+
25
  ```bash
26
  make dev
27
  make run
28
+ # open http://localhost:7860 (Gradio UI)
29
+ ```
30
+
31
+ Or run the backend directly:
32
+
33
+ ```bash
34
+ python app/app.py
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Health Checks
40
+
41
+ The AIOHTTP backend exposes simple endpoints:
42
+
43
+ ```bash
44
+ curl http://127.0.0.1:3978/healthz
45
+ # -> {"status":"ok"}
46
+
47
+ curl -X POST http://127.0.0.1:3978/plain-chat -H "Content-Type: application/json" -d '{"text":"reverse hello"}'
48
+ # -> {"reply":"olleh"}
49
  ```
50
 
51
+ ---
52
+
53
  ## Agentic Integration
54
+
55
+ - **Core bot:** `agenticcore/chatbot/services.py`
56
+ - **Providers:** `agenticcore/providers_unified.py`
57
+ - **CLI:** `python -m agenticcore.cli agentic "hello"` (loads `.env`)
58
+ - **FastAPI demo:**
59
+ ```bash
60
+ uvicorn integrations.web.fastapi.web_agentic:app --reload --port 8000
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Environment Variables
66
+
67
+ Provider integrations are selected automatically, or you can pin one with `AI_PROVIDER`. Supported keys:
68
+
69
+ - Hugging Face: `HF_API_KEY`, `HF_MODEL_SENTIMENT`
70
+ - Azure: `MICROSOFT_AI_SERVICE_ENDPOINT`, `MICROSOFT_AI_API_KEY`
71
+ - OpenAI: `OPENAI_API_KEY`
72
+ - Cohere: `COHERE_API_KEY`
73
+ - DeepAI: `DEEPAI_API_KEY`
74
+
75
+ If no keys are set, the system falls back to **offline sentiment mode**.
76
+
77
+ ---
78
+
79
+ ## Samples & Tests
80
+
81
+ - **UI samples:**
82
+ - `app/assets/html/chat.html` – open in browser for local test
83
+ - **Bots:**
84
+ - `integrations/botframework/bots/echo_bot.py`
85
+ - **Notebooks:**
86
+ - `notebooks/ChatbotIntegration.ipynb`
87
+ - `notebooks/SimpleTraditionalChatbot.ipynb`
88
+ - **Tests:**
89
+ - `tests/smoke_test.py`
90
+ - `tests/test_routes.py`
91
+ - `tests/test_anon_bot.py`
92
+ - **Misc:**
93
+ - `tools/quick_sanity.py`
94
+ - `examples/example.py`
95
+ - `samples/service.py`
96
+
97
+ Run all tests:
98
+
99
+ ```bash
100
+ pytest -q
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Documentation
106
+
107
+ - [Developer & Build/Test Guide](docs/Developer_Guide_Build_Test.md)
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._
agenticcore/web_agentic.py CHANGED
@@ -1,22 +1,51 @@
1
  # /agenticcore/web_agentic.py
2
  from fastapi import FastAPI, Query
3
- from fastapi.responses import HTMLResponse
 
4
  from agenticcore.chatbot.services import ChatBot
 
 
5
 
6
  app = FastAPI(title="AgenticCore Web UI")
7
 
8
- # 1. Simple HTML form at /
9
  @app.get("/", response_class=HTMLResponse)
10
  def index():
11
  return """
12
- <form action="/agentic" method="get">
 
 
 
 
13
  <input type="text" name="msg" placeholder="Type a message" style="width:300px">
14
  <input type="submit" value="Send">
15
  </form>
16
  """
17
 
18
- # 2. Agentic endpoint
19
  @app.get("/agentic")
20
  def run_agentic(msg: str = Query(..., description="Message to send to ChatBot")):
21
  bot = ChatBot()
22
  return bot.reply(msg)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
7
+ import os
8
 
9
  app = FastAPI(title="AgenticCore Web UI")
10
 
11
+ # 1) Simple HTML form at /
12
  @app.get("/", response_class=HTMLResponse)
13
  def index():
14
  return """
15
+ <head>
16
+ <link rel="icon" type="image/png" href="/static/favicon.png">
17
+ <title>AgenticCore</title>
18
+ </head>
19
+ <form action="/agentic" method="get" style="padding:16px;">
20
  <input type="text" name="msg" placeholder="Type a message" style="width:300px">
21
  <input type="submit" value="Send">
22
  </form>
23
  """
24
 
25
+ # 2) Agentic endpoint
26
  @app.get("/agentic")
27
  def run_agentic(msg: str = Query(..., description="Message to send to ChatBot")):
28
  bot = ChatBot()
29
  return bot.reply(msg)
30
+
31
+ # --- Static + favicon setup ---
32
+
33
+ # TIP: we're inside <repo>/agenticcore/web_agentic.py
34
+ # repo root = parents[1]
35
+ repo_root = pathlib.Path(__file__).resolve().parents[1]
36
+
37
+ # Put static assets under app/assets/html
38
+ assets_path = repo_root / "app" / "assets" / "html"
39
+ assets_path_str = str(assets_path)
40
+
41
+ # Mount /static so /static/favicon.png works
42
+ app.mount("/static", StaticFiles(directory=assets_path_str), name="static")
43
+
44
+ # Serve /favicon.ico (browsers request this path)
45
+ @app.get("/favicon.ico", include_in_schema=False)
46
+ async def favicon():
47
+ png = assets_path / "favicon.ico"
48
+ if png.exists():
49
+ return FileResponse(str(ico), media_type="image/ico")
50
+ # Graceful fallback: return an empty 204 if icon missing
51
+ return HTMLResponse(status_code=204, content="")
app/assets/html/favicon.ico ADDED

Git LFS Details

  • SHA256: 806378ed3b1bacfd373590f12b9287cb28381cf545c98aa9b8de9fcf90f6a1d0
  • Pointer size: 131 Bytes
  • Size of remote file: 270 kB
app/assets/html/favicon.png ADDED

Git LFS Details

  • SHA256: 768c5223e8f895ba72db74b19908beab6816768ea53c2a0cec6ff07a71660cec
  • Pointer size: 132 Bytes
  • Size of remote file: 1.24 MB
docs/Agentic_Chatbot_Dev_Build_Test.docx ADDED
Binary file (39.4 kB). View file
 
docs/DEV_DOC.md CHANGED
@@ -1,5 +1,4 @@
1
- <!-- /docs/slides/DEV_DOC.md -->
2
-
3
  ## 3. Functional Requirements
4
 
5
  This section describes the functional requirements for connecting a chatbot to an AI-as-a-Service (AIaaS) platform. It defines the expected system behavior, outlines constraints, and sets measurable acceptance criteria. Requirements are grouped into system context, core functions, supporting functions, and non-functional aspects.
 
1
+ <!-- /docs/DEV_DOC.md -->
 
2
  ## 3. Functional Requirements
3
 
4
  This section describes the functional requirements for connecting a chatbot to an AI-as-a-Service (AIaaS) platform. It defines the expected system behavior, outlines constraints, and sets measurable acceptance criteria. Requirements are grouped into system context, core functions, supporting functions, and non-functional aspects.
docs/Developer_Guide_Build_Test.md ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- /docs/Developer_Guide_Build_Test.md -->
2
+ # Developer & Build/Test Guide
3
+
4
+ ## Purpose & Scope
5
+ This document combines the Developer Guide and Build & Test Guide. It explains the repository structure, endpoints, CLI, providers, and step‑by‑step build/test instructions.
6
+
7
+ ---
8
+
9
+ ## Architecture Overview
10
+ - **UI:** Gradio Blocks UI and plain HTML testers.
11
+ - **Router/Logic:** Routes text to anon/logged-in/agentic paths.
12
+ - **NLU:** Intent router and prompt manager.
13
+ - **Memory:** Session handling and optional RAG retriever.
14
+ - **Guardrails:** PII redaction and safety filters.
15
+ - **Providers:** Cloud/offline AI providers.
16
+
17
+ ---
18
+
19
+ ## Repository Layout
20
+ - `app/` – AIOHTTP server + UI components.
21
+ - `anon_bot/` – Anonymous rule-based bot.
22
+ - `logged_in_bot/` – Provider-backed logic.
23
+ - `nlu/` – Pipeline, router, prompts.
24
+ - `memory/` – Session store + retriever.
25
+ - `guardrails/` – PII/safety enforcement.
26
+ - `agenticcore/` – Unified provider integrations.
27
+
28
+ ---
29
+
30
+ ## Services & Routes
31
+ - `GET /healthz` – health check.
32
+ - `POST /plain-chat` – anon chat endpoint.
33
+ - `POST /api/messages` – Bot Framework activities.
34
+ - `GET /agentic` (FastAPI) – provider-backed demo.
35
+
36
+ ### Health Check Examples
37
+ ```bash
38
+ curl http://127.0.0.1:3978/healthz
39
+ curl -X POST http://127.0.0.1:3978/plain-chat -H "Content-Type: application/json" -d '{"text":"reverse hello"}'
40
+ ```
41
+
42
+ ---
43
+
44
+ ## CLI
45
+ - `python -m agenticcore.cli agentic "hello"`
46
+ - `python -m agenticcore.cli status`
47
+
48
+ ---
49
+
50
+ ## Providers
51
+ Configured via environment variables (HF, Azure, OpenAI, Cohere, DeepAI). Offline fallback included.
52
+
53
+ ### Environment Variables
54
+ - Hugging Face: `HF_API_KEY`, `HF_MODEL_SENTIMENT`
55
+ - Azure: `MICROSOFT_AI_SERVICE_ENDPOINT`, `MICROSOFT_AI_API_KEY`
56
+ - OpenAI: `OPENAI_API_KEY`
57
+ - Cohere: `COHERE_API_KEY`
58
+ - DeepAI: `DEEPAI_API_KEY`
59
+
60
+ If no keys are set, the system falls back to **offline sentiment mode**.
61
+
62
+ ---
63
+
64
+ ## Build Instructions
65
+
66
+ ### Setup
67
+ ```bash
68
+ python -m venv .venv && source .venv/bin/activate
69
+ pip install -r requirements.txt
70
+ ```
71
+
72
+ ### Run AIOHTTP Backend
73
+ ```bash
74
+ python app/app.py
75
+ ```
76
+
77
+ ### Run Gradio UI
78
+ ```bash
79
+ export APP_MODE=gradio
80
+ python app/app.py
81
+ ```
82
+
83
+ ### Run FastAPI Demo
84
+ ```bash
85
+ uvicorn agenticcore.web_agentic:app --reload --port 8000
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Testing
91
+
92
+ ### Automated Tests
93
+ ```bash
94
+ pytest -q
95
+ pytest -q tests/test_anon_bot.py
96
+ pytest -q tests/test_routes.py
97
+ ```
98
+
99
+ ### Manual Tests
100
+ ```bash
101
+ curl http://127.0.0.1:3978/healthz
102
+ curl -X POST http://127.0.0.1:3978/plain-chat -H "Content-Type: application/json" -d '{"text":"reverse hello"}'
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Troubleshooting
108
+ - Missing provider keys → falls back to offline.
109
+ - HTML tester fails → confirm backend running.
110
+ - If provider calls fail → run CLI with `status` to confirm API keys.
111
+
112
+ ---
113
+
114
+ ## Security Defaults
115
+ - No keys in repo.
116
+ - Anon mode is offline.
117
+ - Logged-in mode applies guardrails.
118
+
119
+ ---
120
+
121
+ _Audience: Contributors & Developers_
docs/architecture.md CHANGED
@@ -1,4 +1,4 @@
1
- <!-- /docs/slides/architecture.md -->
2
  # Architecture
3
 
4
  This system follows a **modular chatbot architecture** built around a clear flow of data from the user interface to external services and back. The design emphasizes separation of concerns, allowing each module to handle a specific responsibility while keeping the overall system simple to test and extend.
 
1
+ <!-- /docs/architecture.md -->
2
  # Architecture
3
 
4
  This system follows a **modular chatbot architecture** built around a clear flow of data from the user interface to external services and back. The design emphasizes separation of concerns, allowing each module to handle a specific responsibility while keeping the overall system simple to test and extend.
docs/design.md CHANGED
@@ -1,4 +1,4 @@
1
- <!-- /docs/slides/design.md -->
2
  # Design Notes
3
 
4
  These notes document the reasoning behind major design choices, focusing on **API usage**, **security considerations**, and **tradeoffs** made during development.
 
1
+ <!-- /docs/design.md -->
2
  # Design Notes
3
 
4
  These notes document the reasoning behind major design choices, focusing on **API usage**, **security considerations**, and **tradeoffs** made during development.
docs/favicon.png~ ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54d47bcf0b688fd281e89f6931653e2cd5116c6930d2f3c4e911fc994a7b00ad
3
+ size 1495668
docs/favicon_bundle.zip ADDED
Binary file (61.3 kB). View file
 
docs/favicon_bundle/favicon.ico ADDED

Git LFS Details

  • SHA256: 323bd1d069cb9d6ff92dbca246dbccdb5cb9f0a21ee2c784a2fff47a06c8e6a4
  • Pointer size: 130 Bytes
  • Size of remote file: 40.1 kB
docs/favicon_bundle/favicon.png ADDED

Git LFS Details

  • SHA256: becb7caa4fa59aa75d22c6fc6a7e26950a909dbebd06e9d4304d342b04e1fc2a
  • Pointer size: 130 Bytes
  • Size of remote file: 21 kB
scripts/run_backend.bat ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ @echo off
2
+ set APP_MODE=aiohttp
3
+ set PORT=%1
4
+ if "%PORT%"=="" set PORT=3978
5
+ set HOST=%2
6
+ if "%HOST%"=="" set HOST=127.0.0.1
7
+ python app\app.py
scripts/run_backend.ps1 ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ param(
2
+ [string]$Port = "3978",
3
+ [string]$Host = "127.0.0.1"
4
+ )
5
+ $env:APP_MODE = "aiohttp"
6
+ $env:PORT = $Port
7
+ $env:HOST = $Host
8
+ python app\app.py
scripts/run_fastapi.bat ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ @echo off
2
+ set PORT=%1
3
+ if "%PORT%"=="" set PORT=8000
4
+ set HOST=%2
5
+ if "%HOST%"=="" set HOST=127.0.0.1
6
+ uvicorn agenticcore.web_agentic:app --reload --host %HOST% --port %PORT%
scripts/run_fastapi.ps1 ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ param(
2
+ [string]$Port = "8000",
3
+ [string]$Host = "127.0.0.1"
4
+ )
5
+ uvicorn agenticcore.web_agentic:app --reload --host $Host --port $Port
scripts/run_gradio.bat ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ @echo off
2
+ set APP_MODE=gradio
3
+ set PORT=%1
4
+ if "%PORT%"=="" set PORT=7860
5
+ set HOST=%2
6
+ if "%HOST%"=="" set HOST=127.0.0.1
7
+ python app\app.py
scripts/run_gradio.ps1 ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ param(
2
+ [string]$Port = "7860",
3
+ [string]$Host = "127.0.0.1"
4
+ )
5
+ $env:APP_MODE = "gradio"
6
+ $env:PORT = $Port
7
+ $env:HOST = $Host
8
+ python app\app.py