@@ -7,13 +7,12 @@ import requests | |||||
from bot.bot import Bot | from bot.bot import Bot | ||||
from bot.chatgpt.chat_gpt_session import ChatGPTSession | from bot.chatgpt.chat_gpt_session import ChatGPTSession | ||||
from bot.openai.open_ai_image import OpenAIImage | |||||
from bot.session_manager import SessionManager | from bot.session_manager import SessionManager | ||||
from bridge.context import Context, ContextType | from bridge.context import Context, ContextType | ||||
from bridge.reply import Reply, ReplyType | from bridge.reply import Reply, ReplyType | ||||
from common.log import logger | from common.log import logger | ||||
from config import conf, pconf | from config import conf, pconf | ||||
import threading | |||||
class LinkAIBot(Bot): | class LinkAIBot(Bot): | ||||
# authentication failed | # authentication failed | ||||
@@ -64,7 +63,7 @@ class LinkAIBot(Bot): | |||||
session_id = context["session_id"] | session_id = context["session_id"] | ||||
session = self.sessions.session_query(query, 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 | # remove system message | ||||
if session.messages[0].get("role") == "system": | if session.messages[0].get("role") == "system": | ||||
if app_code or model == "wenxin": | if app_code or model == "wenxin": | ||||
@@ -104,6 +103,10 @@ class LinkAIBot(Bot): | |||||
knowledge_suffix = self._fetch_knowledge_search_suffix(response) | knowledge_suffix = self._fetch_knowledge_search_suffix(response) | ||||
if knowledge_suffix: | if knowledge_suffix: | ||||
reply_content += 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) | return Reply(ReplyType.TEXT, reply_content) | ||||
else: | else: | ||||
@@ -262,3 +265,14 @@ class LinkAIBot(Bot): | |||||
return suffix | return suffix | ||||
except Exception as e: | except Exception as e: | ||||
logger.exception(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) |
@@ -175,6 +175,7 @@ class ChatChannel(Channel): | |||||
if e_context.is_break(): | if e_context.is_break(): | ||||
context["generate_breaked_by"] = e_context["breaked_by"] | context["generate_breaked_by"] = e_context["breaked_by"] | ||||
if context.type == ContextType.TEXT or context.type == ContextType.IMAGE_CREATE: # 文字和图片消息 | if context.type == ContextType.TEXT or context.type == ContextType.IMAGE_CREATE: # 文字和图片消息 | ||||
context["channel"] = e_context["channel"] | |||||
reply = super().build_reply_content(context.content, context) | reply = super().build_reply_content(context.content, context) | ||||
elif context.type == ContextType.VOICE: # 语音消息 | elif context.type == ContextType.VOICE: # 语音消息 | ||||
cmsg = context["msg"] | cmsg = context["msg"] | ||||
@@ -1,7 +1,7 @@ | |||||
{ | { | ||||
"channel_type": "wx", | "channel_type": "wx", | ||||
"model": "", | |||||
"open_ai_api_key": "YOUR API KEY", | "open_ai_api_key": "YOUR API KEY", | ||||
"model": "gpt-3.5-turbo", | |||||
"text_to_image": "dall-e-2", | "text_to_image": "dall-e-2", | ||||
"voice_to_text": "openai", | "voice_to_text": "openai", | ||||
"text_to_voice": "openai", | "text_to_voice": "openai", | ||||
@@ -28,7 +28,6 @@ | |||||
"speech_recognition": true, | "speech_recognition": true, | ||||
"group_speech_recognition": false, | "group_speech_recognition": false, | ||||
"voice_reply_voice": false, | "voice_reply_voice": false, | ||||
"tts_voice_id": "alloy", | |||||
"conversation_max_tokens": 2500, | "conversation_max_tokens": 2500, | ||||
"expires_in_seconds": 3600, | "expires_in_seconds": 3600, | ||||
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。", | "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。", | ||||
@@ -16,7 +16,7 @@ available_setting = { | |||||
"open_ai_api_base": "https://api.openai.com/v1", | "open_ai_api_base": "https://api.openai.com/v1", | ||||
"proxy": "", # openai使用的代理 | "proxy": "", # openai使用的代理 | ||||
# chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称 | # 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 | "use_azure_chatgpt": False, # 是否使用azure的chatgpt | ||||
"azure_deployment_id": "", # azure 模型部署名称 | "azure_deployment_id": "", # azure 模型部署名称 | ||||
"azure_api_version": "", # azure api版本 | "azure_api_version": "", # azure api版本 | ||||
@@ -52,7 +52,7 @@ available_setting = { | |||||
"top_p": 1, | "top_p": 1, | ||||
"frequency_penalty": 0, | "frequency_penalty": 0, | ||||
"presence_penalty": 0, | "presence_penalty": 0, | ||||
"request_timeout": 60, # chatgpt请求超时时间,openai接口默认设置为600,对于难问题一般需要较长时间 | |||||
"request_timeout": 180, # chatgpt请求超时时间,openai接口默认设置为600,对于难问题一般需要较长时间 | |||||
"timeout": 120, # chatgpt重试超时时间,在这个时间内,将会自动重试 | "timeout": 120, # chatgpt重试超时时间,在这个时间内,将会自动重试 | ||||
# Baidu 文心一言参数 | # Baidu 文心一言参数 | ||||
"baidu_wenxin_model": "eb-instant", # 默认使用ERNIE-Bot-turbo模型 | "baidu_wenxin_model": "eb-instant", # 默认使用ERNIE-Bot-turbo模型 | ||||
@@ -25,7 +25,8 @@ | |||||
"summary": { | "summary": { | ||||
"enabled": true, # 文档总结和对话功能开关 | "enabled": true, # 文档总结和对话功能开关 | ||||
"group_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字段即可。 | |||||
#### 限制 | #### 限制 | ||||