Skip to content

Commit

Permalink
feat: Wikipedia tool (#287)
Browse files Browse the repository at this point in the history
* feat: wikipedia tool, bug fix in not logged messages

* Update version to 2.6.0 in package.json
  • Loading branch information
Luisotee authored Mar 19, 2024
1 parent 045dd07 commit bd71bde
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whatsapp-ai-assistant",
"version": "2.5.0",
"version": "2.6.0",
"description": "WhatsApp chatbot",
"module": "src/index.ts",
"type": "module",
Expand Down
8 changes: 8 additions & 0 deletions src/clients/tools-openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
GoogleCalendarViewTool,
} from "@langchain/community/tools/google_calendar";
import { SearchApi } from "@langchain/community/tools/searchapi";
import { WikipediaQueryRun } from "@langchain/community/tools/wikipedia_query_run";
import { ChatOpenAI, DallEAPIWrapper, OpenAI, OpenAIEmbeddings } from "@langchain/openai";
import { Calculator } from "langchain/tools/calculator";
import { WebBrowser } from "langchain/tools/webbrowser";
Expand Down Expand Up @@ -81,12 +82,19 @@ if (SEARCH_API !== '') {

const calculatorTool = new Calculator()

const wikipediaTool = new WikipediaQueryRun({
topKResults: 3,
maxDocContentLength: 4000,
});


export const tools = [
...(searchTool ? [searchTool] : []),
...(webBrowserTool ? [webBrowserTool] : []),
...(googleCalendarCreateTool ? [googleCalendarCreateTool] : []),
...(googleCalendarViewTool ? [googleCalendarViewTool] : []),
...(dalleTool ? [dalleTool] : []),
wikipediaTool,
calculatorTool
];
export const toolNames = tools.map((tool) => tool.name);
2 changes: 1 addition & 1 deletion src/handlers/llm-models/completion-open-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Message } from "whatsapp-web.js";
import { createExecutorForOpenRouter } from "../../clients/open-router";
import {
BOT_PREFIX,
DEBUG_SUMMARY,
Expand All @@ -13,7 +14,6 @@ import {
updateOpenRouterConversation,
} from "../../crud/conversation";
import { handleAudioMessage } from "../audio-message";
import { createExecutorForOpenRouter } from "../../clients/open-router";

export async function getCompletionWithOpenRouter(
message: Message,
Expand Down
28 changes: 15 additions & 13 deletions src/handlers/message/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { Message } from "whatsapp-web.js";
import { setStatusFor } from "../../helpers/message";
import { createContextFromMessage } from "../context";
import {
getCompletionWithBing,
getSources,
getSuggestions,
} from "../llm-models/completion-bing.ts";
import { log } from "../../helpers/utils";
import {
BING_COOKIES,
BOT_PREFIX,
ENABLE_REMINDERS,
ENABLE_SOURCES,
ENABLE_SUGGESTIONS,
OPENROUTER_API_KEY,
OPENROUTER_API_KEY
} from "../../constants";
import { handleReminderFor } from "../reminder/reminder.ts";
import { getLLMModel, updateWaMessageId } from "../../crud/conversation";
import { setStatusFor } from "../../helpers/message";
import { log } from "../../helpers/utils";
import { createContextFromMessage } from "../context";
import {
getCompletionWithBing,
getSources,
getSuggestions,
} from "../llm-models/completion-bing.ts";
import { getCompletionWithOpenRouter } from "../llm-models/completion-open-router.ts";
import { handleReminderFor } from "../reminder/reminder.ts";

export async function handleMessage(message: Message) {
await log(message);
Expand Down Expand Up @@ -61,8 +60,11 @@ export async function handleMessage(message: Message) {

if (!response) throw new Error("No response from LLM");

// @ts-ignore
const finalReply = await streamingReply.edit(response);
let finalReply = null;

while (finalReply === null) {
finalReply = await streamingReply.edit(response);
}

await log(finalReply, true);
await setStatusFor(message, "done");
Expand Down

0 comments on commit bd71bde

Please sign in to comment.