Skip to content

Commit

Permalink
feat: web browser tool (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisotee authored Mar 4, 2024
1 parent d21d73c commit 0fe77ae
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whatsapp-ai-assistant",
"version": "2.2.2",
"version": "2.3.0",
"description": "WhatsApp chatbot",
"module": "src/index.ts",
"type": "module",
Expand Down Expand Up @@ -36,6 +36,8 @@
"@types/common-tags": "^1.8.2",
"@types/node-schedule": "^2.1.1",
"@waylaidwanderer/chatgpt-api": "github:Luisotee/node-chatgpt-api",
"axios": "^1.6.7",
"cheerio": "1.0.0-rc.12",
"common-tags": "^1.8.2",
"dayjs": "^1.11.10",
"dotenv": "^16.3.1",
Expand Down
135 changes: 133 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion src/clients/tools-openrouter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { SearchApi } from "@langchain/community/tools/searchapi";
import {
OPENROUTER_API_KEY,
SEARCH_API
} from "../constants";
import { WebBrowser } from "langchain/tools/webbrowser";
import { ChatOpenAI, OpenAIEmbeddings } from "@langchain/openai";

const OPENROUTER_BASE_URL = "https://openrouter.ai";

const model = new ChatOpenAI(
{
modelName: "openai/gpt-3.5-turbo",
temperature: 0,
openAIApiKey: OPENROUTER_API_KEY,
},
{
basePath: `${OPENROUTER_BASE_URL}/api/v1`,
}
);

const embeddings = new OpenAIEmbeddings();

let searchTool = null;
if (SEARCH_API !== '') {
Expand All @@ -10,5 +28,7 @@ if (SEARCH_API !== '') {
});
}

export const tools = searchTool ? [searchTool] : [];
const webBrowserTool = new WebBrowser({ model, embeddings });

export const tools = [...(searchTool ? [searchTool] : []), webBrowserTool];
export const toolNames = tools.map((tool) => tool.name);

0 comments on commit 0fe77ae

Please sign in to comment.