union-app-chat-stream 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +16 -0
- package/PROJECT_OVERVIEW.md +187 -0
- package/app/.env +63 -0
- package/app/.env.dev +63 -0
- package/app/.env.prod.bj11 +63 -0
- package/app/.env.prod.sh20 +63 -0
- package/app/.env.prod.sz31 +63 -0
- package/app/.env.test.bj12 +63 -0
- package/app/__init__.py +42 -0
- package/app/__pycache__/__init__.cpython-312.pyc +0 -0
- package/app/__pycache__/authenticated_user.cpython-312.pyc +0 -0
- package/app/__pycache__/extensions.cpython-312.pyc +0 -0
- package/app/__pycache__/wsgi.cpython-312.pyc +0 -0
- package/app/authenticated_user.py +77 -0
- package/app/config/__pycache__/config_loader.cpython-312.pyc +0 -0
- package/app/config/__pycache__/env_config.cpython-312.pyc +0 -0
- package/app/config/__pycache__/logger_config.cpython-312.pyc +0 -0
- package/app/config/env_config.py +96 -0
- package/app/config/logger_config.py +46 -0
- package/app/manager/__init__.py +4 -0
- package/app/manager/__pycache__/__init__.cpython-312.pyc +0 -0
- package/app/manager/__pycache__/chatstream_manager.cpython-312.pyc +0 -0
- package/app/manager/__pycache__/prompts.cpython-312.pyc +0 -0
- package/app/manager/__pycache__/runtime_manager.cpython-312.pyc +0 -0
- package/app/manager/__pycache__/toolcall_manager.cpython-312.pyc +0 -0
- package/app/manager/chatstream_manager.py +90 -0
- package/app/manager/prompts.py +62 -0
- package/app/manager/runtime_manager.py +552 -0
- package/app/models/__pycache__/schemas.cpython-312.pyc +0 -0
- package/app/models/schemas.py +30 -0
- package/app/service/__init__.py +4 -0
- package/app/service/__pycache__/__init__.cpython-312.pyc +0 -0
- package/app/service/__pycache__/chat_service.cpython-312.pyc +0 -0
- package/app/service/__pycache__/llm_service.cpython-312.pyc +0 -0
- package/app/service/__pycache__/rag_service.cpython-312.pyc +0 -0
- package/app/service/__pycache__/tool_call_service.cpython-312.pyc +0 -0
- package/app/service/__pycache__/union_service.cpython-312.pyc +0 -0
- package/app/service/chat_service.py +228 -0
- package/app/service/llm_service.py +214 -0
- package/app/service/rag_service.py +866 -0
- package/app/service/union_service.py +201 -0
- package/app/utils/__init__.py +5 -0
- package/app/utils/__pycache__/__init__.cpython-312.pyc +0 -0
- package/app/utils/__pycache__/common_utils.cpython-312.pyc +0 -0
- package/app/utils/__pycache__/debug_context.cpython-312.pyc +0 -0
- package/app/utils/__pycache__/function_utils.cpython-312.pyc +0 -0
- package/app/utils/__pycache__/jwt_utils.cpython-312.pyc +0 -0
- package/app/utils/common_utils.py +169 -0
- package/app/utils/debug_context.py +16 -0
- package/app/utils/function_utils.py +274 -0
- package/app/utils/jwt_utils.py +39 -0
- package/app/views/__init__.py +6 -0
- package/app/views/__pycache__/__init__.cpython-312.pyc +0 -0
- package/app/views/__pycache__/view_chatstream.cpython-312.pyc +0 -0
- package/app/views/__pycache__/view_healthcheck.cpython-312.pyc +0 -0
- package/app/views/__pycache__/view_runtime.cpython-312.pyc +0 -0
- package/app/views/view_chatstream.py +53 -0
- package/app/views/view_healthcheck.py +14 -0
- package/app/views/view_runtime.py +72 -0
- package/app/wsgi.py +37 -0
- package/ci.yml +14 -0
- package/deploy/autoconf/templates/env.j2 +25 -0
- package/deploy/autoconf.yml +15 -0
- package/deploy/scripts/healthcheck.sh +0 -0
- package/deploy/scripts/requirements.txt +53 -0
- package/deploy/scripts/start.sh +75 -0
- package/deploy/scripts/stop.sh +31 -0
- package/knowledge/.gitkeep +0 -0
- package/knowledge/000001-biz-offline-85b99bd43b-v1.md +88 -0
- package/knowledge/000002-biz-offline-717e8d823e-v1.md +90 -0
- package/knowledge/000003-biz-offline-c963227cc8-v1.md +84 -0
- package/knowledge/000004-biz-offline-2a5868e7da-v1.md +92 -0
- package/knowledge/000005-biz-offline-f9d9cf1a88-v1.md +79 -0
- package/knowledge/000006-biz-offline-c4fa2df3bd-v1.md +77 -0
- package/knowledge/000007-biz-offline-78304b70ca-v1.md +76 -0
- package/knowledge/000008-biz-offline-987ae67b35-v1.md +75 -0
- package/knowledge/000009-biz-offline-4d656bcea3-v1.md +85 -0
- package/knowledge/000010-sop-offline-a9e1050719-v1.md +100 -0
- package/knowledge/000011-biz-offline-5de0624891-v1.md +86 -0
- package/knowledge/000012-biz-offline-7dfacccba3-v1.md +82 -0
- package/knowledge/000013-biz-offline-5e1d29d2ed-v1.md +81 -0
- package/knowledge/000014-biz-offline-1d0ed8b841-v1.md +68 -0
- package/knowledge/000015-biz-offline-8a1376ee3e-v1.md +78 -0
- package/knowledge/000016-biz-offline-c8bfc2aa08-v1.md +99 -0
- package/knowledge/000017-biz-offline-9dffb28032-v1.md +88 -0
- package/knowledge/000018-biz-offline-f935bc9a6a-v1.md +80 -0
- package/knowledge/000019-biz-offline-858b3ecd89-v1.md +86 -0
- package/knowledge/000020-biz-offline-65cb5c4f40-v1.md +113 -0
- package/knowledge/000021-biz-offline-1bf211639c-v1.md +148 -0
- package/knowledge/000022-biz-offline-8c5a637879-v1.md +140 -0
- package/knowledge/000023-biz-offline-fe872b8712-v1.md +188 -0
- package/knowledge/000024-biz-offline-a85010c500-v1.md +133 -0
- package/knowledge/000025-biz-offline-8af58a3638-v1.md +136 -0
- package/knowledge/000026-biz-offline-6754102e93-v1.md +142 -0
- package/knowledge/000027-biz-offline-ea2e5ca5f9-v1.md +150 -0
- package/knowledge/000028-scenario-offline-dab45cebb4-v1.md +136 -0
- package/knowledge/000029-scenario-offline-5b8ae5ea9f-v1.md +143 -0
- package/knowledge/000030-scenario-offline-9a82d42f3f-v1.md +136 -0
- package/knowledge/000031-scenario-offline-cc2edc0197-v1.md +122 -0
- package/knowledge/000032-scenario-offline-e5f6e5cbfa-v1.md +122 -0
- package/knowledge/000033-scenario-offline-e1955849aa-v1.md +135 -0
- package/knowledge/000034-scenario-offline-3a13d49a3a-v1.md +138 -0
- package/knowledge/000035-scenario-offline-fd5560211f-v1.md +147 -0
- package/knowledge/000036-scenario-offline-function-call-mock-v1.md +134 -0
- package/package.json +18 -0
- package/requirements.txt +53 -0
- package/tools/prompts.yaml +10 -0
- package/tools/tool_definitions.yaml +303 -0
package/.gitignore
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.idea/
|
|
2
|
+
.venv/
|
|
3
|
+
.chroma/
|
|
4
|
+
__pycache__/
|
|
5
|
+
deploy/scripts/union_py/
|
|
6
|
+
data/
|
|
7
|
+
# Ignore virtual environment files
|
|
8
|
+
*.pyc
|
|
9
|
+
.DS_Store
|
|
10
|
+
.env
|
|
11
|
+
.env.*
|
|
12
|
+
|
|
13
|
+
# Knowledge base (RAG documents, managed separately)
|
|
14
|
+
# Ignore everything in knowledge/ but keep the directory via .gitkeep
|
|
15
|
+
knowledge/*
|
|
16
|
+
!knowledge/.gitkeep
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# Project Overview
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
This repository contains a Python 3.12 Flask application for Union operations
|
|
6
|
+
chat and RAG-assisted troubleshooting. It exposes streaming chat APIs, runtime
|
|
7
|
+
management APIs, and a health check endpoint. The app is intended to run behind
|
|
8
|
+
Hypercorn in Linux x86_64 deployment environments.
|
|
9
|
+
|
|
10
|
+
## Stack
|
|
11
|
+
|
|
12
|
+
- Language: Python 3.12
|
|
13
|
+
- Web framework: Flask running through Hypercorn ASGI
|
|
14
|
+
- LLM SDK: zai-sdk
|
|
15
|
+
- Vector database: ChromaDB
|
|
16
|
+
- Validation: Pydantic v2
|
|
17
|
+
- Logging: Loguru
|
|
18
|
+
- Runtime target: Linux x86_64
|
|
19
|
+
|
|
20
|
+
## Repository Layout
|
|
21
|
+
|
|
22
|
+
```text
|
|
23
|
+
union-py-app/
|
|
24
|
+
├── app/ # Flask application package
|
|
25
|
+
│ ├── __init__.py # create_app() factory and blueprint setup
|
|
26
|
+
│ ├── wsgi.py # Application entrypoint
|
|
27
|
+
│ ├── authenticated_user.py # Session authentication middleware
|
|
28
|
+
│ ├── config/ # Configuration and logging
|
|
29
|
+
│ ├── manager/ # Business orchestration layer
|
|
30
|
+
│ ├── models/ # Pydantic schemas
|
|
31
|
+
│ ├── service/ # Core services: chat, RAG, LLM, union logic
|
|
32
|
+
│ ├── utils/ # Shared utility functions
|
|
33
|
+
│ └── views/ # Flask blueprints and HTTP routes
|
|
34
|
+
├── knowledge/ # RAG knowledge source files
|
|
35
|
+
├── tools/ # Tool definitions for model tool calling
|
|
36
|
+
├── scripts/ # Environment-specific launcher scripts
|
|
37
|
+
├── deploy/ # Deployment config, templates, and scripts
|
|
38
|
+
├── requirements.txt # Python dependencies
|
|
39
|
+
├── ci.yml # CI configuration
|
|
40
|
+
└── .gitignore
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Project-specific context belongs in this file. Do not add a repository-root
|
|
44
|
+
`AGENTS.md`; global working rules are provided outside the repo.
|
|
45
|
+
|
|
46
|
+
## Important Modules
|
|
47
|
+
|
|
48
|
+
- `app/__init__.py`: Builds the Flask app, loads configuration, initializes
|
|
49
|
+
managers in `app.extensions`, and registers blueprints.
|
|
50
|
+
- `app/wsgi.py`: Imports `create_app()` and exposes `app` for Hypercorn.
|
|
51
|
+
- `app/authenticated_user.py`: Validates login identity before requests.
|
|
52
|
+
- `app/config/env_config.py`: Defines Flask configuration values.
|
|
53
|
+
- `app/config/logger_config.py`: Initializes application logging.
|
|
54
|
+
- `app/manager/chatstream_manager.py`: Orchestrates chatstream routes, including
|
|
55
|
+
chat streaming and RAG status/rebuild operations.
|
|
56
|
+
- `app/manager/runtime_manager.py`: Handles runtime management behavior.
|
|
57
|
+
- `app/manager/prompts.py`: Stores prompt templates.
|
|
58
|
+
- `app/models/schemas.py`: Defines request and response schemas.
|
|
59
|
+
- `app/service/chat_service.py`: Implements streaming chat and tool-call loops.
|
|
60
|
+
- `app/service/rag_service.py`: Manages RAG indexing and retrieval.
|
|
61
|
+
- `app/service/llm_service.py`: Wraps LLM provider behavior.
|
|
62
|
+
- `app/service/union_service.py`: Contains Union operations business services.
|
|
63
|
+
- `app/utils/function_utils.py`: Loads YAML tool definitions and dispatches
|
|
64
|
+
tool calls.
|
|
65
|
+
- `app/views/view_chatstream.py`: Chatstream and RAG HTTP endpoints.
|
|
66
|
+
- `app/views/view_runtime.py`: Runtime HTTP endpoints.
|
|
67
|
+
- `app/views/view_healthcheck.py`: Health check HTTP endpoint.
|
|
68
|
+
|
|
69
|
+
## API Surface
|
|
70
|
+
|
|
71
|
+
| Method | Path | Blueprint | Purpose |
|
|
72
|
+
|---|---|---|---|
|
|
73
|
+
| POST | `/chatstream/v1/chat/stream` | chatstream | SSE streaming chat with RAG and tool calls |
|
|
74
|
+
| GET | `/chatstream/v1/rag/check` | chatstream | RAG knowledge and vector database status |
|
|
75
|
+
| POST | `/chatstream/v1/rag/force-rebuild` | chatstream | Force rebuild of the RAG knowledge base |
|
|
76
|
+
| GET | `/healthcheck.html` | healthcheck | Service health check |
|
|
77
|
+
|
|
78
|
+
## Environment Loading
|
|
79
|
+
|
|
80
|
+
Environment-specific launch scripts under `scripts/` contain the target
|
|
81
|
+
environment name on the first line:
|
|
82
|
+
|
|
83
|
+
- `scripts/start-BJ11.sh`: `prod.bj11`
|
|
84
|
+
- `scripts/start-BJ12.sh`: `test.bj12`
|
|
85
|
+
- `scripts/start-SH20.sh`: `prod.sh20`
|
|
86
|
+
- `scripts/start-SZ31.sh`: `prod.sz31`
|
|
87
|
+
|
|
88
|
+
The deploy launcher at `deploy/scripts/start.sh` reads that environment name,
|
|
89
|
+
exports `FLASK_ENV`, and starts the app through Hypercorn.
|
|
90
|
+
|
|
91
|
+
Environment files live under `app/` and are intentionally ignored by Git:
|
|
92
|
+
|
|
93
|
+
- `app/.env`
|
|
94
|
+
- `app/.env.dev`
|
|
95
|
+
- `app/.env.prod.bj11`
|
|
96
|
+
- `app/.env.prod.sh20`
|
|
97
|
+
- `app/.env.prod.sz31`
|
|
98
|
+
- `app/.env.test.bj12`
|
|
99
|
+
|
|
100
|
+
Treat all environment files, credentials, tokens, and production configuration
|
|
101
|
+
as sensitive. Do not commit them.
|
|
102
|
+
|
|
103
|
+
## Deployment
|
|
104
|
+
|
|
105
|
+
Deployment files are organized under `deploy/`:
|
|
106
|
+
|
|
107
|
+
- `deploy/autoconf.yml`: Autoconf mapping for deployment environments.
|
|
108
|
+
- `deploy/autoconf/templates/env.j2`: Template used to render environment
|
|
109
|
+
variables.
|
|
110
|
+
- `deploy/scripts/start.sh`: Creates or uses a virtual environment, installs
|
|
111
|
+
dependencies, and starts Hypercorn.
|
|
112
|
+
- `deploy/scripts/stop.sh`: Stops the Hypercorn process.
|
|
113
|
+
- `deploy/scripts/healthcheck.sh`: Deployment health check entrypoint.
|
|
114
|
+
- `deploy/scripts/requirements.txt`: Deployment dependency file. It should stay
|
|
115
|
+
in sync with root `requirements.txt`.
|
|
116
|
+
- `deploy/offline-packages/`: Expected location for offline wheel packages when
|
|
117
|
+
building a fully offline deployment bundle.
|
|
118
|
+
|
|
119
|
+
## Development Notes
|
|
120
|
+
|
|
121
|
+
- Read this file before changing project code.
|
|
122
|
+
- Keep changes scoped to the requested behavior.
|
|
123
|
+
- Prefer existing package boundaries: views call managers or services; services
|
|
124
|
+
contain core business logic; utils stay generic.
|
|
125
|
+
- Keep RAG knowledge content under `knowledge/`. The directory is tracked using
|
|
126
|
+
`.gitkeep`; knowledge documents are managed separately and ignored by default.
|
|
127
|
+
- Keep tool-call schema changes in `tools/tool_definitions.yaml` aligned with
|
|
128
|
+
`app/utils/function_utils.py` and the services that implement tools.
|
|
129
|
+
- Avoid committing generated caches, virtual environments, local environment
|
|
130
|
+
files, or machine-specific artifacts.
|
|
131
|
+
- Before publishing this project to npm, bump the package version forward and
|
|
132
|
+
verify the packed artifact includes the full `app/`, `tools/`, and
|
|
133
|
+
`knowledge/` directories plus `deploy/` excluding `deploy/offline-packages/`;
|
|
134
|
+
keep the existing `.gitignore` rule that ignores local `knowledge/` files.
|
|
135
|
+
- npm publishes must include `app/.env*` environment files, but only after
|
|
136
|
+
temporarily masking every sensitive value in those files, including keys,
|
|
137
|
+
URLs, tokens, secrets, cookies, passwords, and values that expose business
|
|
138
|
+
terms such as `网联`, `网联清算`, `nucc`, `uops`, or `联合运维`. After the npm
|
|
139
|
+
publish finishes, restore the local `.env*` files back to their original
|
|
140
|
+
plaintext values and remove the temporary masking changes.
|
|
141
|
+
- Keep `app/.env*` files human-editable: preserve their key order, comments,
|
|
142
|
+
and blank-line grouping when normalizing, masking, or restoring them.
|
|
143
|
+
|
|
144
|
+
## GLM Model Capability Reference
|
|
145
|
+
|
|
146
|
+
- Use `/Users/simon/Documents/glm-model-doc.md` as the local long-term reference
|
|
147
|
+
for GLM model capabilities. When a change or design decision depends on GLM
|
|
148
|
+
behavior such as Thinking, Interleaved Thinking, Preserved Thinking,
|
|
149
|
+
turn-level thinking, streaming, function calling, tool streaming, or agent
|
|
150
|
+
loops, read that document before assuming API behavior.
|
|
151
|
+
- For complex chat, RAG, or tool-call work, prefer designs that match GLM's
|
|
152
|
+
native tool-calling and thinking model instead of adding ad hoc orchestration
|
|
153
|
+
first. In particular, RAG can be exposed as a normal tool when the model needs
|
|
154
|
+
to decide search intent from conversation history.
|
|
155
|
+
- When using GLM Thinking with tools, preserve the model's `reasoning_content`
|
|
156
|
+
according to the document's requirements. Interleaved thinking allows the
|
|
157
|
+
model to continue reasoning between tool calls and after tool results; for
|
|
158
|
+
preserved thinking, pass complete, unmodified reasoning content back in later
|
|
159
|
+
messages and use `clear_thinking: false` where applicable.
|
|
160
|
+
- Do not rely on prompt text alone for critical tool hierarchy or evidence
|
|
161
|
+
policy. Keep executable tool definitions in `tools/tool_definitions.yaml`, and
|
|
162
|
+
treat knowledge-base "related functions" as routing hints unless code
|
|
163
|
+
explicitly promotes them to executable tools.
|
|
164
|
+
|
|
165
|
+
## Validation
|
|
166
|
+
|
|
167
|
+
Use the smallest reliable checks that cover the change:
|
|
168
|
+
|
|
169
|
+
- Syntax check: `python3 -m compileall app`
|
|
170
|
+
- RAG smoke check when touching RAG code:
|
|
171
|
+
`python3 -c "from app import create_app; app = create_app(); print(app.extensions['chatstream_manager'].check_rag())"`
|
|
172
|
+
- Endpoint smoke checks should cover `/healthcheck.html` and the relevant
|
|
173
|
+
`/chatstream/v1/*` route when route behavior changes.
|
|
174
|
+
- When dependency files change, verify root `requirements.txt` and
|
|
175
|
+
`deploy/scripts/requirements.txt` stay aligned.
|
|
176
|
+
|
|
177
|
+
## Known Structure Gaps To Confirm
|
|
178
|
+
|
|
179
|
+
These are structure differences observed during the initial repository check:
|
|
180
|
+
|
|
181
|
+
- `deploy/offline-packages/` is expected by the original structure but is not
|
|
182
|
+
currently present.
|
|
183
|
+
- Shell scripts are present but may need executable permissions for deployment.
|
|
184
|
+
- `tools/tool_definitions.yaml` currently exists but may need project-specific
|
|
185
|
+
tool definitions populated.
|
|
186
|
+
- `scripts/healthcheck.sh` and `deploy/scripts/healthcheck.sh` currently exist
|
|
187
|
+
but may need health check logic populated.
|
package/app/.env
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Flask and request authentication
|
|
2
|
+
SECRET_KEY=<MASKED_SECRET>
|
|
3
|
+
|
|
4
|
+
# External API endpoints
|
|
5
|
+
GET_USE_INFO_URL=<MASKED_URL>
|
|
6
|
+
GET_ORG_INFO_URL=<MASKED_URL>
|
|
7
|
+
GET_JIRA_INFO_URL=<MASKED_URL>
|
|
8
|
+
GET_BIGDATA_URL=<MASKED_URL>
|
|
9
|
+
GET_UNION_BASE_URL=<MASKED_URL>
|
|
10
|
+
|
|
11
|
+
# Legacy external API tokens
|
|
12
|
+
GET_ORG_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
13
|
+
GET_JIRA_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
14
|
+
|
|
15
|
+
# Authorization and logging
|
|
16
|
+
PERMISSIONS=
|
|
17
|
+
LOG_LEVEL=INFO
|
|
18
|
+
CONSOLE_STDOUT=TRUE
|
|
19
|
+
LOG_DIR=/data/appLogs
|
|
20
|
+
|
|
21
|
+
# Runtime environment and JWT
|
|
22
|
+
FLASK_ENV=dev
|
|
23
|
+
JWT_SECRET_KEY=<MASKED_SECRET>
|
|
24
|
+
JWT_EXPIRATION_SECOND=900
|
|
25
|
+
JWT_RENEW_SECOND=700
|
|
26
|
+
|
|
27
|
+
# LLM provider
|
|
28
|
+
LLM_URL=<MASKED_URL>
|
|
29
|
+
LLM_KEY=<MASKED_KEY>
|
|
30
|
+
LLM_MODEL=GLM-4.7-Flash
|
|
31
|
+
LLM_MAX_TOKENS=4096
|
|
32
|
+
LLM_TEMPERATURE=0.7
|
|
33
|
+
LLM_TOP_P=0.9
|
|
34
|
+
|
|
35
|
+
# Chat behavior
|
|
36
|
+
SYSTEM_PROMPT=<MASKED_BUSINESS_VALUE>
|
|
37
|
+
|
|
38
|
+
# Business filter
|
|
39
|
+
FILTER_ENABLED=false
|
|
40
|
+
FILTER_ALLOWED_KEYWORDS=<MASKED_BUSINESS_VALUE>
|
|
41
|
+
FILTER_REJECTION_MESSAGE=<MASKED_BUSINESS_VALUE>
|
|
42
|
+
|
|
43
|
+
# Tool and conversation settings
|
|
44
|
+
TOOLS_MAX_ROUNDS=5
|
|
45
|
+
CONVERSATION_MAX_HISTORY=20
|
|
46
|
+
CONVERSATION_TTL=3600
|
|
47
|
+
|
|
48
|
+
# RAG settings
|
|
49
|
+
RAG_ENABLED=true
|
|
50
|
+
RAG_KNOWLEDGE_DIR=knowledge
|
|
51
|
+
RAG_PERSIST_DIR=.chroma
|
|
52
|
+
RAG_COLLECTION=ops_knowledge
|
|
53
|
+
RAG_EMBEDDING_MODEL=embedding-3
|
|
54
|
+
RAG_EMBEDDING_MAX_CHARS=6000
|
|
55
|
+
RAG_EMBEDDING_BATCH_SIZE=8
|
|
56
|
+
RAG_TOP_K=5
|
|
57
|
+
RAG_SEMANTIC_CANDIDATE_K=40
|
|
58
|
+
RAG_CONTEXT_K=8
|
|
59
|
+
RAG_EXACT_CONTEXT_K=3
|
|
60
|
+
RAG_EXACT_PER_FILE_CONTEXT_K=1
|
|
61
|
+
RAG_PER_FILE_CONTEXT_K=2
|
|
62
|
+
RAG_CHUNK_SIZE=1200
|
|
63
|
+
RAG_REBUILD_ON_STARTUP=false
|
package/app/.env.dev
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Flask and request authentication
|
|
2
|
+
SECRET_KEY=<MASKED_SECRET>
|
|
3
|
+
|
|
4
|
+
# External API endpoints
|
|
5
|
+
GET_USE_INFO_URL=<MASKED_URL>
|
|
6
|
+
GET_ORG_INFO_URL=<MASKED_URL>
|
|
7
|
+
GET_JIRA_INFO_URL=<MASKED_URL>
|
|
8
|
+
GET_BIGDATA_URL=<MASKED_URL>
|
|
9
|
+
GET_UNION_BASE_URL=<MASKED_URL>
|
|
10
|
+
|
|
11
|
+
# Legacy external API tokens
|
|
12
|
+
GET_ORG_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
13
|
+
GET_JIRA_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
14
|
+
|
|
15
|
+
# Authorization and logging
|
|
16
|
+
PERMISSIONS=
|
|
17
|
+
LOG_LEVEL=INFO
|
|
18
|
+
CONSOLE_STDOUT=TRUE
|
|
19
|
+
LOG_DIR=/Users/simon/code/union-py-app/data/appLogs
|
|
20
|
+
|
|
21
|
+
# Runtime environment and JWT
|
|
22
|
+
FLASK_ENV=dev
|
|
23
|
+
JWT_SECRET_KEY=<MASKED_SECRET>
|
|
24
|
+
JWT_EXPIRATION_SECOND=900
|
|
25
|
+
JWT_RENEW_SECOND=700
|
|
26
|
+
|
|
27
|
+
# LLM provider
|
|
28
|
+
LLM_URL=<MASKED_URL>
|
|
29
|
+
LLM_KEY=<MASKED_KEY>
|
|
30
|
+
LLM_MODEL=GLM-4.7-Flash
|
|
31
|
+
LLM_MAX_TOKENS=4096
|
|
32
|
+
LLM_TEMPERATURE=0.7
|
|
33
|
+
LLM_TOP_P=0.9
|
|
34
|
+
|
|
35
|
+
# Chat behavior
|
|
36
|
+
SYSTEM_PROMPT=<MASKED_BUSINESS_VALUE>
|
|
37
|
+
|
|
38
|
+
# Business filter
|
|
39
|
+
FILTER_ENABLED=false
|
|
40
|
+
FILTER_ALLOWED_KEYWORDS=<MASKED_BUSINESS_VALUE>
|
|
41
|
+
FILTER_REJECTION_MESSAGE=<MASKED_BUSINESS_VALUE>
|
|
42
|
+
|
|
43
|
+
# Tool and conversation settings
|
|
44
|
+
TOOLS_MAX_ROUNDS=5
|
|
45
|
+
CONVERSATION_MAX_HISTORY=20
|
|
46
|
+
CONVERSATION_TTL=3600
|
|
47
|
+
|
|
48
|
+
# RAG settings
|
|
49
|
+
RAG_ENABLED=true
|
|
50
|
+
RAG_KNOWLEDGE_DIR=knowledge
|
|
51
|
+
RAG_PERSIST_DIR=.chroma
|
|
52
|
+
RAG_COLLECTION=ops_knowledge
|
|
53
|
+
RAG_EMBEDDING_MODEL=embedding-3
|
|
54
|
+
RAG_EMBEDDING_MAX_CHARS=6000
|
|
55
|
+
RAG_EMBEDDING_BATCH_SIZE=8
|
|
56
|
+
RAG_TOP_K=5
|
|
57
|
+
RAG_SEMANTIC_CANDIDATE_K=40
|
|
58
|
+
RAG_CONTEXT_K=8
|
|
59
|
+
RAG_EXACT_CONTEXT_K=3
|
|
60
|
+
RAG_EXACT_PER_FILE_CONTEXT_K=1
|
|
61
|
+
RAG_PER_FILE_CONTEXT_K=2
|
|
62
|
+
RAG_CHUNK_SIZE=1200
|
|
63
|
+
RAG_REBUILD_ON_STARTUP=false
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Flask and request authentication
|
|
2
|
+
SECRET_KEY=<MASKED_SECRET>
|
|
3
|
+
|
|
4
|
+
# External API endpoints
|
|
5
|
+
GET_USE_INFO_URL=<MASKED_URL>
|
|
6
|
+
GET_ORG_INFO_URL=<MASKED_URL>
|
|
7
|
+
GET_JIRA_INFO_URL=<MASKED_URL>
|
|
8
|
+
GET_BIGDATA_URL=<MASKED_URL>
|
|
9
|
+
GET_UNION_BASE_URL=<MASKED_URL>
|
|
10
|
+
|
|
11
|
+
# Legacy external API tokens
|
|
12
|
+
GET_ORG_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
13
|
+
GET_JIRA_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
14
|
+
|
|
15
|
+
# Authorization and logging
|
|
16
|
+
PERMISSIONS=
|
|
17
|
+
LOG_LEVEL=INFO
|
|
18
|
+
CONSOLE_STDOUT=FALSE
|
|
19
|
+
LOG_DIR=/data/appLogs
|
|
20
|
+
|
|
21
|
+
# Runtime environment and JWT
|
|
22
|
+
FLASK_ENV=prod.bj11
|
|
23
|
+
JWT_SECRET_KEY=<MASKED_SECRET>
|
|
24
|
+
JWT_EXPIRATION_SECOND=900
|
|
25
|
+
JWT_RENEW_SECOND=700
|
|
26
|
+
|
|
27
|
+
# LLM provider
|
|
28
|
+
LLM_URL=<MASKED_URL>
|
|
29
|
+
LLM_KEY=<MASKED_KEY>
|
|
30
|
+
LLM_MODEL=glm-5
|
|
31
|
+
LLM_MAX_TOKENS=4096
|
|
32
|
+
LLM_TEMPERATURE=0.7
|
|
33
|
+
LLM_TOP_P=0.9
|
|
34
|
+
|
|
35
|
+
# Chat behavior
|
|
36
|
+
SYSTEM_PROMPT=<MASKED_BUSINESS_VALUE>
|
|
37
|
+
|
|
38
|
+
# Business filter
|
|
39
|
+
FILTER_ENABLED=false
|
|
40
|
+
FILTER_ALLOWED_KEYWORDS=<MASKED_BUSINESS_VALUE>
|
|
41
|
+
FILTER_REJECTION_MESSAGE=<MASKED_BUSINESS_VALUE>
|
|
42
|
+
|
|
43
|
+
# Tool and conversation settings
|
|
44
|
+
TOOLS_MAX_ROUNDS=5
|
|
45
|
+
CONVERSATION_MAX_HISTORY=20
|
|
46
|
+
CONVERSATION_TTL=3600
|
|
47
|
+
|
|
48
|
+
# RAG settings
|
|
49
|
+
RAG_ENABLED=true
|
|
50
|
+
RAG_KNOWLEDGE_DIR=knowledge
|
|
51
|
+
RAG_PERSIST_DIR=.chroma
|
|
52
|
+
RAG_COLLECTION=ops_knowledge
|
|
53
|
+
RAG_EMBEDDING_MODEL=embedding-3
|
|
54
|
+
RAG_EMBEDDING_MAX_CHARS=6000
|
|
55
|
+
RAG_EMBEDDING_BATCH_SIZE=8
|
|
56
|
+
RAG_TOP_K=5
|
|
57
|
+
RAG_SEMANTIC_CANDIDATE_K=40
|
|
58
|
+
RAG_CONTEXT_K=8
|
|
59
|
+
RAG_EXACT_CONTEXT_K=3
|
|
60
|
+
RAG_EXACT_PER_FILE_CONTEXT_K=1
|
|
61
|
+
RAG_PER_FILE_CONTEXT_K=2
|
|
62
|
+
RAG_CHUNK_SIZE=1200
|
|
63
|
+
RAG_REBUILD_ON_STARTUP=false
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Flask and request authentication
|
|
2
|
+
SECRET_KEY=<MASKED_SECRET>
|
|
3
|
+
|
|
4
|
+
# External API endpoints
|
|
5
|
+
GET_USE_INFO_URL=<MASKED_URL>
|
|
6
|
+
GET_ORG_INFO_URL=<MASKED_URL>
|
|
7
|
+
GET_JIRA_INFO_URL=<MASKED_URL>
|
|
8
|
+
GET_BIGDATA_URL=<MASKED_URL>
|
|
9
|
+
GET_UNION_BASE_URL=<MASKED_URL>
|
|
10
|
+
|
|
11
|
+
# Legacy external API tokens
|
|
12
|
+
GET_ORG_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
13
|
+
GET_JIRA_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
14
|
+
|
|
15
|
+
# Authorization and logging
|
|
16
|
+
PERMISSIONS=
|
|
17
|
+
LOG_LEVEL=INFO
|
|
18
|
+
CONSOLE_STDOUT=FALSE
|
|
19
|
+
LOG_DIR=/data/appLogs
|
|
20
|
+
|
|
21
|
+
# Runtime environment and JWT
|
|
22
|
+
FLASK_ENV=prod.sh20
|
|
23
|
+
JWT_SECRET_KEY=<MASKED_SECRET>
|
|
24
|
+
JWT_EXPIRATION_SECOND=900
|
|
25
|
+
JWT_RENEW_SECOND=700
|
|
26
|
+
|
|
27
|
+
# LLM provider
|
|
28
|
+
LLM_URL=<MASKED_URL>
|
|
29
|
+
LLM_KEY=<MASKED_KEY>
|
|
30
|
+
LLM_MODEL=glm-5
|
|
31
|
+
LLM_MAX_TOKENS=4096
|
|
32
|
+
LLM_TEMPERATURE=0.7
|
|
33
|
+
LLM_TOP_P=0.9
|
|
34
|
+
|
|
35
|
+
# Chat behavior
|
|
36
|
+
SYSTEM_PROMPT=<MASKED_BUSINESS_VALUE>
|
|
37
|
+
|
|
38
|
+
# Business filter
|
|
39
|
+
FILTER_ENABLED=false
|
|
40
|
+
FILTER_ALLOWED_KEYWORDS=<MASKED_BUSINESS_VALUE>
|
|
41
|
+
FILTER_REJECTION_MESSAGE=<MASKED_BUSINESS_VALUE>
|
|
42
|
+
|
|
43
|
+
# Tool and conversation settings
|
|
44
|
+
TOOLS_MAX_ROUNDS=5
|
|
45
|
+
CONVERSATION_MAX_HISTORY=20
|
|
46
|
+
CONVERSATION_TTL=3600
|
|
47
|
+
|
|
48
|
+
# RAG settings
|
|
49
|
+
RAG_ENABLED=true
|
|
50
|
+
RAG_KNOWLEDGE_DIR=knowledge
|
|
51
|
+
RAG_PERSIST_DIR=.chroma
|
|
52
|
+
RAG_COLLECTION=ops_knowledge
|
|
53
|
+
RAG_EMBEDDING_MODEL=embedding-3
|
|
54
|
+
RAG_EMBEDDING_MAX_CHARS=6000
|
|
55
|
+
RAG_EMBEDDING_BATCH_SIZE=8
|
|
56
|
+
RAG_TOP_K=5
|
|
57
|
+
RAG_SEMANTIC_CANDIDATE_K=40
|
|
58
|
+
RAG_CONTEXT_K=8
|
|
59
|
+
RAG_EXACT_CONTEXT_K=3
|
|
60
|
+
RAG_EXACT_PER_FILE_CONTEXT_K=1
|
|
61
|
+
RAG_PER_FILE_CONTEXT_K=2
|
|
62
|
+
RAG_CHUNK_SIZE=1200
|
|
63
|
+
RAG_REBUILD_ON_STARTUP=false
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Flask and request authentication
|
|
2
|
+
SECRET_KEY=<MASKED_SECRET>
|
|
3
|
+
|
|
4
|
+
# External API endpoints
|
|
5
|
+
GET_USE_INFO_URL=<MASKED_URL>
|
|
6
|
+
GET_ORG_INFO_URL=<MASKED_URL>
|
|
7
|
+
GET_JIRA_INFO_URL=<MASKED_URL>
|
|
8
|
+
GET_BIGDATA_URL=<MASKED_URL>
|
|
9
|
+
GET_UNION_BASE_URL=<MASKED_URL>
|
|
10
|
+
|
|
11
|
+
# Legacy external API tokens
|
|
12
|
+
GET_ORG_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
13
|
+
GET_JIRA_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
14
|
+
|
|
15
|
+
# Authorization and logging
|
|
16
|
+
PERMISSIONS=
|
|
17
|
+
LOG_LEVEL=INFO
|
|
18
|
+
CONSOLE_STDOUT=FALSE
|
|
19
|
+
LOG_DIR=/data/appLogs
|
|
20
|
+
|
|
21
|
+
# Runtime environment and JWT
|
|
22
|
+
FLASK_ENV=prod.sz31
|
|
23
|
+
JWT_SECRET_KEY=<MASKED_SECRET>
|
|
24
|
+
JWT_EXPIRATION_SECOND=900
|
|
25
|
+
JWT_RENEW_SECOND=700
|
|
26
|
+
|
|
27
|
+
# LLM provider
|
|
28
|
+
LLM_URL=<MASKED_URL>
|
|
29
|
+
LLM_KEY=<MASKED_KEY>
|
|
30
|
+
LLM_MODEL=glm-5
|
|
31
|
+
LLM_MAX_TOKENS=4096
|
|
32
|
+
LLM_TEMPERATURE=0.7
|
|
33
|
+
LLM_TOP_P=0.9
|
|
34
|
+
|
|
35
|
+
# Chat behavior
|
|
36
|
+
SYSTEM_PROMPT=<MASKED_BUSINESS_VALUE>
|
|
37
|
+
|
|
38
|
+
# Business filter
|
|
39
|
+
FILTER_ENABLED=false
|
|
40
|
+
FILTER_ALLOWED_KEYWORDS=<MASKED_BUSINESS_VALUE>
|
|
41
|
+
FILTER_REJECTION_MESSAGE=<MASKED_BUSINESS_VALUE>
|
|
42
|
+
|
|
43
|
+
# Tool and conversation settings
|
|
44
|
+
TOOLS_MAX_ROUNDS=5
|
|
45
|
+
CONVERSATION_MAX_HISTORY=20
|
|
46
|
+
CONVERSATION_TTL=3600
|
|
47
|
+
|
|
48
|
+
# RAG settings
|
|
49
|
+
RAG_ENABLED=true
|
|
50
|
+
RAG_KNOWLEDGE_DIR=knowledge
|
|
51
|
+
RAG_PERSIST_DIR=.chroma
|
|
52
|
+
RAG_COLLECTION=ops_knowledge
|
|
53
|
+
RAG_EMBEDDING_MODEL=embedding-3
|
|
54
|
+
RAG_EMBEDDING_MAX_CHARS=6000
|
|
55
|
+
RAG_EMBEDDING_BATCH_SIZE=8
|
|
56
|
+
RAG_TOP_K=5
|
|
57
|
+
RAG_SEMANTIC_CANDIDATE_K=40
|
|
58
|
+
RAG_CONTEXT_K=8
|
|
59
|
+
RAG_EXACT_CONTEXT_K=3
|
|
60
|
+
RAG_EXACT_PER_FILE_CONTEXT_K=1
|
|
61
|
+
RAG_PER_FILE_CONTEXT_K=2
|
|
62
|
+
RAG_CHUNK_SIZE=1200
|
|
63
|
+
RAG_REBUILD_ON_STARTUP=false
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Flask and request authentication
|
|
2
|
+
SECRET_KEY=<MASKED_SECRET>
|
|
3
|
+
|
|
4
|
+
# External API endpoints
|
|
5
|
+
GET_USE_INFO_URL=<MASKED_URL>
|
|
6
|
+
GET_ORG_INFO_URL=<MASKED_URL>
|
|
7
|
+
GET_JIRA_INFO_URL=<MASKED_URL>
|
|
8
|
+
GET_BIGDATA_URL=<MASKED_URL>
|
|
9
|
+
GET_UNION_BASE_URL=<MASKED_URL>
|
|
10
|
+
|
|
11
|
+
# Legacy external API tokens
|
|
12
|
+
GET_ORG_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
13
|
+
GET_JIRA_INFO_URL_TOKEN=<MASKED_TOKEN>
|
|
14
|
+
|
|
15
|
+
# Authorization and logging
|
|
16
|
+
PERMISSIONS=
|
|
17
|
+
LOG_LEVEL=INFO
|
|
18
|
+
CONSOLE_STDOUT=FALSE
|
|
19
|
+
LOG_DIR=/data/appLogs
|
|
20
|
+
|
|
21
|
+
# Runtime environment and JWT
|
|
22
|
+
FLASK_ENV=test.prod.bj12
|
|
23
|
+
JWT_SECRET_KEY=<MASKED_SECRET>
|
|
24
|
+
JWT_EXPIRATION_SECOND=900
|
|
25
|
+
JWT_RENEW_SECOND=700
|
|
26
|
+
|
|
27
|
+
# LLM provider
|
|
28
|
+
LLM_URL=<MASKED_URL>
|
|
29
|
+
LLM_KEY=<MASKED_KEY>
|
|
30
|
+
LLM_MODEL=glm-5
|
|
31
|
+
LLM_MAX_TOKENS=4096
|
|
32
|
+
LLM_TEMPERATURE=0.7
|
|
33
|
+
LLM_TOP_P=0.9
|
|
34
|
+
|
|
35
|
+
# Chat behavior
|
|
36
|
+
SYSTEM_PROMPT=<MASKED_BUSINESS_VALUE>
|
|
37
|
+
|
|
38
|
+
# Business filter
|
|
39
|
+
FILTER_ENABLED=false
|
|
40
|
+
FILTER_ALLOWED_KEYWORDS=<MASKED_BUSINESS_VALUE>
|
|
41
|
+
FILTER_REJECTION_MESSAGE=<MASKED_BUSINESS_VALUE>
|
|
42
|
+
|
|
43
|
+
# Tool and conversation settings
|
|
44
|
+
TOOLS_MAX_ROUNDS=5
|
|
45
|
+
CONVERSATION_MAX_HISTORY=20
|
|
46
|
+
CONVERSATION_TTL=3600
|
|
47
|
+
|
|
48
|
+
# RAG settings
|
|
49
|
+
RAG_ENABLED=true
|
|
50
|
+
RAG_KNOWLEDGE_DIR=knowledge
|
|
51
|
+
RAG_PERSIST_DIR=.chroma
|
|
52
|
+
RAG_COLLECTION=ops_knowledge
|
|
53
|
+
RAG_EMBEDDING_MODEL=embedding-3
|
|
54
|
+
RAG_EMBEDDING_MAX_CHARS=6000
|
|
55
|
+
RAG_EMBEDDING_BATCH_SIZE=8
|
|
56
|
+
RAG_TOP_K=5
|
|
57
|
+
RAG_SEMANTIC_CANDIDATE_K=40
|
|
58
|
+
RAG_CONTEXT_K=8
|
|
59
|
+
RAG_EXACT_CONTEXT_K=3
|
|
60
|
+
RAG_EXACT_PER_FILE_CONTEXT_K=1
|
|
61
|
+
RAG_PER_FILE_CONTEXT_K=2
|
|
62
|
+
RAG_CHUNK_SIZE=1200
|
|
63
|
+
RAG_REBUILD_ON_STARTUP=false
|
package/app/__init__.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from flask import Flask
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _load_dotenv_for_env():
|
|
8
|
+
config_name = os.getenv("FLASK_ENV", "dev")
|
|
9
|
+
dotenv_file = os.path.join(os.path.dirname(__file__), f".env.{config_name}")
|
|
10
|
+
load_dotenv(dotenv_file, override=True, verbose=True)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def create_app():
|
|
14
|
+
_load_dotenv_for_env()
|
|
15
|
+
|
|
16
|
+
app = Flask(__name__)
|
|
17
|
+
from app.config.env_config import Config
|
|
18
|
+
app.config.from_object(Config)
|
|
19
|
+
|
|
20
|
+
from .authenticated_user import FlaskSessionClient
|
|
21
|
+
FlaskSessionClient(app)
|
|
22
|
+
|
|
23
|
+
from app.manager.chatstream_manager import ChatstreamManager
|
|
24
|
+
from app.manager.runtime_manager import RuntimeManager
|
|
25
|
+
from app.service.chat_service import ChatService
|
|
26
|
+
from app.service.llm_service import llm_service
|
|
27
|
+
from app.service.rag_service import RagService
|
|
28
|
+
from app.service.union_service import union_service
|
|
29
|
+
|
|
30
|
+
llm_service.initialize(app.config)
|
|
31
|
+
union_service.initialize(app.config)
|
|
32
|
+
rag_service = RagService(app.config)
|
|
33
|
+
chat_service = ChatService(app.config, rag_service, union_service)
|
|
34
|
+
|
|
35
|
+
app.extensions["chatstream_manager"] = ChatstreamManager(app.config, chat_service, rag_service)
|
|
36
|
+
app.extensions["runtime_manager"] = RuntimeManager(union_service, llm_service)
|
|
37
|
+
|
|
38
|
+
from .views import blueprints
|
|
39
|
+
|
|
40
|
+
for bp in blueprints:
|
|
41
|
+
app.register_blueprint(bp)
|
|
42
|
+
return app
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|