瀏覽代碼

等待回应开关

develop
H Vs 2 月之前
父節點
當前提交
ffc9308794
共有 4 個檔案被更改,包括 12 行新增8 行删除
  1. +4
    -3
      common/utils.py
  2. +1
    -1
      docker/Dockerfile.latest
  3. +5
    -3
      resources/messages_resource.py
  4. +2
    -1
      wechat/biz.py

+ 4
- 3
common/utils.py 查看文件

@@ -14,7 +14,7 @@ from voice import audio_convert
import cv2
import os
import tempfile
from moviepy import VideoFileClip
from moviepy.editor import VideoFileClip

from common import redis_helper

@@ -362,6 +362,7 @@ def download_video_and_get_thumbnail(url, thumbnail_path):
异常:
可能抛出requests.exceptions.RequestException,cv2.error,IOError等异常。
"""
logger.info("处理视频开始")
# 创建临时目录以下载视频
with tempfile.TemporaryDirectory() as tmp_dir:
# 下载视频到临时文件
@@ -393,7 +394,7 @@ def download_video_and_get_thumbnail(url, thumbnail_path):
clip = VideoFileClip(video_path)
duration = clip.duration
clip.close()
logger.info("处理视频完成")
# OSS 配置(建议将凭证存储在安全的地方)
oss_access_key_id="LTAI5tRTG6pLhTpKACJYoPR5"
oss_access_key_secret="E7dMzeeMxq4VQvLg7Tq7uKf3XWpYfN"
@@ -404,7 +405,7 @@ def download_video_and_get_thumbnail(url, thumbnail_path):
# 上传文件到 OSS
file_path = thumbnail_path
file_url = upload_oss(oss_access_key_id, oss_access_key_secret, oss_endpoint, oss_bucket_name, file_path, oss_prefix)
logger.info("上传缩略图")
# 删除临时文件
try:
os.remove(thumbnail_path)


+ 1
- 1
docker/Dockerfile.latest 查看文件

@@ -25,7 +25,7 @@ RUN apt-get update \
&& cd ${BUILD_PREFIX} \
&& cp config-template.json config.json \
&& /usr/local/bin/python -m pip install --no-cache --upgrade pip \
&& pip install --no-cache -r requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
&& pip install --no-cache -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

WORKDIR ${BUILD_PREFIX}



+ 5
- 3
resources/messages_resource.py 查看文件

@@ -226,7 +226,7 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
# 设置定时器,1秒后检查任务是否超时。这里需要使用 lambda 来传递参数
timeout_timer = threading.Timer(
timeout_duration,
lambda:check_timeout(task_thread, token_id, app_id, callback_to_user)
lambda:check_timeout(task_thread, token_id, wxid,app_id, callback_to_user)
)
timeout_timer.start()

@@ -235,10 +235,12 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
# 取消定时器
timeout_timer.cancel()

def check_timeout( task_thread:threading.Thread, token_id, app_id, callback_to_user):
def check_timeout( task_thread:threading.Thread, token_id,wxid, app_id, callback_to_user):
if task_thread.is_alive():
print(f"任务运行时间超过{timeout_duration}秒,token_id={token_id}, app_id={app_id}, callback_to_user={callback_to_user}")
gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,"亲,我正在组织回复的信息,请稍等一会")
wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid)
if bool(wx_config.get("chatWaitingMsgEnabled",True)):
gewe_chat.wxchat.post_text(token_id,app_id,callback_to_user,"亲,我正在组织回复的信息,请稍等一会")

def ai_chat_text(token_id,app_id,wxid,msg_data,msg_content):
start_time = time.time() # 记录任务开始时间


+ 2
- 1
wechat/biz.py 查看文件

@@ -240,8 +240,9 @@ def send_video_message(wxchat:gewe_chat.GeWeChatCom, token_id, app_id, agent_wxi
filename = os.path.basename(parsed_url.path)
tmp_file_path = os.path.join(os.getcwd(),'tmp', filename) # 拼接完整路径
thumbnail_path=tmp_file_path.replace('.mp4','.jpg')
video_duration,video_thumb_url =utils.download_video_and_get_thumbnail(file_url,thumbnail_path)
video_thumb_url,video_duration =utils.download_video_and_get_thumbnail(file_url,thumbnail_path)

print(f'视频缩略图 {video_thumb_url} 时长 {video_duration}')
if wxchat.forward_video_aeskey == '':
ret,ret_msg,res = wxchat.post_video(token_id, app_id, t, file_url,video_thumb_url,video_duration)
if ret==200:


Loading…
取消
儲存