mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-13 12:43:42 +08:00
feat: rewrite WolframAlphaTool
This commit is contained in:
@@ -10,7 +10,7 @@ import { GoogleSearch } from "@/app/api/langchain-tools/google_search";
|
||||
import { Tool, DynamicTool } from "langchain/tools";
|
||||
import * as langchainTools from "langchain/tools";
|
||||
import { Embeddings } from "langchain/dist/embeddings/base.js";
|
||||
import { promises } from "dns";
|
||||
import { WolframAlphaTool } from "./wolframalpha";
|
||||
|
||||
export class EdgeTool {
|
||||
private apiKey: string | undefined;
|
||||
@@ -50,13 +50,16 @@ export class EdgeTool {
|
||||
);
|
||||
const stableDiffusionTool = new StableDiffusionWrapper();
|
||||
const arxivAPITool = new ArxivAPIWrapper();
|
||||
return [
|
||||
const wolframAlphaTool = new WolframAlphaTool();
|
||||
let tools = [
|
||||
// searchTool,
|
||||
calculatorTool,
|
||||
webBrowserTool,
|
||||
dallEAPITool,
|
||||
stableDiffusionTool,
|
||||
arxivAPITool,
|
||||
wolframAlphaTool,
|
||||
];
|
||||
return tools;
|
||||
}
|
||||
}
|
||||
|
||||
33
app/api/langchain-tools/wolframalpha.ts
Normal file
33
app/api/langchain-tools/wolframalpha.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Tool } from "langchain/tools";
|
||||
|
||||
export class WolframAlphaTool extends Tool {
|
||||
name = "wolfram_alpha_llm";
|
||||
|
||||
description = `A wrapper around Wolfram Alpha. Useful for when you need to answer questions about Math, Science, Technology, Culture, Society and Everyday Life. Input should be a search query. If the result contains an image link, use the markdown syntax to return the image.`;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
async _call(query: string) {
|
||||
const appid = process.env.WOLFRAM_ALPHA_APP_ID;
|
||||
if (!appid) {
|
||||
return "`WOLFRAM_ALPHA_APP_ID` Not configured";
|
||||
}
|
||||
const url = `https://www.wolframalpha.com/api/v1/llm-api?appid=${appid}&input=${encodeURIComponent(
|
||||
query,
|
||||
)}`;
|
||||
console.log("[WolframAlphaTool]", url);
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "GET",
|
||||
});
|
||||
const resText = await res.text();
|
||||
console.log(resText);
|
||||
return resText;
|
||||
} catch (ex) {
|
||||
console.error("[WolframAlphaTool]", ex);
|
||||
return "query error";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user