GithubHelp home page GithubHelp logo

swuecho / chat Goto Github PK

View Code? Open in Web Editor NEW
503.0 9.0 88.0 3.18 MB

chat web app for teams, sass with user management and ratelimit, support chatgpt(openai & azure), claude, gemini and ollama model

Dockerfile 0.14% Makefile 0.10% Go 35.61% Shell 0.12% HTML 1.58% TypeScript 18.99% JavaScript 0.10% Vue 35.24% Less 5.08% CSS 0.01% Python 3.03%
chatgpt sass teams claude-ai ollama

chat's Introduction

Demo

Snipaste_2024-08-03_18-32-02 image image image

规则

  • 第一个消息是系统消息(prompt)
  • 上下文默认附带最新创建的4条消息
  • 第一个注册的用户是管理员
  • 默认限流 100 chatGPT call /10分钟 (OPENAI_RATELIMIT=100)
  • 根据对话生成可以分享的静态页面(like ShareGPT), 也可以继续会话.
  • 对话快照目录(对话集), 支持全文查找(Enlgish), 方便整理, 搜索会话记录.
  • 支持OPEN AI, Claude 模型 免费申请链接
  • 支持Ollama host模型, 配置参考: #396
  • 支持上传文本文件
  • 支持多媒体文件, 需要模型支持
  • 提示词管理, 提示词快捷键 '/'

参与开发

  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:[email protected]: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 有就填.

image

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

image

使用本地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

  • The first message is a system message (prompt)
  • by default, the latest 4 messages are context
  • First user is superuser.
  • 100 chatgpt api call / 10 mins (OPENAI_RATELIMIT=100)
  • Snapshot conversation and Share (like ShareGPT)
  • Support OPEN AI, Claude model free application link
  • Support Upload File
  • Support MultiMedia File (rely on Model support)

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.

image

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.

image

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
image
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:[email protected]: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

chat's People

Contributors

cyx2000 avatar exherb avatar guspan-tanadi avatar oldwang12 avatar swuecho avatar zhaijunxiao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chat's Issues

TODO: add user usage stat

user_email, total_session, total_message, total_sessions(3days), total_message(3days). ratelimit( 1msg/s, 10msg/s, 1000m/s).

问了一个问题一直没有响应

我问:1+1等于多少,前端页面一直没反应

web | 218.82.136.139 - - [10/Apr/2023:09:13:46 +0000] "POST /api/chat_stream HTTP/1.1" 500 61 "http://1x:8084/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-"
api | 172.18.0.4 - - [10/Apr/2023:09:13:46 +0000] "POST /chat_stream HTTP/1.1" 500 61
chat-db-1 | 2023-04-10 17:13:46.927 CST [156] FATAL: role "root" does not exist
api | 2023/04/10 09:13:50 chatSessionUuid: 1fdf2591-898a-4af6-9a62-d0be5a00fead
api | 2023/04/10 09:13:50 chatUuid: 1e5032dd-0c0c-45ea-a04f-d68c412b05f6
api | 2023/04/10 09:13:50 newQuestion: 1+1等于多少
api |
api | 172.18.0.4 - - [10/Apr/2023:09:13:50 +0000] "POST /chat_stream HTTP/1.1" 200 0
web | 218.82.136.139 - - [10/Apr/2023:09:13:50 +0000] "POST /api/chat_stream HTTP/1.1" 200 0 "http://1.x:8084/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-"
chat-db-1 | 2023-04-10 17:13:52.070 CST [165] FATAL: role "root" does not exist
chat-db-1 | 2023-04-10 17:13:57.215 CST [173] FATAL: role "root" does not exist
chat-db-1 | 2023-04-10 17:14:02.357 CST [181] FATAL: role "root" does not exist

auto gen jwt_secret and jwt_aud

      # JWT_SECRET is the key used to encrypt/decrypt the JWT token
      # !!! change this, with output of: openssl rand -base64 32
      - JWT_SECRET='RqJrJBINOsL6PVSocqVfVk8a8H9u4juq55YN6PvnlPE='
      # JWT_AUD represents the audience of the JWT token, i.e., the recipient or target
      - JWT_AUD=bc442bb2b1d848fba5be2aa24123e711

test regenerate

use default 'test_demo_bestqa' to test regenerate use correct query messages

test rate limit

test:

  1. role user, visit /admin, get error 'not auth',

set role to admin directly in db.

  1. role admin, can access the admin, set limit 5. make server request then out of limit.

adjust limit and the error disappear

你好,请教关于配置的问题

感谢大佬的分享。

请问是在哪里修改openai 模型 。
以及在哪里修改这些规则的配置。
谢谢!

第一个消息是系统消息(prompt)
上下文默认附带最新创建的10条消息
第一个注册的用户是管理员
默认限流 100 chatgpt api call /10分钟

create chat snapshot and make the conversation sharable

-- for share chat feature
CREATE TABLE IF NOT EXISTS chat_snapshot (
    id SERIAL PRIMARY KEY,
    uuid VARCHAR(255) NOT NULL default '',
    user_id INTEGER NOT NULL default 0,
    title VARCHAR(255) NOT NULL default '',
    summary TEXT NOT NULL default '',
    tags JSONB DEFAULT '{}' NOT NULL,
    conversation JSONB NOT NULL default '{}',
    created_at TIMESTAMP DEFAULT now() NOT NULL
);

config model svg

Here is the updated component that allows the user to configure models in the frontend:

<template>
  <svg :viewBox="viewBox" :width="width" :height="height">
    <g v-for="model in models" :key="model.id">
      <path :d="model.path" :fill="model.color"/>
      <text :x="model.textX" :y="model.textY">{{ model.name }}</text>
    </g>
  </svg>
  
  <div class="model-config">
    <label>Name: <input v-model="newModel.name"/></label>
    <label>Path: <input v-model="newModel.path"/></label>
    <label>Color: <input v-model="newModel.color"/></label>
    <label>Text X: <input v-model.number="newModel.textX"/></label>
    <label>Text Y: <input v-model.number="newModel.textY"/></label>
    <button @click="addModel">Add Model</button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// SVG props
const width = ref(600)  
const height = ref(400)
const viewBox = ref('0 0 600 400')

// Model data
const models = ref<any[]>([
  { id: 1, name: 'Model 1', ... }  // Model from previous example
])

const newModel = ref({
  name: '',
  path: '',
  color: '',
  textX: 0,
  textY: 0 
})

const addModel = () => {
  newModel.value.id = models.value.length + 1
  models.value.push(newModel.value)
  newModel.value = { name: '', path: '', color: '', textX: 0, textY: 0 } 
} 
</script>


// Comments:
// - Added a .model-config div for the form 
// - newModel ref holds the data for a new model being configured
// - The addModel method adds a new model, generates an id and resets the form
// - Inputs are bound using v-model

enable add comment to message

CREATE TABLE IF NOT EXISTS message_comment (
    id SERIAL PRIMARY KEY,
    uuid VARCHAR(255) NOT NULL default '',
    -- chat_uuid is the chat message or prompt to comment on
    message_uuid VARCHAR(255) NOT NULL default '',
    user_id INTEGER NOT NULL default 0,
    content TEXT DEFAULT '' NOT NULL default '',
    created_at TIMESTAMP DEFAULT now() NOT NULL
);

一直报错 FATAL: role "root" does not exist

web | 218.82.136.139 - - [10/Apr/2023:09:13:46 +0000] "POST /api/chat_stream HTTP/1.1" 500 61 "http://1x:8084/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-"
api | 172.18.0.4 - - [10/Apr/2023:09:13:46 +0000] "POST /chat_stream HTTP/1.1" 500 61
chat-db-1 | 2023-04-10 17:13:46.927 CST [156] FATAL: role "root" does not exist
api | 2023/04/10 09:13:50 chatSessionUuid: 1fdf2591-898a-4af6-9a62-d0be5a00fead
api | 2023/04/10 09:13:50 chatUuid: 1e5032dd-0c0c-45ea-a04f-d68c412b05f6
api | 2023/04/10 09:13:50 newQuestion: 1+1等于多少
api |
api | 172.18.0.4 - - [10/Apr/2023:09:13:50 +0000] "POST /chat_stream HTTP/1.1" 200 0
web | 218.82.136.139 - - [10/Apr/2023:09:13:50 +0000] "POST /api/chat_stream HTTP/1.1" 200 0 "http://1x:8084/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36" "-"
chat-db-1 | 2023-04-10 17:13:52.070 CST [165] FATAL: role "root" does not exist
chat-db-1 | 2023-04-10 17:13:57.215 CST [173] FATAL: role "root" does not exist
chat-db-1 | 2023-04-10 17:14:02.357 CST [181] FATAL: role "root" does not exist

error.invalid_password

为什么我安装完后,访问的时候输入邮箱和密码,点击注册的时候老是报错。error.invalid_password

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.