update database file, add tika host config

This commit is contained in:
RockYang
2024-07-12 18:10:32 +08:00
parent eecce10018
commit 46141f87b8
19 changed files with 1087 additions and 89 deletions

View File

@@ -5,6 +5,7 @@ StaticDir = "./static" # 静态资源的目录
StaticUrl = "/static" # 静态资源访问 URL
AesEncryptKey = ""
WeChatBot = false
TikaHost = "http://tika:9998"
[Session]
SecretKey = "azyehq3ivunjhbntz78isj00i4hz2mt9xtddysfucxakadq4qbfrt0b7q3lnvg80" # 注意:这个是 JWT Token 授权密钥,生产环境请务必更换

View File

@@ -35,6 +35,7 @@ type AppConfig struct {
SmtpConfig SmtpConfig // 邮件发送配置
JPayConfig JPayConfig // payjs 支付配置
WechatPayConfig WechatPayConfig // 微信支付渠道配置
TikaHost string // TiKa 服务器地址
}
type SmtpConfig struct {

View File

@@ -317,13 +317,18 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
// extract files in prompt
files := utils.ExtractFileURLs(prompt)
logger.Debugf("detected FILES: %+v", files)
if len(files) > 0 {
// 如果不是逆向模型,则提取文件内容
if len(files) > 0 && !(session.Model.Value == "gpt-4-all" ||
strings.HasPrefix(session.Model.Value, "gpt-4-gizmo") ||
strings.HasSuffix(session.Model.Value, "claude-3")) {
contents := make([]string, 0)
var file model.File
for _, v := range files {
h.DB.Where("url = ?", v).First(&file)
content, err := utils.ReadFileContent(v)
if err == nil {
content, err := utils.ReadFileContent(v, h.App.Config.TikaHost)
if err != nil {
logger.Error("error with read file: ", err)
} else {
contents = append(contents, fmt.Sprintf("%s 文件内容:%s", file.Name, content))
}
text = strings.Replace(text, v, "", 1)

View File

@@ -36,7 +36,7 @@ func (h *UploadHandler) Upload(c *gin.Context) {
return
}
logger.Info("upload file: %s", file.Name)
logger.Info("upload file: ", file.Name)
// cut the file name if it's too long
if len(file.Name) > 100 {
file.Name = file.Name[:90] + file.Ext

View File

@@ -256,8 +256,8 @@ func (h *UserHandler) Logout(c *gin.Context) {
resp.SUCCESS(c)
}
// Clogin 第三方登录请求二维码
func (h *UserHandler) Clogin(c *gin.Context) {
// CLogin 第三方登录请求二维码
func (h *UserHandler) CLogin(c *gin.Context) {
returnURL := h.GetTrim(c, "return_url")
var res types.BizVo
apiURL := fmt.Sprintf("%s/api/clogin/request", h.App.Config.ApiConfig.ApiURL)

View File

@@ -240,7 +240,7 @@ func main() {
group.POST("password", h.UpdatePass)
group.POST("bind/username", h.BindUsername)
group.POST("resetPass", h.ResetPass)
group.GET("clogin", h.Clogin)
group.GET("clogin", h.CLogin)
group.GET("clogin/callback", h.CLoginCallback)
}),
fx.Invoke(func(s *core.AppServer, h *chatimpl.ChatHandler) {

View File

@@ -7,7 +7,7 @@ import (
func main() {
file := "http://nk.img.r9it.com/chatgpt-plus/1719389335351828.xlsx"
content, err := utils.ReadFileContent(file)
content, err := utils.ReadFileContent(file, "http://172.22.11.69:9998")
if err != nil {
panic(err)
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/google/go-tika/tika"
)
func ReadFileContent(filePath string) (string, error) {
func ReadFileContent(filePath string, tikaHost string) (string, error) {
// for remote file, download it first
if strings.HasPrefix(filePath, "http") {
file, err := downloadFile(filePath)
@@ -23,7 +23,7 @@ func ReadFileContent(filePath string) (string, error) {
filePath = file
}
// 创建 Tika 客户端
client := tika.NewClient(nil, "http://172.22.11.69:9998")
client := tika.NewClient(nil, tikaHost)
// 打开 PDF 文件
file, err := os.Open(filePath)
if err != nil {