feat: add arxiv plugin (#55)

This commit is contained in:
Hk-Gosuto
2023-11-06 04:21:52 -06:00
committed by GitHub
parent 7a3f6f83da
commit d41b7d3f95
6 changed files with 131 additions and 32 deletions

View File

@@ -22,6 +22,7 @@ import { DallEAPIWrapper } from "@/app/api/langchain-tools/dalle_image_generator
import { BaiduSearch } from "@/app/api/langchain-tools/baidu_search";
import { GoogleSearch } from "@/app/api/langchain-tools/google_search";
import { StableDiffusionWrapper } from "@/app/api/langchain-tools/stable_diffusion_image_generator";
import { ArxivAPIWrapper } from "@/app/api/langchain-tools/arxiv";
const serverConfig = getServerSideConfig();
@@ -95,8 +96,8 @@ async function handle(req: NextRequest) {
const handler = BaseCallbackHandler.fromMethods({
async handleLLMNewToken(token: string) {
// console.log("[Token]", token);
if (token) {
console.log("[Token]", token);
var response = new ResponseBody();
response.message = token;
await writer.ready;
@@ -151,8 +152,7 @@ async function handle(req: NextRequest) {
if (!reqBody.returnIntermediateSteps) return;
var response = new ResponseBody();
response.isToolMessage = true;
let toolInput = <ToolInput>(<unknown>action.toolInput);
response.message = toolInput.input;
response.message = JSON.stringify(action.toolInput);
response.toolName = action.tool;
await writer.ready;
await writer.write(
@@ -230,12 +230,14 @@ async function handle(req: NextRequest) {
const calculatorTool = new Calculator();
const dallEAPITool = new DallEAPIWrapper(apiKey, baseUrl);
const stableDiffusionTool = new StableDiffusionWrapper();
const arxivAPITool = new ArxivAPIWrapper();
if (useTools.includes("web-search")) tools.push(searchTool);
if (useTools.includes(webBrowserTool.name)) tools.push(webBrowserTool);
if (useTools.includes(calculatorTool.name)) tools.push(calculatorTool);
if (useTools.includes(dallEAPITool.name)) tools.push(dallEAPITool);
if (useTools.includes(stableDiffusionTool.name))
tools.push(stableDiffusionTool);
if (useTools.includes(arxivAPITool.name)) tools.push(arxivAPITool);
useTools.forEach((toolName) => {
if (toolName) {