mirror of
				https://github.com/yangjian102621/geekai.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	add Makefile, fixed websocket url for https
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -23,3 +23,4 @@ dist-ssr
 | 
				
			|||||||
*.sln
 | 
					*.sln
 | 
				
			||||||
*.sw?
 | 
					*.sw?
 | 
				
			||||||
tmp
 | 
					tmp
 | 
				
			||||||
 | 
					bin
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										32
									
								
								Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								Makefile
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -9,8 +9,8 @@
 | 
				
			|||||||
* [x] 用户聊天鉴权,设置口令模式
 | 
					* [x] 用户聊天鉴权,设置口令模式
 | 
				
			||||||
* [ ] 每次连接自动加载历史记录
 | 
					* [ ] 每次连接自动加载历史记录
 | 
				
			||||||
* [x] OpenAI API 负载均衡,限制每个 API Key 每分钟之内调用次数不超过 15次,防止被封
 | 
					* [x] OpenAI API 负载均衡,限制每个 API Key 每分钟之内调用次数不超过 15次,防止被封
 | 
				
			||||||
* [ ] 角色设定,预设一些角色,比如程序员,产品经理,医生,作家,老师...
 | 
					* [ ] 角色设定,预设一些角色,比如程序员,客服,作家,老师,艺术家...
 | 
				
			||||||
* [ ] markdown 语法解析
 | 
					* [x] markdown 语法解析和代码高亮
 | 
				
			||||||
* [ ] 用户配置界面,配置用户的使用习惯
 | 
					* [ ] 用户配置界面,配置用户的使用习惯
 | 
				
			||||||
* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片
 | 
					* [ ] 嵌入 AI 绘画功能,支持根据描述词生成图片
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								config.sample.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								config.sample.toml
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -68,7 +68,7 @@ func NewServer(configPath string) (*Server, error) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *Server) Run(webRoot embed.FS, path string) {
 | 
					func (s *Server) Run(webRoot embed.FS, path string) {
 | 
				
			||||||
	gin.SetMode(gin.DebugMode)
 | 
						gin.SetMode(gin.ReleaseMode)
 | 
				
			||||||
	engine := gin.Default()
 | 
						engine := gin.Default()
 | 
				
			||||||
	engine.Use(sessionMiddleware(s.Config))
 | 
						engine.Use(sessionMiddleware(s.Config))
 | 
				
			||||||
	engine.Use(corsMiddleware())
 | 
						engine.Use(corsMiddleware())
 | 
				
			||||||
@@ -80,6 +80,12 @@ func (s *Server) Run(webRoot embed.FS, path string) {
 | 
				
			|||||||
	engine.Any("/api/chat", s.ChatHandle)
 | 
						engine.Any("/api/chat", s.ChatHandle)
 | 
				
			||||||
	engine.POST("/api/config/set", s.ConfigSetHandle)
 | 
						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
 | 
						// process front-end web static files
 | 
				
			||||||
	engine.StaticFS("/chat", http.FS(StaticFile{
 | 
						engine.StaticFS("/chat", http.FS(StaticFile{
 | 
				
			||||||
		embedFS: webRoot,
 | 
							embedFS: webRoot,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,2 +1,2 @@
 | 
				
			|||||||
VUE_APP_API_HOST=172.22.11.200:5678
 | 
					VUE_APP_API_HOST=http://172.22.11.200:5678
 | 
				
			||||||
VUE_APP_API_SECURE=false
 | 
					VUE_APP_WS_HOST=ws://172.22.11.200:5678
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,2 +1,2 @@
 | 
				
			|||||||
VUE_APP_API_HOST=172.22.11.200:5678
 | 
					VUE_APP_API_HOST=http://chat.r9it.com:6789
 | 
				
			||||||
VUE_APP_API_SECURE=false
 | 
					VUE_APP_WS_HOST=ws://chat.r9it.com:6789
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,7 @@ import axios from 'axios'
 | 
				
			|||||||
import {getSessionId} from "@/utils/storage";
 | 
					import {getSessionId} from "@/utils/storage";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
axios.defaults.timeout = 5000
 | 
					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.withCredentials = true;
 | 
				
			||||||
axios.defaults.headers.post['Content-Type'] = 'application/json'
 | 
					axios.defaults.headers.post['Content-Type'] = 'application/json'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -198,6 +198,8 @@ export default defineComponent({
 | 
				
			|||||||
                confirmButtonText: '重连会话',
 | 
					                confirmButtonText: '重连会话',
 | 
				
			||||||
                cancelButtonText: '不聊了',
 | 
					                cancelButtonText: '不聊了',
 | 
				
			||||||
                type: 'warning',
 | 
					                type: 'warning',
 | 
				
			||||||
 | 
					                showClose: false,
 | 
				
			||||||
 | 
					                closeOnClickModal: false
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
          ).then(() => {
 | 
					          ).then(() => {
 | 
				
			||||||
            this.connect();
 | 
					            this.connect();
 | 
				
			||||||
@@ -214,7 +216,7 @@ export default defineComponent({
 | 
				
			|||||||
    connect: function () {
 | 
					    connect: function () {
 | 
				
			||||||
      // 初始化 WebSocket 对象
 | 
					      // 初始化 WebSocket 对象
 | 
				
			||||||
      const token = getSessionId();
 | 
					      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', () => {
 | 
					      socket.addEventListener('open', () => {
 | 
				
			||||||
        ElMessage.success('创建会话成功!');
 | 
					        ElMessage.success('创建会话成功!');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user