MCPcopy Create free account
hub / github.com/SillyTavern/Extension-WebSearch / registerFunctionTools

Function registerFunctionTools

index.js:1505–1596  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1503}
1504
1505function registerFunctionTools() {
1506 try {
1507 const { registerFunctionTool, unregisterFunctionTool } = SillyTavern.getContext();
1508
1509 if (!registerFunctionTool || !unregisterFunctionTool) {
1510 console.log('WebSearch: Function tools are not supported');
1511 return;
1512 }
1513
1514 if (!extension_settings.websearch.use_function_tool || !extension_settings.websearch.enabled) {
1515 unregisterFunctionTool('WebSearch');
1516 unregisterFunctionTool('VisitLinks');
1517 return;
1518 }
1519
1520 const webSearchSchema = Object.freeze({
1521 $schema: 'http://json-schema.org/draft-04/schema#',
1522 type: 'object',
1523 properties: {
1524 query: {
1525 type: 'string',
1526 description: 'Web Query used in search engine.',
1527 },
1528 },
1529 required: [
1530 'query',
1531 ],
1532 });
1533
1534 const visitLinksSchema = Object.freeze({
1535 $schema: 'http://json-schema.org/draft-04/schema#',
1536 type: 'object',
1537 properties: {
1538 links: {
1539 type: 'array',
1540 items: {
1541 type: 'string',
1542 },
1543 description: 'Web links to visit.',
1544 },
1545 },
1546 required: [
1547 'links',
1548 ],
1549 });
1550
1551 registerFunctionTool({
1552 name: 'WebSearch',
1553 displayName: 'Web Search',
1554 description: 'Search the web and get the content of the relevant pages. Search for unknown knowledge, public personalities, up-to-date information, weather, news, etc.',
1555 parameters: webSearchSchema,
1556 formatMessage: (args) => args?.query ? `Searching the web for: ${args?.query}` : '',
1557 action: async (args) => {
1558 if (!args) throw new Error('No arguments provided');
1559 if (!args.query) throw new Error('No query provided');
1560 if (!(await isSearchAvailable())) throw new Error('Search is not available');
1561 const search = await performSearchRequest(args.query, { useCache: true });
1562 return search;

Callers 1

index.jsFile · 0.85

Calls 4

isSearchAvailableFunction · 0.85
performSearchRequestFunction · 0.85
isAllowedUrlFunction · 0.85
visitLinkFunction · 0.85

Tested by

no test coverage detected