Skip to content
Snippets Groups Projects
Commit c47ed4e8 authored by thucpn's avatar thucpn
Browse files

revert wiki (update in another PR)

parent c6eee12e
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,6 @@ export * from "./tools/img-gen";
export * from "./tools/interpreter";
export * from "./tools/openapi-action";
export * from "./tools/weather";
export * from "./tools/wikipedia";
export * from "./tools/wiki";
export * from "./tool-call";
import { tool } from "@llamaindex/core/tools";
import { default as wiki } from "wikipedia";
import { default as wikipedia } from "wikipedia";
import { z } from "zod";
export type WikiToolOutput = {
......@@ -7,7 +7,7 @@ export type WikiToolOutput = {
content: string;
};
export const wikipedia = () => {
export const wiki = () => {
return tool({
name: "wikipedia",
description: "Use this function to search Wikipedia",
......@@ -16,11 +16,11 @@ export const wikipedia = () => {
lang: z.string().describe("The language to search in").default("en"),
}),
execute: async ({ query, lang }): Promise<WikiToolOutput> => {
wiki.setLang(lang);
const searchResult = await wiki.search(query);
wikipedia.setLang(lang);
const searchResult = await wikipedia.search(query);
const pageTitle = searchResult?.results[0]?.title;
if (!pageTitle) return { title: "No search results.", content: "" };
const result = await wiki.page(pageTitle, { autoSuggest: false });
const result = await wikipedia.page(pageTitle, { autoSuggest: false });
return { title: pageTitle, content: await result.content() };
},
});
......
import { describe, expect, test } from "vitest";
import { wikipedia } from "../src/tools/wikipedia";
import { wiki } from "../src/tools/wiki";
describe("Wikipedia Tool", () => {
test("wiki tool returns content for valid query", async () => {
const wikipediaTool = wikipedia();
const result = await wikipediaTool.call({
const wikiTool = wiki();
const result = await wikiTool.call({
query: "Albert Einstein",
lang: "en",
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment