Skip to content

Commit 3bd3830

Browse files
authored
feat: sso login, demo mode & new mindmap support (#644) bump:minor
* fix: update .env.example * feat: add SSO login * fix: update flowsetting * fix: add requirement * fix: refine UI * fix: update group id-based operation * fix: improve citation logics * fix: UI enhancement * fix: user_id to string in models * fix: improve chat suggestion UI and flow * fix: improve group id handling * fix: improve chat suggestion * fix: secure download for single file * fix: file limiting in docstore * fix: improve chat suggestion logics & language conform * feat: add markmap and select text to highlight function * fix: update Dockerfile * fix: user id auto generate * fix: default user id * feat: add demo mode * fix: update flowsetting * fix: revise default params for demo * feat: sso_app alternative * feat: sso login demo * feat: demo specific customization * feat: add login using API key * fix: disable key-based login * fix: optimize duplicate upload * fix: gradio routing * fix: disable arm build for demo * fix: revise full-text search js logic * feat: add rate limit * fix: update Dockerfile with new launch script * fix: update Dockerfile * fix: update Dockerignore * fix: update ratelimit logic * fix: user_id in user management page * fix: rename conv logic * feat: update demo hint * fix: minor fix * fix: highlight on long PDF load * feat: add HF paper list * fix: update HF papers load logic * feat: fly config * fix: update fly config * fix: update paper list pull api * fix: minor update root routing * fix: minor update root routing * fix: simplify login flow & paper list UI * feat: add paper recommendation * fix: update Dockerfile * fix: update Dockerfile * fix: update default model * feat: add long context Ollama through LCOllama * feat: espose Gradio share to env * fix: revert customized changes * fix: list group at app load * fix: relocate share conv button * fix: update launch script * fix: update Docker CI * feat: add Ollama model selection at first setup * docs: update README
1 parent 3006402 commit 3bd3830

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2478
-927
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ env/
1111
README.md
1212
*.zip
1313
*.sh
14+
15+
!/launch.sh

.env.example

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# settings for OpenAI
44
OPENAI_API_BASE=https://api.openai.com/v1
55
OPENAI_API_KEY=<YOUR_OPENAI_KEY>
6-
OPENAI_CHAT_MODEL=gpt-3.5-turbo
7-
OPENAI_EMBEDDINGS_MODEL=text-embedding-ada-002
6+
OPENAI_CHAT_MODEL=gpt-4o-mini
7+
OPENAI_EMBEDDINGS_MODEL=text-embedding-3-large
88

99
# settings for Azure OpenAI
1010
AZURE_OPENAI_ENDPOINT=
@@ -17,10 +17,8 @@ AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=text-embedding-ada-002
1717
COHERE_API_KEY=<COHERE_API_KEY>
1818

1919
# settings for local models
20-
LOCAL_MODEL=llama3.1:8b
20+
LOCAL_MODEL=qwen2.5:7b
2121
LOCAL_MODEL_EMBEDDINGS=nomic-embed-text
22-
LOCAL_EMBEDDING_MODEL_DIM = 768
23-
LOCAL_EMBEDDING_MODEL_MAX_TOKENS = 8192
2422

2523
# settings for GraphRAG
2624
GRAPHRAG_API_KEY=<YOUR_OPENAI_KEY>

.github/workflows/build-push-docker.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
target:
2929
- lite
3030
- full
31+
- ollama
3132
steps:
3233
- name: Free Disk Space (Ubuntu)
3334
uses: jlumbroso/free-disk-space@main

.github/workflows/fly-deploy.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ repos:
5757
"types-requests",
5858
"sqlmodel",
5959
"types-Markdown",
60+
"types-cachetools",
6061
types-tzlocal,
6162
]
6263
args: ["--check-untyped-defs", "--ignore-missing-imports"]

Dockerfile

+15-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RUN bash scripts/download_pdfjs.sh $PDFJS_PREBUILT_DIR
3535

3636
# Copy contents
3737
COPY . /app
38+
COPY launch.sh /app/launch.sh
3839
COPY .env.example /app/.env
3940

4041
# Install pip packages
@@ -54,7 +55,7 @@ RUN apt-get autoremove \
5455
&& rm -rf /var/lib/apt/lists/* \
5556
&& rm -rf ~/.cache
5657

57-
CMD ["python", "app.py"]
58+
ENTRYPOINT ["sh", "/app/launch.sh"]
5859

5960
# Full version
6061
FROM lite AS full
@@ -97,7 +98,17 @@ RUN apt-get autoremove \
9798
&& rm -rf /var/lib/apt/lists/* \
9899
&& rm -rf ~/.cache
99100

100-
# Download nltk packages as required for unstructured
101-
# RUN python -c "from unstructured.nlp.tokenize import _download_nltk_packages_if_not_present; _download_nltk_packages_if_not_present()"
101+
ENTRYPOINT ["sh", "/app/launch.sh"]
102102

103-
CMD ["python", "app.py"]
103+
# Ollama-bundled version
104+
FROM full AS ollama
105+
106+
# Install ollama
107+
RUN --mount=type=ssh \
108+
--mount=type=cache,target=/root/.cache/pip \
109+
curl -fsSL https://ollama.com/install.sh | sh
110+
111+
# RUN nohup bash -c "ollama serve &" && sleep 4 && ollama pull qwen2.5:7b
112+
RUN nohup bash -c "ollama serve &" && sleep 4 && ollama pull nomic-embed-text
113+
114+
ENTRYPOINT ["sh", "/app/launch.sh"]

README.md

+9-13
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,7 @@ documents and developers who want to build their own RAG pipeline.
9696

9797
### With Docker (recommended)
9898

99-
1. We support both `lite` & `full` version of Docker images. With `full`, the extra packages of `unstructured` will be installed as well, it can support additional file types (`.doc`, `.docx`, ...) but the cost is larger docker image size. For most users, the `lite` image should work well in most cases.
100-
101-
- To use the `lite` version.
102-
103-
```bash
104-
docker run \
105-
-e GRADIO_SERVER_NAME=0.0.0.0 \
106-
-e GRADIO_SERVER_PORT=7860 \
107-
-v ./ktem_app_data:/app/ktem_app_data \
108-
-p 7860:7860 -it --rm \
109-
ghcr.io/cinnamon/kotaemon:main-lite
110-
```
99+
1. We support both `lite` & `full` version of Docker images. With `full` version, the extra packages of `unstructured` will be installed, which can support additional file types (`.doc`, `.docx`, ...) but the cost is larger docker image size. For most users, the `lite` image should work well in most cases.
111100

112101
- To use the `full` version.
113102

@@ -124,9 +113,16 @@ documents and developers who want to build their own RAG pipeline.
124113

125114
```bash
126115
# change image name to
127-
ghcr.io/cinnamon/kotaemon:feat-ollama_docker-full
116+
docker run <...> ghcr.io/cinnamon/kotaemon:main-ollama
128117
```
129118

119+
- To use the `lite` version.
120+
121+
```bash
122+
# change image name to
123+
docker run <...> ghcr.io/cinnamon/kotaemon:main-lite
124+
```
125+
130126
2. We currently support and test two platforms: `linux/amd64` and `linux/arm64` (for newer Mac). You can specify the platform by passing `--platform` in the `docker run` command. For example:
131127

132128
```bash

app.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from theflow.settings import settings as flowsettings
44

55
KH_APP_DATA_DIR = getattr(flowsettings, "KH_APP_DATA_DIR", ".")
6+
KH_GRADIO_SHARE = getattr(flowsettings, "KH_GRADIO_SHARE", False)
67
GRADIO_TEMP_DIR = os.getenv("GRADIO_TEMP_DIR", None)
78
# override GRADIO_TEMP_DIR if it's not set
89
if GRADIO_TEMP_DIR is None:
@@ -21,4 +22,5 @@
2122
"libs/ktem/ktem/assets",
2223
GRADIO_TEMP_DIR,
2324
],
25+
share=KH_GRADIO_SHARE,
2426
)

docs/about.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ An open-source tool for chatting with your documents. Built with both end users
44
developers in mind.
55

66
[Source Code](https://github.com/Cinnamon/kotaemon) |
7-
[Live Demo](https://huggingface.co/spaces/cin-model/kotaemon-demo)
7+
[HF Space](https://huggingface.co/spaces/cin-model/kotaemon-demo)
88

9-
[User Guide](https://cinnamon.github.io/kotaemon/) |
9+
[Installation Guide](https://cinnamon.github.io/kotaemon/) |
1010
[Developer Guide](https://cinnamon.github.io/kotaemon/development/) |
1111
[Feedback](https://github.com/Cinnamon/kotaemon/issues)

docs/online_install.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Installation (Online HuggingFace Space)
22

33
1. Go to [HF kotaemon_template](https://huggingface.co/spaces/cin-model/kotaemon_template).
4-
2. Use Duplicate function to create your own space.
4+
2. Use Duplicate function to create your own space. Or use this [direct link](https://huggingface.co/spaces/cin-model/kotaemon_template?duplicate=true).
55
![Duplicate space](https://raw.githubusercontent.com/Cinnamon/kotaemon/main/docs/images/duplicate_space.png)
66
![Change space params](https://raw.githubusercontent.com/Cinnamon/kotaemon/main/docs/images/change_space_params.png)
77
3. Wait for the build to complete and start up (apprx 10 mins).

flowsettings.py

+38-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
except Exception:
2626
KH_APP_VERSION = "local"
2727

28-
KH_ENABLE_FIRST_SETUP = True
28+
KH_GRADIO_SHARE = config("KH_GRADIO_SHARE", default=False, cast=bool)
29+
KH_ENABLE_FIRST_SETUP = config("KH_ENABLE_FIRST_SETUP", default=True, cast=bool)
2930
KH_DEMO_MODE = config("KH_DEMO_MODE", default=False, cast=bool)
3031
KH_OLLAMA_URL = config("KH_OLLAMA_URL", default="http://localhost:11434/v1/")
3132

@@ -65,6 +66,8 @@
6566
KH_DOC_DIR = this_dir / "docs"
6667

6768
KH_MODE = "dev"
69+
KH_SSO_ENABLED = config("KH_SSO_ENABLED", default=False, cast=bool)
70+
6871
KH_FEATURE_CHAT_SUGGESTION = config(
6972
"KH_FEATURE_CHAT_SUGGESTION", default=False, cast=bool
7073
)
@@ -137,43 +140,58 @@
137140
"default": False,
138141
}
139142

140-
if config("OPENAI_API_KEY", default=""):
143+
OPENAI_DEFAULT = "<YOUR_OPENAI_KEY>"
144+
OPENAI_API_KEY = config("OPENAI_API_KEY", default=OPENAI_DEFAULT)
145+
GOOGLE_API_KEY = config("GOOGLE_API_KEY", default="your-key")
146+
IS_OPENAI_DEFAULT = len(OPENAI_API_KEY) > 0 and OPENAI_API_KEY != OPENAI_DEFAULT
147+
148+
if OPENAI_API_KEY:
141149
KH_LLMS["openai"] = {
142150
"spec": {
143151
"__type__": "kotaemon.llms.ChatOpenAI",
144152
"temperature": 0,
145153
"base_url": config("OPENAI_API_BASE", default="")
146154
or "https://api.openai.com/v1",
147-
"api_key": config("OPENAI_API_KEY", default=""),
148-
"model": config("OPENAI_CHAT_MODEL", default="gpt-3.5-turbo"),
155+
"api_key": OPENAI_API_KEY,
156+
"model": config("OPENAI_CHAT_MODEL", default="gpt-4o-mini"),
149157
"timeout": 20,
150158
},
151-
"default": True,
159+
"default": IS_OPENAI_DEFAULT,
152160
}
153161
KH_EMBEDDINGS["openai"] = {
154162
"spec": {
155163
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
156164
"base_url": config("OPENAI_API_BASE", default="https://api.openai.com/v1"),
157-
"api_key": config("OPENAI_API_KEY", default=""),
165+
"api_key": OPENAI_API_KEY,
158166
"model": config(
159-
"OPENAI_EMBEDDINGS_MODEL", default="text-embedding-ada-002"
167+
"OPENAI_EMBEDDINGS_MODEL", default="text-embedding-3-large"
160168
),
161169
"timeout": 10,
162170
"context_length": 8191,
163171
},
164-
"default": True,
172+
"default": IS_OPENAI_DEFAULT,
165173
}
166174

167175
if config("LOCAL_MODEL", default=""):
168176
KH_LLMS["ollama"] = {
169177
"spec": {
170178
"__type__": "kotaemon.llms.ChatOpenAI",
171179
"base_url": KH_OLLAMA_URL,
172-
"model": config("LOCAL_MODEL", default="llama3.1:8b"),
180+
"model": config("LOCAL_MODEL", default="qwen2.5:7b"),
173181
"api_key": "ollama",
174182
},
175183
"default": False,
176184
}
185+
KH_LLMS["ollama-long-context"] = {
186+
"spec": {
187+
"__type__": "kotaemon.llms.LCOllamaChat",
188+
"base_url": KH_OLLAMA_URL.replace("v1/", ""),
189+
"model": config("LOCAL_MODEL", default="qwen2.5:7b"),
190+
"num_ctx": 8192,
191+
},
192+
"default": False,
193+
}
194+
177195
KH_EMBEDDINGS["ollama"] = {
178196
"spec": {
179197
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
@@ -183,7 +201,6 @@
183201
},
184202
"default": False,
185203
}
186-
187204
KH_EMBEDDINGS["fast_embed"] = {
188205
"spec": {
189206
"__type__": "kotaemon.embeddings.FastEmbedEmbeddings",
@@ -205,9 +222,9 @@
205222
"spec": {
206223
"__type__": "kotaemon.llms.chats.LCGeminiChat",
207224
"model_name": "gemini-1.5-flash",
208-
"api_key": config("GOOGLE_API_KEY", default="your-key"),
225+
"api_key": GOOGLE_API_KEY,
209226
},
210-
"default": False,
227+
"default": not IS_OPENAI_DEFAULT,
211228
}
212229
KH_LLMS["groq"] = {
213230
"spec": {
@@ -241,8 +258,9 @@
241258
"spec": {
242259
"__type__": "kotaemon.embeddings.LCGoogleEmbeddings",
243260
"model": "models/text-embedding-004",
244-
"google_api_key": config("GOOGLE_API_KEY", default="your-key"),
245-
}
261+
"google_api_key": GOOGLE_API_KEY,
262+
},
263+
"default": not IS_OPENAI_DEFAULT,
246264
}
247265
# KH_EMBEDDINGS["huggingface"] = {
248266
# "spec": {
@@ -301,9 +319,12 @@
301319

302320
USE_NANO_GRAPHRAG = config("USE_NANO_GRAPHRAG", default=False, cast=bool)
303321
USE_LIGHTRAG = config("USE_LIGHTRAG", default=True, cast=bool)
322+
USE_MS_GRAPHRAG = config("USE_MS_GRAPHRAG", default=True, cast=bool)
304323

305-
GRAPHRAG_INDEX_TYPES = ["ktem.index.file.graph.GraphRAGIndex"]
324+
GRAPHRAG_INDEX_TYPES = []
306325

326+
if USE_MS_GRAPHRAG:
327+
GRAPHRAG_INDEX_TYPES.append("ktem.index.file.graph.GraphRAGIndex")
307328
if USE_NANO_GRAPHRAG:
308329
GRAPHRAG_INDEX_TYPES.append("ktem.index.file.graph.NanoGraphRAGIndex")
309330
if USE_LIGHTRAG:
@@ -323,7 +344,7 @@
323344
".png, .jpeg, .jpg, .tiff, .tif, .pdf, .xls, .xlsx, .doc, .docx, "
324345
".pptx, .csv, .html, .mhtml, .txt, .md, .zip"
325346
),
326-
"private": False,
347+
"private": True,
327348
},
328349
"index_type": graph_type,
329350
}
@@ -338,7 +359,7 @@
338359
".png, .jpeg, .jpg, .tiff, .tif, .pdf, .xls, .xlsx, .doc, .docx, "
339360
".pptx, .csv, .html, .mhtml, .txt, .md, .zip"
340361
),
341-
"private": False,
362+
"private": True,
342363
},
343364
"index_type": "ktem.index.file.FileIndex",
344365
},

fly.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# fly.toml app configuration file generated for kotaemon on 2024-12-24T20:56:32+07:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'kotaemon'
7+
primary_region = 'sin'
8+
9+
[build]
10+
11+
[mounts]
12+
destination = "/app/ktem_app_data"
13+
source = "ktem_volume"
14+
15+
[http_service]
16+
internal_port = 7860
17+
force_https = true
18+
auto_stop_machines = 'suspend'
19+
auto_start_machines = true
20+
min_machines_running = 0
21+
processes = ['app']
22+
23+
[[vm]]
24+
memory = '4gb'
25+
cpu_kind = 'shared'
26+
cpus = 4

launch.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
if [ -z "$GRADIO_SERVER_NAME" ]; then
4+
export GRADIO_SERVER_NAME="0.0.0.0"
5+
fi
6+
if [ -z "$GRADIO_SERVER_PORT" ]; then
7+
export GRADIO_SERVER_PORT="7860"
8+
fi
9+
10+
# Check if environment variable KH_DEMO_MODE is set to true
11+
if [ "$KH_DEMO_MODE" = "true" ]; then
12+
echo "KH_DEMO_MODE is true. Launching in demo mode..."
13+
# Command to launch in demo mode
14+
GR_FILE_ROOT_PATH="/app" KH_FEATURE_USER_MANAGEMENT=false USE_LIGHTRAG=false uvicorn sso_app_demo:app --host "$GRADIO_SERVER_NAME" --port "$GRADIO_SERVER_PORT"
15+
else
16+
if [ "$KH_SSO_ENABLED" = "true" ]; then
17+
echo "KH_SSO_ENABLED is true. Launching in SSO mode..."
18+
GR_FILE_ROOT_PATH="/app" KH_SSO_ENABLED=true uvicorn sso_app:app --host "$GRADIO_SERVER_NAME" --port "$GRADIO_SERVER_PORT"
19+
else
20+
ollama serve &
21+
python app.py
22+
fi
23+
fi

0 commit comments

Comments
 (0)