Skip to content

Commit

Permalink
Merge branch 'josStorer:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaiat authored Apr 16, 2024
2 parents 787d191 + 5deb115 commit 6422273
Show file tree
Hide file tree
Showing 66 changed files with 5,416 additions and 1,175 deletions.
171 changes: 171 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Publish Docker Image
on: [push]

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
docker_build:
name: Build ${{ matrix.arch }} Image
runs-on: ubuntu-latest

strategy:
matrix:
include:
- arch: amd64
name: amd64
# - arch: arm64
# name: arm64

steps:
- name: Free up disk spaces
run: |
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /opt/ghc || true
sudo rm -rf "/usr/local/share/boost" || true
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
- name: Get lowercase string for the repository name
id: lowercase-repo-name
uses: ASzc/change-string-case-action@v2
with:
string: ${{ github.event.repository.name }}

- name: Checkout base
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ github.ref }}-${{ matrix.arch }}
restore-keys: |
${{ github.ref }}-${{ matrix.arch }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: linux/${{ matrix.arch }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get commit SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Build and export
id: build
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v3
with:
push: true
platforms: linux/${{ matrix.arch }}
tags: ${{ secrets.DOCKER_USERNAME }}/${{ steps.lowercase-repo-name.outputs.lowercase }}:${{ matrix.name }}-latest
build-args: |
SHA=${{ steps.vars.outputs.sha_short }}
outputs: type=image,push=true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v1
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

- name: Build release and export
id: build_rel
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v3
with:
push: true
platforms: linux/${{ matrix.arch }}
tags: ${{ secrets.DOCKER_USERNAME }}/${{ steps.lowercase-repo-name.outputs.lowercase }}:${{ matrix.name }}-${{steps.version.outputs.result}}
build-args: |
SHA=${{ steps.version.outputs.result }}
outputs: type=image,push=true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Save digest
if: github.ref == 'refs/heads/master'
run: echo ${{ steps.build.outputs.digest }} > /tmp/digest.txt

- name: Save release digest
if: startsWith(github.ref, 'refs/tags/')
run: echo ${{ steps.build_rel.outputs.digest }} > /tmp/digest.txt

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: digest_${{ matrix.name }}
path: /tmp/digest.txt

manifests:
name: Build manifests
needs: [docker_build]
runs-on: ubuntu-latest
steps:
- name: Get lowercase string for the repository name
id: lowercase-repo-name
uses: ASzc/change-string-case-action@v2
with:
string: ${{ github.event.repository.name }}

- name: Checkout base
uses: actions/checkout@v2
with:
fetch-depth: 0

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Download artifact
uses: actions/download-artifact@v3
with:
path: /tmp/images/

- name: Docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Replace tag without `v`
if: startsWith(github.ref, 'refs/tags/')
uses: actions/github-script@v1
id: version
with:
script: |
return context.payload.ref.replace(/\/?refs\/tags\/v/, '')
result-encoding: string

- name: Merge and push manifest on master branch
if: github.ref == 'refs/heads/master'
run: python scripts/merge_manifest.py "${{ secrets.DOCKER_USERNAME }}/${{ steps.lowercase-repo-name.outputs.lowercase }}"

- name: Merge and push manifest on release
if: startsWith(github.ref, 'refs/tags/')
run: python scripts/merge_manifest.py "${{ secrets.DOCKER_USERNAME }}/${{ steps.lowercase-repo-name.outputs.lowercase }}" ${{steps.version.outputs.result}}
13 changes: 1 addition & 12 deletions CURRENT_CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
## Changes

### Features

- allow setting tokenChunkSize of WebGPU mode
- expose global_penalty

### Improvements

- improve parameters controllable range

### Chores

- update defaultModelConfigs
- bump webgpu mode (https://github.com/Ai00-X/ai00_server) (#321)

## Install

Expand Down
55 changes: 55 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM node:21-slim AS frontend

RUN echo "registry=https://registry.npmmirror.com/" > ~/.npmrc

WORKDIR /app

COPY manifest.json manifest.json
COPY frontend frontend

WORKDIR /app/frontend

RUN npm ci
RUN npm run build

FROM nvidia/cuda:11.6.1-devel-ubuntu20.04 AS runtime

ENV DEBIAN_FRONTEND=noninteractive

RUN apt update && \
apt install -yq git curl wget build-essential ninja-build aria2 jq software-properties-common

RUN add-apt-repository -y ppa:deadsnakes/ppa && \
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt install -y g++-11 python3.10 python3.10-distutils python3.10-dev && \
curl -sS http://mirrors.aliyun.com/pypi/get-pip.py | python3.10

RUN python3.10 -m pip install cmake

FROM runtime AS librwkv

WORKDIR /app

RUN git clone https://github.com/RWKV/rwkv.cpp.git && \
cd rwkv.cpp && \
git submodule update --init --recursive && \
mkdir -p build && \
cd build && \
cmake -G Ninja .. && \
cmake --build .

FROM runtime AS final

WORKDIR /app

COPY ./backend-python/requirements.txt ./backend-python/requirements.txt

RUN python3.10 -m pip install --quiet -r ./backend-python/requirements.txt

COPY . .
COPY --from=frontend /app/frontend/dist /app/frontend/dist
COPY --from=librwkv /app/rwkv.cpp/build/librwkv.so /app/backend-python/rwkv_pip/cpp/librwkv.so

EXPOSE 27777

CMD ["python3.10", "./backend-python/main.py", "--port", "27777", "--host", "0.0.0.0", "--webui"]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ English | [简体中文](README_ZH.md) | [日本語](README_JA.md)
- Built-in model conversion tool.
- Built-in download management and remote model inspection.
- Built-in one-click LoRA Finetune. (Windows Only)
- Can also be used as an OpenAI ChatGPT and GPT-Playground client. (Fill in the API URL and API Key in Settings page)
- Can also be used as an OpenAI ChatGPT, GPT-Playground, Ollama and more clients. (Fill in the API URL and API Key in
Settings page)
- Multilingual localization.
- Theme switching.
- Automatic updates.
Expand Down
4 changes: 2 additions & 2 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
- 内蔵モデル変換ツール
- ダウンロード管理とリモートモデル検査機能内蔵
- 内蔵のLoRA微調整機能を搭載しています (Windowsのみ)
- このプログラムは、OpenAI ChatGPTとGPT Playgroundのクライアントとしても使用できます(設定ページで `API URL``API Key`
を入力してください)
- このプログラムは、OpenAI ChatGPT、GPT Playground、Ollama などのクライアントとしても使用できます(設定ページで `API URL`
`API Key` を入力してください)
- 多言語ローカライズ
- テーマ切り替え
- 自動アップデート
Expand Down
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ API兼容的接口,这意味着一切ChatGPT客户端都是RWKV客户端。
- 内置模型转换工具
- 内置下载管理和远程模型检视
- 内置一键LoRA微调 (仅限Windows)
- 也可用作 OpenAI ChatGPTGPT Playground 客户端 (在设置内填写API URL和API Key)
- 也可用作 OpenAI ChatGPT, GPT Playground, Ollama 等服务的客户端 (在设置内填写API URL和API Key)
- 多语言本地化
- 主题切换
- 自动更新
Expand Down
67 changes: 67 additions & 0 deletions backend-golang/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
"context"
"errors"
"io"
"log"
"net"
"net/http"
"net/http/httputil"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand All @@ -27,6 +31,7 @@ type App struct {
HasConfigData bool
ConfigData map[string]any
Dev bool
proxyPort int
exDir string
cmdPrefix string
}
Expand All @@ -36,6 +41,63 @@ func NewApp() *App {
return &App{}
}

func (a *App) newFetchProxy() {
go func() {
handler := func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "*")
w.Header().Set("Access-Control-Allow-Origin", "*")
return
}
proxy := &httputil.ReverseProxy{
ModifyResponse: func(res *http.Response) error {
res.Header.Set("Access-Control-Allow-Origin", "*")
return nil
},
Director: func(req *http.Request) {
realTarget := req.Header.Get("Real-Target")
if realTarget != "" {
realTarget, err := url.PathUnescape(realTarget)
if err != nil {
log.Printf("Error decoding target URL: %v\n", err)
return
}
target, err := url.Parse(realTarget)
if err != nil {
log.Printf("Error parsing target URL: %v\n", err)
return
}
req.Header.Set("Accept", "*/*")
req.Header.Del("Origin")
req.Header.Del("Referer")
req.Header.Del("Real-Target")
req.Header.Del("Sec-Fetch-Dest")
req.Header.Del("Sec-Fetch-Mode")
req.Header.Del("Sec-Fetch-Site")
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
req.URL.Path = target.Path
req.URL.RawQuery = url.PathEscape(target.RawQuery)
log.Println("Proxying to", realTarget)
} else {
log.Println("Real-Target header is missing")
}
},
}
proxy.ServeHTTP(w, r)
}
http.HandleFunc("/", handler)
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
return
}
a.proxyPort = listener.Addr().(*net.TCPAddr).Port

http.Serve(listener, nil)
}()
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) OnStartup(ctx context.Context) {
Expand Down Expand Up @@ -76,6 +138,7 @@ func (a *App) OnStartup(ctx context.Context) {
a.midiLoop()
a.watchFs()
a.monitorHardware()
a.newFetchProxy()
}

func (a *App) OnBeforeClose(ctx context.Context) bool {
Expand Down Expand Up @@ -239,3 +302,7 @@ func (a *App) RestartApp() error {
func (a *App) GetPlatform() string {
return runtime.GOOS
}

func (a *App) GetProxyPort() int {
return a.proxyPort
}
Loading

0 comments on commit 6422273

Please sign in to comment.