From f6190a543856cbf824b201da788828d31eb277b5 Mon Sep 17 00:00:00 2001 From: comma Date: Tue, 16 Jan 2024 22:26:04 +0800 Subject: [PATCH] =?UTF-8?q?:new:=E6=96=B0=E5=A2=9EGoogle=20gemini-pro?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E5=A4=84=E7=90=86=E3=80=82=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E5=85=88=E8=BF=99=E6=A0=B7=EF=BC=8C=E6=9C=89=E7=A9=BA?= =?UTF-8?q?=E4=BB=94=E7=BB=86=E7=90=A2=E7=A3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 21 ++++++++-------- Dockerfile | 40 +++++++++++++++--------------- config.yaml | 59 -------------------------------------------- plugin/plugins/ai.go | 22 +++++++++++++++++ 4 files changed, 53 insertions(+), 89 deletions(-) delete mode 100644 config.yaml diff --git a/.gitignore b/.gitignore index 45a581b..2c87e61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,11 @@ -.idea -vendor -logs -*.exe -*.pprof -cache -log -dist -*.log -blacklist.txt \ No newline at end of file +.idea +vendor +logs +*.exe +*.pprof +cache +log +dist +*.log +blacklist.txt +config.yaml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0b40c0d..d6c027f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,21 @@ -FROM golang:alpine as builder -WORKDIR /builder -COPY . . - -#ENV GO111MODULE=on -#ENV GOPROXY=https://goproxy.cn,direct - -RUN go version -RUN go mod download && go build -o wxhelper -RUN ls -lh && chmod -R +x ./* - -FROM code.hyxc1.com/open/alpine:3.16.0 as runner -LABEL org.opencontainers.image.authors="lxh@cxh.cn" - -EXPOSE 19099 -EXPOSE 8080 - -WORKDIR /app -COPY --from=builder /builder/wxhelper ./wxhelper -COPY --from=builder /builder/views ./views +FROM golang:alpine as builder +WORKDIR /builder +COPY . . + +#ENV GO111MODULE=on +#ENV GOPROXY=https://goproxy.cn,direct + +RUN go version +RUN go mod download && go build -o wxhelper +RUN ls -lh && chmod -R +x ./* + +FROM code.hyxc1.com/open/alpine:3.16.0 as runner +LABEL org.opencontainers.image.authors="lxh@cxh.cn" + +EXPOSE 19099 +EXPOSE 8080 + +WORKDIR /app +COPY --from=builder /builder/wxhelper ./wxhelper +COPY --from=builder /builder/views ./views CMD ./wxhelper \ No newline at end of file diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 52dac8a..0000000 --- a/config.yaml +++ /dev/null @@ -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 diff --git a/plugin/plugins/ai.go b/plugin/plugins/ai.go index 59eb786..5dcf49d 100644 --- a/plugin/plugins/ai.go +++ b/plugin/plugins/ai.go @@ -97,6 +97,9 @@ func AI(m *plugin.MessageContext) { chatModel = config.Conf.Ai.Model } + // 处理gemini-pro + messages, chatModel = googleGeminiContextMessage(messages, chatModel) + // 默认使用AI回复 conf := openai.DefaultConfig(config.Conf.Ai.ApiKey) if config.Conf.Ai.BaseUrl != "" { @@ -170,3 +173,22 @@ func getUserPrivateMessages(userId string) (records []entity.Message) { Limit(4).Find(&records) 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 +}