Browse Source

feat: support send knowledge base image

master
zhayujie 1 year ago
parent
commit
374cd5dbb8
5 changed files with 24 additions and 9 deletions
  1. +17
    -3
      bot/linkai/link_ai_bot.py
  2. +1
    -0
      channel/chat_channel.py
  3. +1
    -2
      config-template.json
  4. +2
    -2
      config.py
  5. +3
    -2
      plugins/linkai/README.md

+ 17
- 3
bot/linkai/link_ai_bot.py View File

@@ -7,13 +7,12 @@ import requests

from bot.bot import Bot
from bot.chatgpt.chat_gpt_session import ChatGPTSession
from bot.openai.open_ai_image import OpenAIImage
from bot.session_manager import SessionManager
from bridge.context import Context, ContextType
from bridge.reply import Reply, ReplyType
from common.log import logger
from config import conf, pconf
import threading

class LinkAIBot(Bot):
# authentication failed
@@ -64,7 +63,7 @@ class LinkAIBot(Bot):
session_id = context["session_id"]

session = self.sessions.session_query(query, session_id)
model = conf().get("model") or "gpt-3.5-turbo"
model = conf().get("model")
# remove system message
if session.messages[0].get("role") == "system":
if app_code or model == "wenxin":
@@ -104,6 +103,10 @@ class LinkAIBot(Bot):
knowledge_suffix = self._fetch_knowledge_search_suffix(response)
if knowledge_suffix:
reply_content += knowledge_suffix
# image process
if response["choices"][0].get("img_urls"):
thread = threading.Thread(target=self._send_image, args=(context.get("channel"), context, response["choices"][0].get("img_urls")))
thread.start()
return Reply(ReplyType.TEXT, reply_content)

else:
@@ -262,3 +265,14 @@ class LinkAIBot(Bot):
return suffix
except Exception as e:
logger.exception(e)


def _send_image(self, channel, context, image_urls):
if not image_urls:
return
try:
for url in image_urls:
reply = Reply(ReplyType.IMAGE_URL, url)
channel.send(reply, context)
except Exception as e:
logger.error(e)

+ 1
- 0
channel/chat_channel.py View File

@@ -175,6 +175,7 @@ class ChatChannel(Channel):
if e_context.is_break():
context["generate_breaked_by"] = e_context["breaked_by"]
if context.type == ContextType.TEXT or context.type == ContextType.IMAGE_CREATE: # 文字和图片消息
context["channel"] = e_context["channel"]
reply = super().build_reply_content(context.content, context)
elif context.type == ContextType.VOICE: # 语音消息
cmsg = context["msg"]


+ 1
- 2
config-template.json View File

@@ -1,7 +1,7 @@
{
"channel_type": "wx",
"model": "",
"open_ai_api_key": "YOUR API KEY",
"model": "gpt-3.5-turbo",
"text_to_image": "dall-e-2",
"voice_to_text": "openai",
"text_to_voice": "openai",
@@ -28,7 +28,6 @@
"speech_recognition": true,
"group_speech_recognition": false,
"voice_reply_voice": false,
"tts_voice_id": "alloy",
"conversation_max_tokens": 2500,
"expires_in_seconds": 3600,
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。",


+ 2
- 2
config.py View File

@@ -16,7 +16,7 @@ available_setting = {
"open_ai_api_base": "https://api.openai.com/v1",
"proxy": "", # openai使用的代理
# chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称
"model": "gpt-3.5-turbo", # 还支持 gpt-3.5-turbo-16k, gpt-4, wenxin, xunfei
"model": "gpt-3.5-turbo", # 还支持 gpt-4, gpt-4-turbo, wenxin, xunfei
"use_azure_chatgpt": False, # 是否使用azure的chatgpt
"azure_deployment_id": "", # azure 模型部署名称
"azure_api_version": "", # azure api版本
@@ -52,7 +52,7 @@ available_setting = {
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"request_timeout": 60, # chatgpt请求超时时间,openai接口默认设置为600,对于难问题一般需要较长时间
"request_timeout": 180, # chatgpt请求超时时间,openai接口默认设置为600,对于难问题一般需要较长时间
"timeout": 120, # chatgpt重试超时时间,在这个时间内,将会自动重试
# Baidu 文心一言参数
"baidu_wenxin_model": "eb-instant", # 默认使用ERNIE-Bot-turbo模型


+ 3
- 2
plugins/linkai/README.md View File

@@ -25,7 +25,8 @@
"summary": {
"enabled": true, # 文档总结和对话功能开关
"group_enabled": true, # 是否支持群聊开启
"max_file_size": 5000 # 文件的大小限制,单位KB,默认为5M,超过该大小直接忽略
"max_file_size": 5000, # 文件的大小限制,单位KB,默认为5M,超过该大小直接忽略
"type": ["FILE", "SHARING", "IMAGE"] # 支持总结的类型,分别表示 文件、分享链接、图片
}
}
```
@@ -99,7 +100,7 @@

#### 使用

功能开启后,向机器人发送 **文件** 或 **分享链接卡片** 即可生成摘要,进一步可以与文件或链接的内容进行多轮对话。
功能开启后,向机器人发送 **文件**、 **分享链接卡片**、**图片** 即可生成摘要,进一步可以与文件或链接的内容进行多轮对话。如果需要关闭某种类型的内容总结,设置 `summary`配置中的type字段即可。

#### 限制



Loading…
Cancel
Save