diff --git a/.gitignore b/.gitignore index a1acad64..8aa08a53 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ dist-ssr *.sln *.sw? tmp +bin diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..b530046a --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index e5ea5406..ee03c4ce 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ * [x] 用户聊天鉴权,设置口令模式 * [ ] 每次连接自动加载历史记录 * [x] OpenAI API 负载均衡,限制每个 API Key 每分钟之内调用次数不超过 15次,防止被封 -* [ ] 角色设定,预设一些角色,比如程序员,产品经理,医生,作家,老师... -* [ ] markdown 语法解析 +* [ ] 角色设定,预设一些角色,比如程序员,客服,作家,老师,艺术家... +* [x] markdown 语法解析和代码高亮 * [ ] 用户配置界面,配置用户的使用习惯 * [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片 diff --git a/config.sample.toml b/config.sample.toml new file mode 100644 index 00000000..dbf30b4a --- /dev/null +++ b/config.sample.toml @@ -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 diff --git a/server/server.go b/server/server.go index 67a00f33..a2495a35 100644 --- a/server/server.go +++ b/server/server.go @@ -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, diff --git a/web/.env.development b/web/.env.development index 3ea203f8..8e08ffb8 100644 --- a/web/.env.development +++ b/web/.env.development @@ -1,2 +1,2 @@ -VUE_APP_API_HOST=172.22.11.200:5678 -VUE_APP_API_SECURE=false \ No newline at end of file +VUE_APP_API_HOST=http://172.22.11.200:5678 +VUE_APP_WS_HOST=ws://172.22.11.200:5678 diff --git a/web/.env.production b/web/.env.production index 3ea203f8..8bdbc1c8 100644 --- a/web/.env.production +++ b/web/.env.production @@ -1,2 +1,2 @@ -VUE_APP_API_HOST=172.22.11.200:5678 -VUE_APP_API_SECURE=false \ No newline at end of file +VUE_APP_API_HOST=http://chat.r9it.com:6789 +VUE_APP_WS_HOST=ws://chat.r9it.com:6789 diff --git a/web/src/utils/http.js b/web/src/utils/http.js index 6ce15291..e5899e09 100644 --- a/web/src/utils/http.js +++ b/web/src/utils/http.js @@ -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' diff --git a/web/src/views/Chat.vue b/web/src/views/Chat.vue index 784b6318..656f5842 100644 --- a/web/src/views/Chat.vue +++ b/web/src/views/Chat.vue @@ -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('创建会话成功!');