Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sso login, demo mode & new mindmap support #644

Merged
merged 62 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
b2767f9
fix: update .env.example
taprosoft Dec 24, 2024
0603a92
feat: add SSO login
taprosoft Dec 23, 2024
d6abb02
fix: update flowsetting
taprosoft Dec 23, 2024
2d4c847
fix: add requirement
taprosoft Dec 23, 2024
7ad3209
fix: refine UI
taprosoft Dec 24, 2024
a1dbc4e
fix: update group id-based operation
taprosoft Dec 24, 2024
de3cb6c
fix: improve citation logics
taprosoft Dec 24, 2024
9d9f083
fix: UI enhancement
taprosoft Dec 24, 2024
2215843
fix: user_id to string in models
taprosoft Dec 24, 2024
45a0afd
fix: improve chat suggestion UI and flow
taprosoft Dec 24, 2024
ae6144b
fix: improve group id handling
taprosoft Dec 24, 2024
b7f8931
fix: improve chat suggestion
taprosoft Dec 24, 2024
e075b08
fix: secure download for single file
taprosoft Dec 24, 2024
698b3dc
fix: file limiting in docstore
taprosoft Dec 25, 2024
aed2a08
fix: improve chat suggestion logics & language conform
taprosoft Dec 25, 2024
f0279eb
feat: add markmap and select text to highlight function
taprosoft Dec 30, 2024
6da40bc
fix: update Dockerfile
taprosoft Dec 30, 2024
d2c7f5d
fix: user id auto generate
taprosoft Dec 30, 2024
788fdbc
fix: default user id
taprosoft Dec 30, 2024
b575a9f
feat: add demo mode
taprosoft Dec 31, 2024
93ee71f
fix: update flowsetting
taprosoft Dec 31, 2024
a2a5b67
fix: revise default params for demo
taprosoft Dec 31, 2024
5ed2b78
feat: sso_app alternative
taprosoft Dec 31, 2024
fe42443
feat: sso login demo
taprosoft Dec 31, 2024
45f6b3a
feat: demo specific customization
taprosoft Dec 31, 2024
a002fde
feat: add login using API key
taprosoft Jan 2, 2025
ef9c219
fix: disable key-based login
taprosoft Jan 2, 2025
6ba6fba
fix: optimize duplicate upload
taprosoft Jan 2, 2025
4dfacc6
fix: gradio routing
taprosoft Jan 2, 2025
426d1ac
fix: disable arm build for demo
taprosoft Jan 2, 2025
563566f
fix: revise full-text search js logic
taprosoft Jan 2, 2025
f118e21
feat: add rate limit
taprosoft Jan 3, 2025
21e1ef9
fix: update Dockerfile with new launch script
taprosoft Jan 3, 2025
285e27d
fix: update Dockerfile
taprosoft Jan 3, 2025
e422964
fix: update Dockerignore
taprosoft Jan 3, 2025
5b8671b
fix: update ratelimit logic
taprosoft Jan 3, 2025
7a86d2b
fix: user_id in user management page
taprosoft Jan 3, 2025
ea37f0b
fix: rename conv logic
taprosoft Jan 3, 2025
d8dff11
feat: update demo hint
taprosoft Jan 3, 2025
8784c68
fix: minor fix
taprosoft Jan 3, 2025
33a45f1
fix: highlight on long PDF load
taprosoft Jan 4, 2025
0c44e05
feat: add HF paper list
taprosoft Jan 5, 2025
4f6aed2
fix: update HF papers load logic
taprosoft Jan 5, 2025
86dd5e5
feat: fly config
taprosoft Jan 6, 2025
8de8f8b
fix: update fly config
taprosoft Jan 6, 2025
f0ec683
fix: update paper list pull api
taprosoft Jan 7, 2025
5298bf0
fix: minor update root routing
taprosoft Jan 8, 2025
8cf65e4
fix: minor update root routing
taprosoft Jan 8, 2025
da5bdae
fix: simplify login flow & paper list UI
taprosoft Jan 16, 2025
9ee2f7d
feat: add paper recommendation
taprosoft Jan 17, 2025
c468bab
fix: update Dockerfile
taprosoft Jan 20, 2025
95aba5c
fix: update Dockerfile
taprosoft Jan 20, 2025
bff35d0
fix: update default model
taprosoft Jan 21, 2025
24bcf45
feat: add long context Ollama through LCOllama
taprosoft Jan 21, 2025
1faa94b
feat: espose Gradio share to env
taprosoft Jan 21, 2025
e681d13
fix: revert customized changes
taprosoft Jan 27, 2025
906c6fc
fix: list group at app load
taprosoft Feb 1, 2025
9a3c064
fix: relocate share conv button
taprosoft Feb 1, 2025
af6399b
fix: update launch script
taprosoft Feb 2, 2025
f7b0a22
fix: update Docker CI
taprosoft Feb 2, 2025
2246c00
feat: add Ollama model selection at first setup
taprosoft Feb 2, 2025
5f8aa37
docs: update README
taprosoft Feb 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ env/
README.md
*.zip
*.sh

!/launch.sh
8 changes: 3 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# settings for OpenAI
OPENAI_API_BASE=https://api.openai.com/v1
OPENAI_API_KEY=<YOUR_OPENAI_KEY>
OPENAI_CHAT_MODEL=gpt-3.5-turbo
OPENAI_EMBEDDINGS_MODEL=text-embedding-ada-002
OPENAI_CHAT_MODEL=gpt-4o-mini
OPENAI_EMBEDDINGS_MODEL=text-embedding-3-large

# settings for Azure OpenAI
AZURE_OPENAI_ENDPOINT=
Expand All @@ -17,10 +17,8 @@ AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT=text-embedding-ada-002
COHERE_API_KEY=<COHERE_API_KEY>

# settings for local models
LOCAL_MODEL=llama3.1:8b
LOCAL_MODEL=qwen2.5:7b
LOCAL_MODEL_EMBEDDINGS=nomic-embed-text
LOCAL_EMBEDDING_MODEL_DIM = 768
LOCAL_EMBEDDING_MODEL_MAX_TOKENS = 8192

# settings for GraphRAG
GRAPHRAG_API_KEY=<YOUR_OPENAI_KEY>
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-push-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
target:
- lite
- full
- ollama
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ repos:
"types-requests",
"sqlmodel",
"types-Markdown",
"types-cachetools",
types-tzlocal,
]
args: ["--check-untyped-defs", "--ignore-missing-imports"]
Expand Down
19 changes: 15 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ RUN bash scripts/download_pdfjs.sh $PDFJS_PREBUILT_DIR

# Copy contents
COPY . /app
COPY launch.sh /app/launch.sh
COPY .env.example /app/.env

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

CMD ["python", "app.py"]
ENTRYPOINT ["sh", "/app/launch.sh"]

# Full version
FROM lite AS full
Expand Down Expand Up @@ -97,7 +98,17 @@ RUN apt-get autoremove \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf ~/.cache

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

CMD ["python", "app.py"]
# Ollama-bundled version
FROM full AS ollama

# Install ollama
RUN --mount=type=ssh \
--mount=type=cache,target=/root/.cache/pip \
curl -fsSL https://ollama.com/install.sh | sh

# RUN nohup bash -c "ollama serve &" && sleep 4 && ollama pull qwen2.5:7b
RUN nohup bash -c "ollama serve &" && sleep 4 && ollama pull nomic-embed-text

ENTRYPOINT ["sh", "/app/launch.sh"]
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,7 @@ documents and developers who want to build their own RAG pipeline.

### With Docker (recommended)

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.

- To use the `lite` version.

```bash
docker run \
-e GRADIO_SERVER_NAME=0.0.0.0 \
-e GRADIO_SERVER_PORT=7860 \
-v ./ktem_app_data:/app/ktem_app_data \
-p 7860:7860 -it --rm \
ghcr.io/cinnamon/kotaemon:main-lite
```
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.

- To use the `full` version.

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

```bash
# change image name to
ghcr.io/cinnamon/kotaemon:feat-ollama_docker-full
docker run <...> ghcr.io/cinnamon/kotaemon:main-ollama
```

- To use the `lite` version.

```bash
# change image name to
docker run <...> ghcr.io/cinnamon/kotaemon:main-lite
```

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:

```bash
Expand Down
2 changes: 2 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from theflow.settings import settings as flowsettings

KH_APP_DATA_DIR = getattr(flowsettings, "KH_APP_DATA_DIR", ".")
KH_GRADIO_SHARE = getattr(flowsettings, "KH_GRADIO_SHARE", False)
GRADIO_TEMP_DIR = os.getenv("GRADIO_TEMP_DIR", None)
# override GRADIO_TEMP_DIR if it's not set
if GRADIO_TEMP_DIR is None:
Expand All @@ -21,4 +22,5 @@
"libs/ktem/ktem/assets",
GRADIO_TEMP_DIR,
],
share=KH_GRADIO_SHARE,
)
4 changes: 2 additions & 2 deletions docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ An open-source tool for chatting with your documents. Built with both end users
developers in mind.

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

[User Guide](https://cinnamon.github.io/kotaemon/) |
[Installation Guide](https://cinnamon.github.io/kotaemon/) |
[Developer Guide](https://cinnamon.github.io/kotaemon/development/) |
[Feedback](https://github.com/Cinnamon/kotaemon/issues)
2 changes: 1 addition & 1 deletion docs/online_install.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Installation (Online HuggingFace Space)

1. Go to [HF kotaemon_template](https://huggingface.co/spaces/cin-model/kotaemon_template).
2. Use Duplicate function to create your own space.
2. Use Duplicate function to create your own space. Or use this [direct link](https://huggingface.co/spaces/cin-model/kotaemon_template?duplicate=true).
![Duplicate space](https://raw.githubusercontent.com/Cinnamon/kotaemon/main/docs/images/duplicate_space.png)
![Change space params](https://raw.githubusercontent.com/Cinnamon/kotaemon/main/docs/images/change_space_params.png)
3. Wait for the build to complete and start up (apprx 10 mins).
Expand Down
55 changes: 38 additions & 17 deletions flowsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
except Exception:
KH_APP_VERSION = "local"

KH_ENABLE_FIRST_SETUP = True
KH_GRADIO_SHARE = config("KH_GRADIO_SHARE", default=False, cast=bool)
KH_ENABLE_FIRST_SETUP = config("KH_ENABLE_FIRST_SETUP", default=True, cast=bool)
KH_DEMO_MODE = config("KH_DEMO_MODE", default=False, cast=bool)
KH_OLLAMA_URL = config("KH_OLLAMA_URL", default="http://localhost:11434/v1/")

Expand Down Expand Up @@ -65,6 +66,8 @@
KH_DOC_DIR = this_dir / "docs"

KH_MODE = "dev"
KH_SSO_ENABLED = config("KH_SSO_ENABLED", default=False, cast=bool)

KH_FEATURE_CHAT_SUGGESTION = config(
"KH_FEATURE_CHAT_SUGGESTION", default=False, cast=bool
)
Expand Down Expand Up @@ -137,43 +140,58 @@
"default": False,
}

if config("OPENAI_API_KEY", default=""):
OPENAI_DEFAULT = "<YOUR_OPENAI_KEY>"
OPENAI_API_KEY = config("OPENAI_API_KEY", default=OPENAI_DEFAULT)
GOOGLE_API_KEY = config("GOOGLE_API_KEY", default="your-key")
IS_OPENAI_DEFAULT = len(OPENAI_API_KEY) > 0 and OPENAI_API_KEY != OPENAI_DEFAULT

if OPENAI_API_KEY:
KH_LLMS["openai"] = {
"spec": {
"__type__": "kotaemon.llms.ChatOpenAI",
"temperature": 0,
"base_url": config("OPENAI_API_BASE", default="")
or "https://api.openai.com/v1",
"api_key": config("OPENAI_API_KEY", default=""),
"model": config("OPENAI_CHAT_MODEL", default="gpt-3.5-turbo"),
"api_key": OPENAI_API_KEY,
"model": config("OPENAI_CHAT_MODEL", default="gpt-4o-mini"),
"timeout": 20,
},
"default": True,
"default": IS_OPENAI_DEFAULT,
}
KH_EMBEDDINGS["openai"] = {
"spec": {
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
"base_url": config("OPENAI_API_BASE", default="https://api.openai.com/v1"),
"api_key": config("OPENAI_API_KEY", default=""),
"api_key": OPENAI_API_KEY,
"model": config(
"OPENAI_EMBEDDINGS_MODEL", default="text-embedding-ada-002"
"OPENAI_EMBEDDINGS_MODEL", default="text-embedding-3-large"
),
"timeout": 10,
"context_length": 8191,
},
"default": True,
"default": IS_OPENAI_DEFAULT,
}

if config("LOCAL_MODEL", default=""):
KH_LLMS["ollama"] = {
"spec": {
"__type__": "kotaemon.llms.ChatOpenAI",
"base_url": KH_OLLAMA_URL,
"model": config("LOCAL_MODEL", default="llama3.1:8b"),
"model": config("LOCAL_MODEL", default="qwen2.5:7b"),
"api_key": "ollama",
},
"default": False,
}
KH_LLMS["ollama-long-context"] = {
"spec": {
"__type__": "kotaemon.llms.LCOllamaChat",
"base_url": KH_OLLAMA_URL.replace("v1/", ""),
"model": config("LOCAL_MODEL", default="qwen2.5:7b"),
"num_ctx": 8192,
},
"default": False,
}

KH_EMBEDDINGS["ollama"] = {
"spec": {
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
Expand All @@ -183,7 +201,6 @@
},
"default": False,
}

KH_EMBEDDINGS["fast_embed"] = {
"spec": {
"__type__": "kotaemon.embeddings.FastEmbedEmbeddings",
Expand All @@ -205,9 +222,9 @@
"spec": {
"__type__": "kotaemon.llms.chats.LCGeminiChat",
"model_name": "gemini-1.5-flash",
"api_key": config("GOOGLE_API_KEY", default="your-key"),
"api_key": GOOGLE_API_KEY,
},
"default": False,
"default": not IS_OPENAI_DEFAULT,
}
KH_LLMS["groq"] = {
"spec": {
Expand Down Expand Up @@ -241,8 +258,9 @@
"spec": {
"__type__": "kotaemon.embeddings.LCGoogleEmbeddings",
"model": "models/text-embedding-004",
"google_api_key": config("GOOGLE_API_KEY", default="your-key"),
}
"google_api_key": GOOGLE_API_KEY,
},
"default": not IS_OPENAI_DEFAULT,
}
# KH_EMBEDDINGS["huggingface"] = {
# "spec": {
Expand Down Expand Up @@ -301,9 +319,12 @@

USE_NANO_GRAPHRAG = config("USE_NANO_GRAPHRAG", default=False, cast=bool)
USE_LIGHTRAG = config("USE_LIGHTRAG", default=True, cast=bool)
USE_MS_GRAPHRAG = config("USE_MS_GRAPHRAG", default=True, cast=bool)

GRAPHRAG_INDEX_TYPES = ["ktem.index.file.graph.GraphRAGIndex"]
GRAPHRAG_INDEX_TYPES = []

if USE_MS_GRAPHRAG:
GRAPHRAG_INDEX_TYPES.append("ktem.index.file.graph.GraphRAGIndex")
if USE_NANO_GRAPHRAG:
GRAPHRAG_INDEX_TYPES.append("ktem.index.file.graph.NanoGraphRAGIndex")
if USE_LIGHTRAG:
Expand All @@ -323,7 +344,7 @@
".png, .jpeg, .jpg, .tiff, .tif, .pdf, .xls, .xlsx, .doc, .docx, "
".pptx, .csv, .html, .mhtml, .txt, .md, .zip"
),
"private": False,
"private": True,
},
"index_type": graph_type,
}
Expand All @@ -338,7 +359,7 @@
".png, .jpeg, .jpg, .tiff, .tif, .pdf, .xls, .xlsx, .doc, .docx, "
".pptx, .csv, .html, .mhtml, .txt, .md, .zip"
),
"private": False,
"private": True,
},
"index_type": "ktem.index.file.FileIndex",
},
Expand Down
26 changes: 26 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# fly.toml app configuration file generated for kotaemon on 2024-12-24T20:56:32+07:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'kotaemon'
primary_region = 'sin'

[build]

[mounts]
destination = "/app/ktem_app_data"
source = "ktem_volume"

[http_service]
internal_port = 7860
force_https = true
auto_stop_machines = 'suspend'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '4gb'
cpu_kind = 'shared'
cpus = 4
23 changes: 23 additions & 0 deletions launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

if [ -z "$GRADIO_SERVER_NAME" ]; then
export GRADIO_SERVER_NAME="0.0.0.0"
fi
if [ -z "$GRADIO_SERVER_PORT" ]; then
export GRADIO_SERVER_PORT="7860"
fi

# Check if environment variable KH_DEMO_MODE is set to true
if [ "$KH_DEMO_MODE" = "true" ]; then
echo "KH_DEMO_MODE is true. Launching in demo mode..."
# Command to launch in demo mode
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"
else
if [ "$KH_SSO_ENABLED" = "true" ]; then
echo "KH_SSO_ENABLED is true. Launching in SSO mode..."
GR_FILE_ROOT_PATH="/app" KH_SSO_ENABLED=true uvicorn sso_app:app --host "$GRADIO_SERVER_NAME" --port "$GRADIO_SERVER_PORT"
else
ollama serve &
python app.py
fi
fi
Loading