Giter Club home page Giter Club logo

biligpthelper's Introduction

✨Bilibili GPT Bot✨

把ChatGPT放到B站里!更高效、快速的了解视频内容

Python 3.11 License: MIT wakatime release_docker

🌟 介绍

b站那种AI课代表都见过吧?看起来超级酷!所以我也搞了个捏

📜 声明

当你查阅、下载了本项目源代码或二进制程序,即代表你接受了以下条款:

  1. 本项目和项目成果仅供技术,学术交流和Python3性能测试使用\
  2. 本项目贡献者编写该项目旨在学习Python3 ,提高编程水平\
  3. 用户在使用本项目和项目成果前,请用户了解并遵守当地法律法规,如果本项目及项目成果使用过程中存在违反当地法律法规的行为,请勿使用该项目及项目成果\
  4. 法律后果及使用后果由使用者承担\
  5. 开发者(yanyao2333)不会 将任何用户的cookie、个人信息收集上传至除b站官方的其他平台或服务器。同时,开发者(yanyao2333)不对任何造成的后果负责(包括但不限于账号封禁等后果),如有顾虑,请谨慎使用

若用户不同意上述条款任意一条请勿使用本项目和项目成果

😎 特性

  • 使用大模型生成总结、根据视频内容向ai提出问题
  • 已支持Claude、Openai大语言模型
  • 已支持openai的whisper和本地whisper语音转文字
  • 支持热插拔的asr和llm模块,基于优先级和运行稳定情况调度
  • 优化prompt,达到更好的效果、更高的信息密度,尽量不再说废话。还可以让LLM输出自己的思考、评分,让摘要更有意思
  • 支持llm返回消息格式不对自动修复
  • 支持艾特和私信两种触发方式
  • 支持视频缓存,避免重复生成
  • 可自动检测和刷新b站cookie(实验性功能)
  • 支持自定义触发关键词
  • 支持保存当前处理进度,下次启动时恢复
  • 支持一键生成并不精美的运行报告,包含一些图表

🚀 使用方法

一、通过docker运行

现在有两个版本的docker,代码都是最新版本,只是包不一样:

  1. latest 这个版本不包含whisper,也就是只能用来总结包含字幕的视频。这个镜像只有200多m,适合偶尔使用
  2. with_whisper 这个版本包含whisper,大小达到了2g,但是可以使用本地语音转文字生成字幕
docker pull yanyaobbb/bilibili_gpt_helper:latest
或
yanyaobbb/bilibili_gpt_helper:with_whisper
docker run -d \
    --name biligpthelper \
    -v 你本地的biligpt配置文件目录:/data \
    yanyaobbb/bilibili_gpt_helper:latest(with_whisper)

首次运行会创建模板文件,编辑config.yml,然后重启容器即可

二、源代码运行

  1. 克隆并安装依赖
git clone https://github.com/yanyao2333/BiliGPTHelper.git
cd BiliGPTHelper
pip install -r requirements.txt
  1. 编辑config.yml

  2. 运行,等待初始化完成

python main.py

触发命令

私信

方式一:转发视频+发送一条包含关键词的消息(向ai提问的方式与下面讲的相同)
方式二:发送消息:视频bv号+关键词 视频bv号必须要在消息最前面!

向ai提问,需要使用 提问关键词[冒号]你的问题 的格式 eg.BVxxxxxxxxxx 问一下:这视频有啥特色
获取视频摘要,单独发送摘要关键词即可

at

在评论区发送关键字即可
(向ai提问的方式与上面讲的相同)
但是你b评论区风控真的太严格了,体验完全没私信好,还污染评论区(所以,你懂我意思了吧)

💸 这玩意烧钱吗

Claude

claude才是唯一真神!!!比gpt-3.5-turbo-16k低将近一半的价格(指prompt价格),还有100k的上下文窗口!输出的格式也很稳定,内容质量与3.5不相上下。

现在对接了个aiproxy的claude接口,简直香炸...gpt3.5是什么?真不熟

GPT

根据我的测试,单纯使用gpt-3.5-turbo-16k,20元大概能撑起5000次时长为10min左右的视频总结(在不包括格式不对重试的情况下)

但在我的测试中,gpt3.5返回的内容已经十分稳定,我并没有遇到过格式不对的情况,所以这个价格应该是可以接受的

如果你出现了格式不对的情况,可以附带bad case示例发issue,我尝试优化下prompt

OPENAI WHISPER

相比之下这个有点贵,20元能转大概8小时视频

🤔 目前问题

  1. 无法回复楼中楼评论的at(我实在搞不懂评论的继承逻辑是什么,设置值了对应id也没法发送楼中楼,我好笨)
  2. 不支持多p视频的总结(这玩意我觉得没法修复,本来都是快要被你b抛弃的东西)
  3. 你b严格的审查机制导致私信/回复消息触碰敏感词会被屏蔽

📝 TODO

  • 支持多账号负载均衡 (on progress)
  • 能够画思维导图(拜托,这真的超酷的好嘛)

❤ 感谢

Nemo2011/bilibili-api | 封装b站api库 JetBrains | 感谢JetBrains提供的免费license

📚 大致流程(更详细内容指路 开发文档

sequenceDiagram
    participant 用户
    participant 监听器
    participant 处理链
    participant 发送器
    participant LLMs
    participant ASRs
    用户 ->> 监听器: 发送私信或at消息消息
    alt 消息触发关键词
        监听器 ->> 处理链: 触发关键词,开始处理
    else 消息不触发关键词
        监听器 ->> 用户: 不触发关键词,不处理
    end
    处理链 ->> 处理链: 检查是否有缓存
    alt 有缓存
        处理链 ->> 发送器: 有缓存,直接发送
    end
    处理链 ->> 处理链: 检查是否有字幕
    alt 有字幕
        处理链 ->> LLMs: 根据视频简介、标签、热评、字幕构建prompt并生成摘要
    else 没有字幕
        处理链 ->> ASRs: 转译视频
        ASRs ->> ASRs: 自动调度asr插件,选择一个发送请求
        ASRs ->> 处理链: 转译完成
        处理链 ->> LLMs: 根据视频简介、标签、热评、字幕构建prompt并生成摘要
    end
    LLMs ->> 处理链: 摘要内容
    处理链 ->> 处理链: 解析摘要是否符合要求
    alt 摘要符合要求
        处理链 ->> 发送器: 发送摘要
        发送器 ->> 用户: 发送成功
    else 摘要不符合要求
        处理链 ->> 处理链: 使用指定prompt修复摘要
        处理链 ->> 发送器: 发送摘要
        发送器 ->> 用户: 发送成功
    end

biligpthelper's People

Contributors

fossabot avatar pawnzzi avatar yanyao2333 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

biligpthelper's Issues

新版本还在开发嘛?

最近闲下来了,看下下代码,好多都重构了,是还在重构中嘛?
把代码clone下来,好几个地方都在报错。好几处bug。

程序日志显示评论发送成功,但实际上bilibili里没有评论

发现两个问题:
1-同一个视频要第二次at才会发送评论、首次at只会写进缓存不会发送评论,第二次之后的at就去缓存读取数据发送了。
2-评论发送成功,调用发送评论接口成功了,拿到正确的响应,但是视频的评论中没有这条评论,不知道是不是阿b秒删,还是程序问题。

项目启动起来了,

目前遇到几个问题:
第一个报错:
Job "Session.run.<locals>.qurey (trigger: interval[0:00:06], next run at: 2024-02-17 14:49:17 CST)" raised an exception Traceback (most recent call last): File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\apscheduler\executors\base_py3.py", line 30, in run_coroutine_job retval = await job.func(*job.args, **job.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\bilibili_api\session.py", line 502, in qurey js: dict = await new_sessions(self.credential, self.maxTs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\bilibili_api\session.py", line 79, in new_sessions return await Api(**api, credential=credential).update_params(**params).result ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\bilibili_api\utils\network.py", line 273, in result self.__result = await self.request() ^^^^^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\bilibili_api\utils\network.py", line 173, in inner return await func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\bilibili_api\utils\network.py", line 553, in request async with session.request(**config) as resp: File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\aiohttp\client.py", line 1194, in __aenter__ self._resp = await self._coro ^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\aiohttp\client.py", line 605, in _request await resp.start(conn) File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\aiohttp\client_reqrep.py", line 966, in start message, payload = await protocol.read() # type: ignore[union-attr] ^^^^^^^^^^^^^^^^^^^^^ File "E:\biliGPT\v3\BiliGPTHelper\venv\Lib\site-packages\aiohttp\streams.py", line 622, in read await self._waiter aiohttp.client_exceptions.ClientOSError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接。
项目启动之后会一直循环报这个错,疑似新版bilibiliapi的问题?

第二个报错:bili_linsten.py文件中
for item in reversed(data["items"]): if item["at_time"] > self.last_at_time: _LOGGER.debug(f"at_time{item['at_time']}大于last_at_time{self.last_at_time},放入新消息队列") item["user"] = data["items"]["user"] new_items.append(item)
item["user"] = data["items"]["user"] 这行代码应该注释掉吧?不然逻辑不通,不注释也会报错。

第三个报错:bili_linsten.py文件中
原代码:
`async def build_task_from_at_msg(self, msg: dict) -> BiliGPTTask | None:
try:
event = deepcopy(msg)
if msg["type"] != "reply" or msg["business_id"] != 1:
_LOGGER.warning("不是回复消息,跳过")
return None
elif msg["item"]["root_id"] == 0 and msg["item"]["target_id"] == 0:
_LOGGER.warning("该消息是楼中楼消息,暂时不受支持,跳过处理")
return None
event["source_type"] = "bili_comment"
event["raw_task_data"] = deepcopy(msg)
event["source_extra_attr"] = BiliAtSpecialAttributes.model_validate(event)
event["sender_id"] = event["user"]["mid"]
event["video_url"] = event["uri"]
event["source_command"] = event["source_content"]
event["video_id"] = await BiliVideo(url=event["uri"]).bvid
task_metadata = BiliGPTTask.model_validate(event)
except Exception:
traceback.print_exc()
_LOGGER.error("在验证任务数据结构时出现错误,跳过处理!")
return None

    return task_metadata`

本地修改后:
` async def build_task_from_at_msg(self, msg: dict) -> BiliGPTTask | None:
try:
event = deepcopy(msg)
if msg["item"]["type"] != "reply" or msg["item"]["business_id"] != 1:
_LOGGER.warning("不是回复消息,跳过")
return None
elif msg["item"]["root_id"] != 0 or msg["item"]["target_id"] != 0:
_LOGGER.warning("该消息是楼中楼消息,暂时不受支持,跳过处理")
return None
event["source_type"] = "bili_comment"
event["raw_task_data"] = deepcopy(msg)
event["source_extra_attr"] = BiliAtSpecialAttributes.model_validate(event["item"])
event["sender_id"] = str(event["user"]["mid"])
event["video_url"] = event["item"]["uri"]
event["source_command"] = event["item"]["source_content"]
event["video_id"] = await BiliVideo(credential=self.credential, url=event["item"]["uri"]).bvid
task_metadata = BiliGPTTask.model_validate(event)
except Exception as e:
traceback.print_exc()
_LOGGER.error(e)
_LOGGER.error("在验证任务数据结构时出现错误,跳过处理!")
return None

    return task_metadata`

这个是我本地修改之后的代码,第二个问题的循环结束后会调用这个方法,参数是new_items循环的item
结合上面的逻辑所以好几处的值都是在event['item']中,楼中楼的判断值不等0才是。
但是修改完后执行到event["video_id"] = await BiliVideo(credential=self.credential, url=event["item"]["uri"]).bvid的时候直接捕获异常了,提示请求超时。
以上是遇到的几个问题,能启动,但是跑不通。都是在调用bilibliapi时报错,不知道是新版本的api问题还是账号问题,晚些换个账号再测试下。不清楚你的逻辑,上述问题是否存在我所说的bug,如是,我晚些提个PR

cookie刷新失败的问题找到了

requirements.txt中bilibili-api-python依赖替换成bilibili-api-dev就可以了。这个项目分支解决了这个问题,开发者的代码少了个右括号

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.