feat: add wolframAlpha plugin

This commit is contained in:
Hk-Gosuto
2023-12-29 19:00:01 +08:00
parent 4551abdce8
commit 2a9b36f626
4 changed files with 40 additions and 6 deletions

View File

@@ -16,7 +16,7 @@ import { ACCESS_CODE_PREFIX, ServiceProvider } from "@/app/constant";
import * as langchainTools from "langchain/tools";
import { HttpGetTool } from "@/app/api/langchain-tools/http_get";
import { DuckDuckGo } from "@/app/api/langchain-tools/duckduckgo_search";
import { DynamicTool, Tool } from "langchain/tools";
import { DynamicTool, Tool, WolframAlphaTool } from "langchain/tools";
import { BaiduSearch } from "@/app/api/langchain-tools/baidu_search";
import { GoogleSearch } from "@/app/api/langchain-tools/google_search";
import { useAccessStore } from "@/app/store";
@@ -282,6 +282,16 @@ export class AgentApi {
var tool = langchainTools[
toolName as keyof typeof langchainTools
] as any;
if (
toolName === "wolfram_alpha" &&
process.env.WOLFRAM_ALPHA_APP_ID
) {
const tool = new WolframAlphaTool({
appid: process.env.WOLFRAM_ALPHA_APP_ID,
});
tools.push(tool);
return;
}
if (tool) {
tools.push(new tool());
}
@@ -387,7 +397,6 @@ export class AgentApi {
[handler],
);
console.log("returning response");
return new Response(this.transformStream.readable, {
headers: { "Content-Type": "text/event-stream" },
});

View File

@@ -84,4 +84,15 @@ export const CN_PLUGINS: BuiltinPlugin[] = [
enable: false,
onlyNodeRuntime: true,
},
{
name: "WolframAlphaTool",
toolName: "wolfram_alpha",
lang: "cn",
description:
"在需要回答有关数学、科学、技术、文化、社会和日常生活的问题时非常有用。",
builtin: true,
createdAt: 1703846656000,
enable: false,
onlyNodeRuntime: false,
},
];

View File

@@ -87,4 +87,15 @@ export const EN_PLUGINS: BuiltinPlugin[] = [
enable: false,
onlyNodeRuntime: true,
},
{
name: "WolframAlphaTool",
toolName: "wolfram_alpha",
lang: "en",
description:
"Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life.",
builtin: true,
createdAt: 1703846656000,
enable: false,
onlyNodeRuntime: false,
},
];