add Makefile, fixed websocket url for https

This commit is contained in:
RockYang 2023-03-23 18:10:23 +08:00
parent a061881d4a
commit 2067aa3f83
9 changed files with 72 additions and 9 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ dist-ssr
*.sln
*.sw?
tmp
bin

32
Makefile Normal file
View File

@ -0,0 +1,32 @@
SHELL=/usr/bin/env bash
NAME := wechatGPT
all: window_x86 window_amd64 linux_x86 linux_amd64 mac_x86 mac_64
window_x86:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o bin/$(NAME).exe main.go
.PHONY: window_x86
window_amd64:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/$(NAME)-amd64.exe main.go
.PHONY: window_amd64
linux_x86:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o bin/$(NAME)-386-linux main.go
.PHONY: linux_x86
linux_amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/$(NAME)-amd64-linux main.go
.PHONY: linux_amd64
mac_x86:
CGO_ENABLED=1 GOOS=darwin GOARCH=386 go build -o bin/$(NAME)-386-darwin main.go
.PHONY: mac_x86
mac_64:
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o bin/$(NAME)-amd64-darwin main.go
.PHONY: mac_64
clean:
rm -rf bin/$(NAME)-*
.PHONY: clean

View File

@ -9,8 +9,8 @@
* [x] 用户聊天鉴权,设置口令模式
* [ ] 每次连接自动加载历史记录
* [x] OpenAI API 负载均衡,限制每个 API Key 每分钟之内调用次数不超过 15次防止被封
* [ ] 角色设定,预设一些角色,比如程序员,产品经理,医生,作家,老师...
* [ ] markdown 语法解析
* [ ] 角色设定,预设一些角色,比如程序员,客服,作家,老师,艺术家...
* [x] markdown 语法解析和代码高亮
* [ ] 用户配置界面,配置用户的使用习惯
* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片

22
config.sample.toml Normal file
View File

@ -0,0 +1,22 @@
Listen = "0.0.0.0:5678"
ProxyURL = "http://127.0.0.1:7890"
EnableAuth = false
Tokens = [""]
[Session]
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80"
Name = "CHAT_SESSION_ID"
Path = "/"
Domain = ""
MaxAge = 86400
Secure = true
HttpOnly = false
SameSite = 4
[Chat]
ApiURL = "https://api.openai.com/v1/chat/completions"
ApiKeys = ["xxx"]
Model = "gpt-3.5-turbo"
Temperature = 1.0
MaxTokens = 1024
EnableContext = true

View File

@ -68,7 +68,7 @@ func NewServer(configPath string) (*Server, error) {
}
func (s *Server) Run(webRoot embed.FS, path string) {
gin.SetMode(gin.DebugMode)
gin.SetMode(gin.ReleaseMode)
engine := gin.Default()
engine.Use(sessionMiddleware(s.Config))
engine.Use(corsMiddleware())
@ -80,6 +80,12 @@ func (s *Server) Run(webRoot embed.FS, path string) {
engine.Any("/api/chat", s.ChatHandle)
engine.POST("/api/config/set", s.ConfigSetHandle)
engine.NoRoute(func(c *gin.Context) {
if c.Request.URL.Path == "/favicon.ico" {
c.Redirect(http.StatusMovedPermanently, "/chat/"+c.Request.URL.Path)
}
})
// process front-end web static files
engine.StaticFS("/chat", http.FS(StaticFile{
embedFS: webRoot,

View File

@ -1,2 +1,2 @@
VUE_APP_API_HOST=172.22.11.200:5678
VUE_APP_API_SECURE=false
VUE_APP_API_HOST=http://172.22.11.200:5678
VUE_APP_WS_HOST=ws://172.22.11.200:5678

View File

@ -1,2 +1,2 @@
VUE_APP_API_HOST=172.22.11.200:5678
VUE_APP_API_SECURE=false
VUE_APP_API_HOST=http://chat.r9it.com:6789
VUE_APP_WS_HOST=ws://chat.r9it.com:6789

View File

@ -2,7 +2,7 @@ import axios from 'axios'
import {getSessionId} from "@/utils/storage";
axios.defaults.timeout = 5000
axios.defaults.baseURL = process.env.VUE_APP_API_SECURE === true ? 'https://' + process.env.VUE_APP_API_HOST : 'http://' + process.env.VUE_APP_API_HOST
axios.defaults.baseURL = process.env.VUE_APP_API_HOST
axios.defaults.withCredentials = true;
axios.defaults.headers.post['Content-Type'] = 'application/json'

View File

@ -198,6 +198,8 @@ export default defineComponent({
confirmButtonText: '重连会话',
cancelButtonText: '不聊了',
type: 'warning',
showClose: false,
closeOnClickModal: false
}
).then(() => {
this.connect();
@ -214,7 +216,7 @@ export default defineComponent({
connect: function () {
// WebSocket
const token = getSessionId();
const socket = new WebSocket('ws://' + process.env.VUE_APP_API_HOST + '/api/chat?token=' + token);
const socket = new WebSocket(process.env.VUE_APP_WS_HOST + '/api/chat?token=' + token);
socket.addEventListener('open', () => {
ElMessage.success('创建会话成功!');