forked from lxh/go-wxhelper
Merge pull request '🆕新增Google gemini-pro上下文处理。暂时先这样,有空仔细琢磨' (#1) from coward into main
Reviewed-on: #1
This commit is contained in:
commit
bb781ee3a8
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,10 +1,11 @@
|
|||||||
.idea
|
.idea
|
||||||
vendor
|
vendor
|
||||||
logs
|
logs
|
||||||
*.exe
|
*.exe
|
||||||
*.pprof
|
*.pprof
|
||||||
cache
|
cache
|
||||||
log
|
log
|
||||||
dist
|
dist
|
||||||
*.log
|
*.log
|
||||||
blacklist.txt
|
blacklist.txt
|
||||||
|
config.yaml
|
40
Dockerfile
40
Dockerfile
@ -1,21 +1,21 @@
|
|||||||
FROM golang:alpine as builder
|
FROM golang:alpine as builder
|
||||||
WORKDIR /builder
|
WORKDIR /builder
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
#ENV GO111MODULE=on
|
#ENV GO111MODULE=on
|
||||||
#ENV GOPROXY=https://goproxy.cn,direct
|
#ENV GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
RUN go version
|
RUN go version
|
||||||
RUN go mod download && go build -o wxhelper
|
RUN go mod download && go build -o wxhelper
|
||||||
RUN ls -lh && chmod -R +x ./*
|
RUN ls -lh && chmod -R +x ./*
|
||||||
|
|
||||||
FROM code.hyxc1.com/open/alpine:3.16.0 as runner
|
FROM code.hyxc1.com/open/alpine:3.16.0 as runner
|
||||||
LABEL org.opencontainers.image.authors="lxh@cxh.cn"
|
LABEL org.opencontainers.image.authors="lxh@cxh.cn"
|
||||||
|
|
||||||
EXPOSE 19099
|
EXPOSE 19099
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=builder /builder/wxhelper ./wxhelper
|
COPY --from=builder /builder/wxhelper ./wxhelper
|
||||||
COPY --from=builder /builder/views ./views
|
COPY --from=builder /builder/views ./views
|
||||||
CMD ./wxhelper
|
CMD ./wxhelper
|
59
config.yaml
59
config.yaml
@ -1,59 +0,0 @@
|
|||||||
# 微信HOOK配置
|
|
||||||
wechat:
|
|
||||||
# 微信HOOK接口地址
|
|
||||||
host: 10.0.0.73:19088
|
|
||||||
# 微信容器映射出来的vnc页面地址,没有就不填
|
|
||||||
vncUrl: http://192.168.1.175:19087/vnc_lite.html
|
|
||||||
# 是否在启动的时候自动设置hook服务的回调
|
|
||||||
autoSetCallback: false
|
|
||||||
# 回调IP,如果是Docker运行,本参数必填(填auto表示自动,不适用于 docker 环境),如果Docker修改了映射,格式为 ip:port
|
|
||||||
callback: 10.0.0.51
|
|
||||||
# 转发到其他地址
|
|
||||||
forward:
|
|
||||||
# - 10.0.0.247:4299
|
|
||||||
|
|
||||||
# 数据库
|
|
||||||
mysql:
|
|
||||||
host: 10.0.0.31
|
|
||||||
port: 3307
|
|
||||||
user: wechat
|
|
||||||
password: wechat123
|
|
||||||
db: wechat
|
|
||||||
|
|
||||||
task:
|
|
||||||
enable: false
|
|
||||||
syncFriends:
|
|
||||||
enable: false
|
|
||||||
cron: '*/5 * * * *' # 五分钟一次
|
|
||||||
waterGroup:
|
|
||||||
enable: true
|
|
||||||
cron:
|
|
||||||
yesterday: '30 9 * * *' # 每天9:30
|
|
||||||
week: '30 9 * * 1' # 每周一9:30
|
|
||||||
month: '30 9 1 * *' # 每月1号9:30
|
|
||||||
year: '0 9 1 1 *' # 每年1月1号9:30
|
|
||||||
|
|
||||||
# AI回复
|
|
||||||
ai:
|
|
||||||
# 是否启用
|
|
||||||
enable: false
|
|
||||||
# 模型,不填默认gpt-3.5-turbo-0613
|
|
||||||
model: gpt-3.5-turbo-0613
|
|
||||||
# OpenAI Api key
|
|
||||||
apiKey: sk-xxxx
|
|
||||||
# 接口代理域名,不填默认ChatGPT官方地址
|
|
||||||
baseUrl: https://sxxx
|
|
||||||
# 人设
|
|
||||||
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。
|
|
||||||
|
|
||||||
# 资源配置
|
|
||||||
# map[k]v结构,k 会变成全小写,所以这儿不能用大写字母
|
|
||||||
resource:
|
|
||||||
# 欢迎新成员表情包
|
|
||||||
welcome-new:
|
|
||||||
type: emotion
|
|
||||||
path: 58e4150be2bba8f7b71974b10391f9e9
|
|
||||||
# 水群排行榜词云,只能是图片,末尾的`\%s`也是必须的
|
|
||||||
wordcloud:
|
|
||||||
type: image
|
|
||||||
path: D:\Share\wordcloud\%s
|
|
@ -97,6 +97,9 @@ func AI(m *plugin.MessageContext) {
|
|||||||
chatModel = config.Conf.Ai.Model
|
chatModel = config.Conf.Ai.Model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理gemini-pro
|
||||||
|
messages, chatModel = googleGeminiContextMessage(messages, chatModel)
|
||||||
|
|
||||||
// 默认使用AI回复
|
// 默认使用AI回复
|
||||||
conf := openai.DefaultConfig(config.Conf.Ai.ApiKey)
|
conf := openai.DefaultConfig(config.Conf.Ai.ApiKey)
|
||||||
if config.Conf.Ai.BaseUrl != "" {
|
if config.Conf.Ai.BaseUrl != "" {
|
||||||
@ -170,3 +173,22 @@ func getUserPrivateMessages(userId string) (records []entity.Message) {
|
|||||||
Limit(4).Find(&records)
|
Limit(4).Find(&records)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// googleGeminiContextMessage
|
||||||
|
// @description: 处理一下谷歌gemini
|
||||||
|
// @param messages
|
||||||
|
// @param model
|
||||||
|
// @return []openai.ChatCompletionMessage
|
||||||
|
// @return string
|
||||||
|
func googleGeminiContextMessage(ctxMsg []openai.ChatCompletionMessage, modelStr string) (messages []openai.ChatCompletionMessage, model string) {
|
||||||
|
if !strings.HasSuffix(modelStr, "-gemini-pro") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
messages = ctxMsg
|
||||||
|
model = strings.Replace(modelStr, "-gemini-pro", "", -1)
|
||||||
|
// 上下文截取推出,gemini-pro不支持上下文当中多条连续用户发送的。
|
||||||
|
if len(messages)%2 == 0 {
|
||||||
|
messages = append(messages[:1], messages[len(messages)-1:]...) // 首条不去因为是人设
|
||||||
|
}
|
||||||
|
return messages, model
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user