mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-14 05:03:43 +08:00
update plugins and env template for better usages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import md5 from "md5";
|
||||
import { getRandomUserAgent } from "./ua_tools";
|
||||
|
||||
const mixinKeyEncTab: number[] = [
|
||||
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
|
||||
@@ -45,14 +46,18 @@ export async function getWbiKeys(): Promise<{
|
||||
img_key: string;
|
||||
sub_key: string;
|
||||
}> {
|
||||
// check if process.env.BILIBILI_COOKIES is set
|
||||
if (!process.env.BILIBILI_COOKIES) {
|
||||
throw new Error(
|
||||
"Cookie not found. Please set BILIBILI_COOKIES environment variable.",
|
||||
);
|
||||
}
|
||||
const res: Response = await fetch(
|
||||
"https://api.bilibili.com/x/web-interface/nav",
|
||||
{
|
||||
headers: {
|
||||
// SESSDATA 字段
|
||||
Cookie: "SESSDATA=xxxxxx",
|
||||
"User-Agent":
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
|
||||
Cookie: process.env.BILIBILI_COOKIES,
|
||||
"User-Agent": getRandomUserAgent(),
|
||||
Referer: "https://www.bilibili.com/", //对于直接浏览器调用可能不适用
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Tool } from "@langchain/core/tools";
|
||||
import { getRandomUserAgent } from "./ua_tools";
|
||||
import { encWbi, getWbiKeys } from "./bili_wbi_tools";
|
||||
|
||||
export interface Headers {
|
||||
[key: string]: string;
|
||||
@@ -35,12 +34,24 @@ export class BilibiliMusicRecognitionTool extends Tool implements RequestTool {
|
||||
try {
|
||||
// let result = await this.doAcrcloudRecognitionUsingMetaprocAPI(searchQuery);
|
||||
// parse query
|
||||
const [videoAid, pid, targetSec] = query.split(",");
|
||||
var [videoAid, pid, targetSec] = query.split(",");
|
||||
// check if arguments are valid
|
||||
// is videoAid a string of numbers?
|
||||
if (!/^\d+$/.test(videoAid)) {
|
||||
if (!(/^\d+$/.test(videoAid) || /^av\d+$/.test(videoAid))) {
|
||||
throw new Error(
|
||||
"Invalid videoAid: It should be a string of numbers. If a BVid or a short link is given, please convert it to Aid using av{BVid} format using BiliVideoInfo tool.",
|
||||
"Invalid videoAid: It should be a string of numbers. If a BVid or a short link is given, please convert it to Aid using av{Aid} format using BiliVideoInfo tool.",
|
||||
);
|
||||
}
|
||||
if (videoAid.startsWith("av")) videoAid = videoAid.slice(2);
|
||||
|
||||
if (!/^\d+$/.test(pid)) {
|
||||
throw new Error(
|
||||
"Invalid pid: it should be a number representing the page number of the video, starting from 1.",
|
||||
);
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(targetSec)) {
|
||||
throw new Error(
|
||||
"Invalid targetSec: it should be a number representing the time in seconds where the recognition is expected to start from.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,9 +73,13 @@ export class BilibiliMusicRecognitionTool extends Tool implements RequestTool {
|
||||
pid: number,
|
||||
targetSec: number,
|
||||
) {
|
||||
// get http://10.0.1.3:32345/api/recog_music_in_bili_video?video_aid=170001&pid=1&target_sec=14
|
||||
// TODO open-source the forwarding server, and put the server address in an environment variable
|
||||
const url = `http://10.0.1.3:32345/api/recog_music_in_bili_video?video_aid=${videoAid}&pid=${pid}&target_sec=${targetSec}`;
|
||||
if (!process.env.BILIVID_METAPROCESS_SERVER_ADDRESS) {
|
||||
throw new Error(
|
||||
"BILIVID_METAPROCESS_SERVER_ADDRESS environment variable is not set. Please set it to the address of the BiliVid metaprocess server.",
|
||||
);
|
||||
}
|
||||
// for reference: https://github.com/fred913/bilivid-metaprocess-server
|
||||
const url = `http://${process.env.BILIVID_METAPROCESS_SERVER_ADDRESS}/api/recog_music_in_bili_video?video_aid=${videoAid}&pid=${pid}&target_sec=${targetSec}`;
|
||||
|
||||
const headers = {
|
||||
"User-Agent": getRandomUserAgent(),
|
||||
|
||||
@@ -35,7 +35,6 @@ export class BilibiliVideoConclusionTool extends Tool implements RequestTool {
|
||||
try {
|
||||
var [videoAid, pid] = query.split(",");
|
||||
// check if arguments are valid
|
||||
// is videoAid a string of numbers?
|
||||
if (!(/^\d+$/.test(videoAid) || /^av\d+$/.test(videoAid))) {
|
||||
throw new Error(
|
||||
"Invalid videoAid: It should be a string of numbers. If a BVid or a short link is given, please convert it to Aid using av{Aid} format using BiliVideoInfo tool.",
|
||||
|
||||
@@ -57,8 +57,8 @@ export class NodeJSTool {
|
||||
const pdfBrowserTool = new PDFBrowser(this.model, this.embeddings);
|
||||
const bilibiliVideoInfoTool = new BilibiliVideoInfoTool();
|
||||
const bilibiliVideoSearchTool = new BilibiliVideoSearchTool();
|
||||
const bilibiliMusicRecognitionTool = new BilibiliMusicRecognitionTool();
|
||||
const bilibiliVideoConclusionTool = new BilibiliVideoConclusionTool();
|
||||
const bilibiliMusicRecognitionTool = new BilibiliMusicRecognitionTool();
|
||||
let tools = [
|
||||
calculatorTool,
|
||||
webBrowserTool,
|
||||
|
||||
Reference in New Issue
Block a user