You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module does not generate the final chatbot answer and does not make investment conclusions. Downstream modules should consume the two JSON outputs for document learning, sentiment analysis, trend analysis, numerical feature computation, and response generation.
8
+
The core Query Intelligence pipeline does not make investment conclusions. The repository also ships a local browser chatbot wrapper at `GET /` and `POST /chat`; that wrapper consumes the same NLU/Retrieval artifacts, calls DeepSeek for response polishing when configured, and falls back to a structured evidence summary when the model is unavailable.
9
9
10
10
## Scope
11
11
@@ -24,7 +24,7 @@ HK/US stocks and overseas products are not guaranteed by default. To support the
-`sentiment/` and `scripts/llm_response.py`are downstream consumers. They may use `torch`, `transformers`, FinBERT, or local generation models, but they must not re-infer the user's intent, target entities, or retrieval source plan.
27
+
-`sentiment/`, `scripts/llm_response.py`, and the `/chat` browser wrapper are downstream consumers. They may use `torch`, `transformers`, FinBERT, or remote/local generation models, but they must not re-infer the user's intent, target entities, or retrieval source plan.
|`POST /query/intelligence/artifacts`| End-to-end run and write JSON artifacts |`ArtifactRequest`|`ArtifactResponse`|
68
74
75
+
## Local Frontend Chatbot
76
+
77
+
The local frontend is a single-page chat app rendered by `query_intelligence/chatbot.py` and served from `query_intelligence/api/app.py`. It runs the same Query Intelligence pipeline, then sends compact evidence to DeepSeek only for final response wording.
Use `deepseek-v4-pro` by setting `DEEPSEEK_MODEL=deepseek-v4-pro` or editing `config/app_config.json`. Use `DEEPSEEK_REASONING_EFFORT=max` for heavier reasoning. The API key should be provided through `DEEPSEEK_API_KEY` or a local `.env`; do not commit it.
94
+
95
+
The UI response JSON includes `answer`, `key_points`, `risk_disclaimer`, `evidence_used`, `evidence_sources`, `llm`, `nlu_result`, and `retrieval_result`. For the full frontend reference and screenshots from real local runs, see [docs/frontend-chatbot.md](docs/frontend-chatbot.md).
96
+
69
97
### Frontend Request JSON
70
98
71
99
Recommended endpoint: `POST /query/intelligence`. Use `POST /query/intelligence/artifacts` if the backend should also write files.
@@ -415,8 +443,10 @@ flowchart TD
415
443
E --> F["retrieval_result.json"]
416
444
F --> G["Document Sentiment Analysis: sentiment/"]
417
445
F --> H["LLM Response Utility: scripts/llm_response.py"]
446
+
F --> J["Browser Chatbot: POST /chat"]
418
447
G --> I["Downstream Analysis and Chatbot Answering"]
- The retrieval pipeline intentionally skipped an unsafe or irrelevant source.
778
809
779
-
### The API returns JSON but no natural-language answer
810
+
### `/query/intelligence` returns JSON but no natural-language answer
780
811
781
-
This is expected. Query Intelligence only produces understanding and evidence artifacts. Final chatbot wording, investment-safe answer generation, sentiment analysis, trend analysis, and numerical calculation belong to downstream modules. For the current experimental answer-generation handoff, see `scripts/llm_response.py`.
812
+
This is expected. Query Intelligence only produces understanding and evidence artifacts. Final chatbot wording, investment-safe answer generation, sentiment analysis, trend analysis, and numerical calculation belong to downstream modules. Use `POST /chat` or the local browser app for a DeepSeek-polished chatbot response. Use `scripts/llm_response.py` only for the legacy local-transformers frontend handoff flow.
782
813
783
814
## Frontend LLM Response Handoff
784
815
785
-
`scripts/llm_response.py` is a downstream utility for producing frontend-ready JSON from compact evidence. It can either consume an existing Query Intelligence record or run Query Intelligence first from a raw query.
816
+
`scripts/llm_response.py` is a downstream utility for producing frontend-ready JSON from compact evidence. It can either consume an existing Query Intelligence record or run Query Intelligence first from a raw query. It is separate from the local browser chatbot: `/chat` uses DeepSeek API settings from `config/app_config.json`, while this script remains the local HuggingFace/transformers handoff path in this checkout.
The local frontend chatbot is the browser-facing demo for FinSight. It is intentionally thin: the UI sends a user question to `POST /chat`, the backend runs Query Intelligence, and DeepSeek only rewrites the compact evidence into a user-facing answer.
6
+
7
+
This wrapper must not replace the NLU/Retrieval backbone. Entity resolution, intent, source planning, evidence retrieval, ranking, warnings, and `analysis_summary` still come from Query Intelligence.
If DeepSeek is missing, unreachable, or returns invalid JSON, `/chat` returns a structured-summary fallback with `llm.status="fallback"`. It still includes `nlu_result`, `retrieval_result`, and evidence sources.
46
+
47
+
## DeepSeek Configuration
48
+
49
+
Defaults live in `config/app_config.json` and can be overridden by environment variables.
Use `DEEPSEEK_MODEL=deepseek-v4-pro` when you want the higher-capability model. Use `DEEPSEEK_REASONING_EFFORT=max` for heavier thinking. The backend sends `response_format={"type":"json_object"}` and prompts DeepSeek for one strict JSON object.
63
+
64
+
## API Contract
65
+
66
+
`POST /chat` accepts the same frontend context fields as the core pipeline:
67
+
68
+
```json
69
+
{
70
+
"query": "你觉得中国平安怎么样?",
71
+
"user_profile": {},
72
+
"dialog_context": [],
73
+
"top_k": 20,
74
+
"debug": false
75
+
}
76
+
```
77
+
78
+
Response fields:
79
+
80
+
| Field | Meaning |
81
+
|---|---|
82
+
|`answer`| Final user-facing wording generated by DeepSeek or fallback summary. |
83
+
|`key_points`| Short bullet points grounded in retrieved evidence. |
84
+
|`risk_disclaimer`| Investment-risk disclaimer. |
85
+
|`evidence_used`| Evidence IDs selected by the answer layer. |
86
+
|`evidence_sources`| UI-ready source cards with title, type, source name, and optional URL. |
87
+
|`llm`|`{provider, model, status, error}` for model observability. |
88
+
|`nlu_result`| Full Query Intelligence NLU artifact. |
89
+
|`retrieval_result`| Full retrieval artifact, including warnings and `analysis_summary`. |
90
+
91
+
## Verified Local Run
92
+
93
+
The following screenshots came from real local browser runs on May 3, 2026. The service was started with `deepseek-v4-flash`, thinking enabled, `reasoning_effort=high`, and a local environment variable for the API key. The key is not written to the repository.
| Dependency issue fixed | Added `socksio` so `httpx` can use local SOCKS proxy variables |
120
+
121
+
## Troubleshooting
122
+
123
+
If DeepSeek falls back with a SOCKS proxy error, install dependencies again:
124
+
125
+
```bash
126
+
pip install -r requirements.txt
127
+
```
128
+
129
+
If live providers fail, inspect `retrieval_result.warnings`. The pipeline is expected to degrade gracefully and still answer from fallback providers or shipped runtime assets when possible.
0 commit comments