Skip to content

Commit f42fbce

Browse files
authored
Initial commit
0 parents  commit f42fbce

20 files changed

Lines changed: 7765 additions & 0 deletions

.env.example

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# PowerAgent minimal configuration for PowerMem + SeekDB (OceanBase-compatible)
2+
# Copy this file to .env and fill in your provider credentials.
3+
4+
# Database (SeekDB via OceanBase-compatible protocol)
5+
DATABASE_PROVIDER=oceanbase
6+
OCEANBASE_HOST=127.0.0.1
7+
OCEANBASE_PORT=2881
8+
OCEANBASE_USER=root
9+
OCEANBASE_PASSWORD=
10+
OCEANBASE_DATABASE=powermem
11+
OCEANBASE_COLLECTION=memories
12+
OCEANBASE_EMBEDDING_MODEL_DIMS=1536
13+
14+
# LLM
15+
LLM_PROVIDER=qwen
16+
LLM_API_KEY=your_api_key_here
17+
LLM_MODEL=qwen-plus
18+
19+
# Embeddings
20+
EMBEDDING_PROVIDER=qwen
21+
EMBEDDING_API_KEY=your_api_key_here
22+
EMBEDDING_MODEL=text-embedding-v4
23+
EMBEDDING_DIMS=1536

.gitattributes

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
*.7z filter=lfs diff=lfs merge=lfs -text
2+
*.arrow filter=lfs diff=lfs merge=lfs -text
3+
*.bin filter=lfs diff=lfs merge=lfs -text
4+
*.bin.* filter=lfs diff=lfs merge=lfs -text
5+
*.bz2 filter=lfs diff=lfs merge=lfs -text
6+
*.ftz filter=lfs diff=lfs merge=lfs -text
7+
*.gz filter=lfs diff=lfs merge=lfs -text
8+
*.h5 filter=lfs diff=lfs merge=lfs -text
9+
*.joblib filter=lfs diff=lfs merge=lfs -text
10+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
11+
*.model filter=lfs diff=lfs merge=lfs -text
12+
*.msgpack filter=lfs diff=lfs merge=lfs -text
13+
*.onnx filter=lfs diff=lfs merge=lfs -text
14+
*.ot filter=lfs diff=lfs merge=lfs -text
15+
*.parquet filter=lfs diff=lfs merge=lfs -text
16+
*.pb filter=lfs diff=lfs merge=lfs -text
17+
*.pt filter=lfs diff=lfs merge=lfs -text
18+
*.pth filter=lfs diff=lfs merge=lfs -text
19+
*.rar filter=lfs diff=lfs merge=lfs -text
20+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
21+
*.tar.* filter=lfs diff=lfs merge=lfs -text
22+
*.tflite filter=lfs diff=lfs merge=lfs -text
23+
*.tgz filter=lfs diff=lfs merge=lfs -text
24+
*.xz filter=lfs diff=lfs merge=lfs -text
25+
*.zip filter=lfs diff=lfs merge=lfs -text
26+
*.zstandard filter=lfs diff=lfs merge=lfs -text
27+
*.tfevents* filter=lfs diff=lfs merge=lfs -text
28+
*.db* filter=lfs diff=lfs merge=lfs -text
29+
*.ark* filter=lfs diff=lfs merge=lfs -text
30+
**/*ckpt*data* filter=lfs diff=lfs merge=lfs -text
31+
**/*ckpt*.meta filter=lfs diff=lfs merge=lfs -text
32+
**/*ckpt*.index filter=lfs diff=lfs merge=lfs -text
33+
*.safetensors filter=lfs diff=lfs merge=lfs -text
34+
*.ckpt filter=lfs diff=lfs merge=lfs -text
35+
*.gguf* filter=lfs diff=lfs merge=lfs -text
36+
*.ggml filter=lfs diff=lfs merge=lfs -text
37+
*.llamafile* filter=lfs diff=lfs merge=lfs -text
38+
*.pt2 filter=lfs diff=lfs merge=lfs -text
39+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
40+
*.npy filter=lfs diff=lfs merge=lfs -text
41+
*.npz filter=lfs diff=lfs merge=lfs -text
42+
*.pickle filter=lfs diff=lfs merge=lfs -text
43+
*.pkl filter=lfs diff=lfs merge=lfs -text
44+
*.tar filter=lfs diff=lfs merge=lfs -text
45+
*.wasm filter=lfs diff=lfs merge=lfs -text
46+
*.zst filter=lfs diff=lfs merge=lfs -text
47+
*tfevents* filter=lfs diff=lfs merge=lfs -text
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Setup Python Environment"
2+
description: "Set up Python environment for the given Python version"
3+
4+
inputs:
5+
python-version:
6+
description: "Python version to use"
7+
required: true
8+
default: "3.12"
9+
uv-version:
10+
description: "uv version to use"
11+
required: true
12+
default: "0.9.18"
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
18+
with:
19+
python-version: ${{ inputs.python-version }}
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e
23+
with:
24+
version: ${{ inputs.uv-version }}
25+
enable-cache: "true"
26+
cache-suffix: ${{ inputs.python-version }}
27+
28+
- name: Install Python dependencies
29+
run: uv sync --all-groups --frozen
30+
shell: bash

.github/workflows/main.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, ready_for_review]
9+
10+
jobs:
11+
quality:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out
15+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955
16+
17+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
18+
with:
19+
path: ~/.cache/prek
20+
key: prek-${{ hashFiles('.pre-commit-config.yaml') }}
21+
22+
- name: Set up the environment
23+
uses: ./.github/actions/setup-python-env
24+
25+
- name: Run checks
26+
run: make check
27+
28+
tests:
29+
runs-on: ubuntu-latest
30+
strategy:
31+
matrix:
32+
python-version: ["3.10", "3.11", "3.12", "3.13"]
33+
fail-fast: false
34+
steps:
35+
- name: Check out
36+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955
37+
38+
- name: Set up the environment
39+
uses: ./.github/actions/setup-python-env
40+
with:
41+
python-version: ${{ matrix.python-version }}
42+
43+
- name: Run tests
44+
run: make test
45+
46+
check-docs:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Check out
50+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955
51+
52+
- name: Set up the environment
53+
uses: ./.github/actions/setup-python-env
54+
55+
- name: Check if documentation can be built
56+
run: make docs-test
57+
58+
check-links:
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Check out
62+
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955
63+
64+
- name: Link Checker
65+
uses: lycheeverse/lychee-action@1ef33e2493308e49729a7789ddd73e7f8bed8f45
66+
with:
67+
fail: false

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.env
2+
.env.local
3+
.venv/
4+
__pycache__/
5+
*.py[cod]
6+
.pytest_cache/
7+
.ruff_cache/
8+
.pdm-build/
9+
build/
10+
dist/
11+
site/

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: "v5.0.0"
4+
hooks:
5+
- id: check-case-conflict
6+
- id: check-merge-conflict
7+
- id: check-toml
8+
- id: check-yaml
9+
- id: check-json
10+
- id: pretty-format-json
11+
args: [--autofix, --no-sort-keys]
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace
14+
15+
- repo: https://github.com/astral-sh/ruff-pre-commit
16+
rev: "v0.12.7"
17+
hooks:
18+
- id: ruff-check
19+
args: [--exit-non-zero-on-fix]
20+
- id: ruff-format

Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM quay.io/oceanbase/seekdb:latest
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN if command -v yum >/dev/null 2>&1; then \
6+
yum install -y --allowerasing curl ca-certificates python3 python3-pip && \
7+
yum clean all; \
8+
else \
9+
echo "No supported package manager found." && exit 1; \
10+
fi
11+
12+
RUN python3 -m pip install --no-cache-dir -U uv
13+
14+
ENV PATH="/root/.local/bin:${PATH}"
15+
16+
WORKDIR /app
17+
18+
COPY pyproject.toml uv.lock README.md ./
19+
COPY app.py ./
20+
COPY src ./src
21+
COPY .env.example ./.env.example
22+
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
23+
24+
ARG PIP_INDEX_URL=https://pypi.org/simple
25+
ENV PIP_INDEX_URL=${PIP_INDEX_URL}
26+
ENV UV_INDEX_URL=${PIP_INDEX_URL}
27+
ENV UV_LINK_MODE=copy
28+
ENV UV_HTTP_TIMEOUT=300
29+
30+
RUN chmod +x /usr/local/bin/entrypoint.sh
31+
RUN uv sync --frozen
32+
33+
ENV GRADIO_SERVER_NAME=0.0.0.0
34+
ENV GRADIO_SERVER_PORT=7860
35+
ENV OCEANBASE_HOST=127.0.0.1
36+
ENV OCEANBASE_PORT=2881
37+
38+
EXPOSE 7860
39+
EXPOSE 2881
40+
41+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.PHONY: install
2+
install: ## Create the virtual environment and install dependencies
3+
@echo "Creating virtual environment using uv"
4+
@uv sync
5+
@uv run prek install
6+
7+
.PHONY: lock
8+
lock: ## Update uv.lock
9+
@echo "Updating uv.lock"
10+
@uv lock
11+
12+
.PHONY: export
13+
export: ## Export requirements.txt from uv.lock
14+
@echo "Exporting requirements.txt"
15+
@uv export -o requirements.txt --format requirements.txt
16+
17+
.PHONY: run
18+
run: ## Run the Gradio app
19+
@uv run python app.py
20+
21+
.PHONY: test
22+
test: ## Run tests
23+
@uv run pytest
24+
25+
.PHONY: check
26+
check: ## Run code quality checks
27+
@echo "Checking lock file consistency with 'pyproject.toml'"
28+
@uv lock --locked
29+
@echo "Running pre-commit hooks via prek"
30+
@uv run prek run -a
31+
32+
.PHONY: lint
33+
lint: ## Run ruff lint
34+
@uv run ruff check .
35+
36+
.PHONY: fmt
37+
fmt: ## Run ruff formatter
38+
@uv run ruff format .
39+
40+
.PHONY: docs-test
41+
docs-test: ## Build docs with mkdocs
42+
@uv run mkdocs build -s
43+
44+
.PHONY: docs
45+
docs: ## Serve docs locally
46+
@uv run mkdocs serve
47+
48+
.PHONY: help
49+
help:
50+
@awk -F '## ' '/^[A-Za-z_-]+:.*##/ { target = $$1; sub(/:.*/, "", target); printf "\033[36m%-20s\033[0m %s\n", target, $$2 }' $(MAKEFILE_LIST)
51+
52+
.PHONY: compose-up
53+
compose-up: ## Build and start app + seekdb with docker compose
54+
@docker compose up --build
55+
56+
.PHONY: compose-down
57+
compose-down: ## Stop docker compose
58+
@docker compose down
59+
60+
.PHONY: compose-logs
61+
compose-logs: ## Tail docker compose logs
62+
@docker compose logs -f
63+
64+
.PHONY: docker-build
65+
docker-build: ## Build a single-container image for ModelScope Docker Studio
66+
@docker build -t poweragent:latest .
67+
68+
.DEFAULT_GOAL := help

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
# Detailed docs: https://modelscope.cn/docs/studios/create
3+
domain:
4+
# domain: cv/nlp/audio/multi-modal/AutoML
5+
tags:
6+
- chatbot
7+
- memory
8+
- gradio
9+
- oceanbase
10+
datasets:
11+
evaluation:
12+
test:
13+
train:
14+
models:
15+
# - organization/model
16+
## Entry file for Gradio/Streamlit is app.py by default
17+
# deployspec:
18+
# entry_file: app.py
19+
license: Apache License 2.0
20+
---
21+
22+
# PowerAgent
23+
24+
A lightweight Gradio chat agent with long-term memory powered by PowerMem, SeekDB, and OceanBase. Built to be ModelScope-friendly while staying easy to run locally.
25+
26+
## What it is
27+
28+
- Long-term chat memory with vector search (SeekDB + OceanBase)
29+
- Simple Gradio chat UI with streaming responses
30+
- Works out of the box on ModelScope Docker Studio via the included `Dockerfile`
31+
- Supports OpenAI, Qwen, and other LLM/embedding providers
32+
33+
## Run on ModelScope Docker Studio
34+
35+
1) Keep the provided `Dockerfile` and `docker/entrypoint.sh` (they start SeekDB and the app).
36+
2) Exposed ports: `7860` (Gradio) and `2881` (SeekDB). Entry file is `app.py`.
37+
3) Set environment secrets in Studio, e.g. `LLM_PROVIDER`, `LLM_API_KEY`, `LLM_MODEL`, `EMBEDDING_PROVIDER`, `EMBEDDING_API_KEY`, `EMBEDDING_MODEL`, `EMBEDDING_DIMS`, `DATABASE_PROVIDER=oceanbase`, plus `OCEANBASE_*` if overriding defaults.
38+
4) Build and run; open the forwarded `7860` port to use the chat UI.
39+
40+
## Run locally (preferred: Docker)
41+
42+
### Docker Compose (app + SeekDB)
43+
```bash
44+
cp .env.example .env # fill in keys
45+
make compose-up # builds and starts everything
46+
```
47+
The UI is at `http://localhost:7860`. Stop with `make compose-down`.
48+
49+
### Single container
50+
```bash
51+
docker build -t poweragent:latest .
52+
docker run --rm -p 7860:7860 -p 2881:2881 poweragent:latest
53+
```
54+
55+
### Bare-metal (advanced, no containers)
56+
```bash
57+
uv sync
58+
cp .env.example .env
59+
make run
60+
```
61+
62+
## Docs
63+
64+
- `docs/index.md` contains architecture, local/Docker workflows, and configuration details.
65+
66+
## License
67+
68+
Apache License 2.0
69+
70+
## Related
71+
72+
- PowerMem: https://github.com/oceanbase/powermem
73+
- SeekDB: https://www.oceanbase.ai/product/seekdb
74+
- OceanBase: https://www.oceanbase.com/

0 commit comments

Comments
 (0)