Home

Awesome

Demo

<img width="850" alt="Snipaste_2024-08-03_18-32-02" src="https://github.com/user-attachments/assets/d9ccb0ef-1409-43e4-94a1-80aed2fd33d6"> <img width="850" alt="image" src="https://github.com/swuecho/chat/assets/666683/e41742c8-2a44-43bc-8fd6-4b66db783967"> <img width="850" alt="image" src="https://github.com/swuecho/chat/assets/666683/45dd865e-7f9f-4209-8587-4781e37dd928"> <img width="850" alt="image" src="https://github.com/swuecho/chat/assets/666683/0c4f546a-e884-4dc1-91c0-d4b07e63a1a9.png">

规则

参与开发

  1. git clone
  2. golang dev
cd chat; cd api
go install github.com/cosmtrek/air@latest
go mod tidy
# export env var, change base on your env
export PG_HOST=192.168.0.135
export PG_DB=hwu
export PG_USER=hwu
export PG_PASS=pass
export PG_PORT=5432
# export DATABASE_URL= postgres://user:pass@192.168.0.1:5432/db?sslmode=disable

# export OPENAI_API_KEY=sk-xxx, not required if you use `debug` model
# export OPENAI_RATELIMIT=100
#
make serve
  1. node env
cd ..; cd web
npm install
npm run dev
  1. e2e test
cd ..; cd e2e
# export env var, change base on your env
export PG_HOST=192.168.0.135
export PG_DB=hwu
export PG_USER=hwu
export PG_PASS=pass
export PG_PORT=5432
npm install
npx playwright test # --ui 

The instruction might not be accurate, ask in issue or discussion if unclear.

如何部署

参考 docker-compose.yaml

Deploy on Railway

然后配置环境变量就可以了.

PORT=8080
OPENAI_RATELIMIT=0

别的两个 api key 有就填.

<img width="750" alt="image" src="https://user-images.githubusercontent.com/666683/232234418-941c9336-783c-4430-857c-9e7b703bb1c1.png">

部署之后, 注册用户, 第一个用户是管理员, 然后到 https://$hostname/static/#/admin/user, 设置 ratelimit, 公网部署, 只对信任的email 增加 ratelimit, 这样即使有人注册, 也是不能用的.

<img width="750" alt="image" src="https://user-images.githubusercontent.com/666683/232227529-284289a8-1336-49dd-b5c6-8e8226b9e862.png">

使用本地Ollama 模型

  1. 安装ollama 并下载模型
curl -fsSL https://ollama.com/install.sh | sh
ollama pull mistral

linux 下,默认的systemd 的配置限制了本机访问, 需要改HOST 能远程访问,如果ollama 和chat 在同一个host, 则不存在这个问题

image

  1. 在 Chat Admin 页面配置模型 image
id: ollama-{modelName}  # modelName 与 pull的 ollama 模型 一致, 比如 mistral, ollama3, ollama2
name: does not matter, naming as you like, 
baseUrl: http://hostname:11434/api/chat
other fields is irrelevant.

id 和 baseUrl 这两个地方配置对即可。

enjoy!

致谢

LICENCE: MIT

How to Use

How to Deploy

Refer to docker-compose.yaml

Deploy on Railway

Then configure the environment variables.

PORT=8080
OPENAI_RATELIMIT=0

Fill in the other two keys if you have them.

<img width="750" alt="image" src="https://user-images.githubusercontent.com/666683/232234418-941c9336-783c-4430-857c-9e7b703bb1c1.png">

After deployment, registering users, the first user is an administrator, then go to https://$hostname/static/#/admin/user to set rate limiting. Public deployment, only adds rate limiting to trusted emails, so even if someone registers, it will not be available.

<img width="750" alt="image" src="https://user-images.githubusercontent.com/666683/232227529-284289a8-1336-49dd-b5c6-8e8226b9e862.png">

This helps ensure only authorized users can access the deployed system by limiting registration to trusted emails and enabling rate limiting controls.

  1. download ollama and pull mistral model.
curl -fsSL https://ollama.com/install.sh | sh
ollama pull mistral

image

  1. config ollama model in chat admin
<img width="1293" alt="image" src="https://github.com/swuecho/chat/assets/666683/65cfca8a-edbf-4fa2-844c-c3b536b32cd0">
id: ollama-{modelName}
name: does not matter, naming as you like
baseUrl: http://hostname:11434/api/chat
other fields is irrelevant.

enjoy!

Dev locally

  1. git clone
  2. golang dev
cd chat; cd api
go install github.com/cosmtrek/air@latest
go mod tidy
# export env var, change base on your env
export PG_HOST=192.168.0.135
export PG_DB=hwu
export PG_USER=hwu
export PG_PASS=pass
export PG_PORT=5432
# export DATABASE_URL= postgres://user:pass@192.168.0.1:5432/db?sslmode=disable

# export OPENAI_API_KEY=sk-xxx, not required if you use `debug` model
# export OPENAI_RATELIMIT=100
#
make serve
  1. node env
cd ..; cd web
npm install
npm run dev
  1. e2e test
cd ..; cd e2e
# export env var, change base on your env
export PG_HOST=192.168.0.135
export PG_DB=hwu
export PG_USER=hwu
export PG_PASS=pass
export PG_PORT=5432
npm install
npx playwright test # --ui 

The instruction might not be accurate, ask in issue or discussion if unclear.

Acknowledgments