mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-04 07:41:50 +08:00
feat(core): add web search tool and reasoning params (#11912)
Close [AI-60](https://linear.app/affine-design/issue/AI-60). ### What changed? - Add Exa web search tool - Add reasoning params
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export * from './web-search';
|
||||
@@ -0,0 +1,35 @@
|
||||
import { tool } from 'ai';
|
||||
import Exa from 'exa-js';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Config } from '../../../base';
|
||||
|
||||
export const createExaTool = (config: Config) => {
|
||||
return tool({
|
||||
description: 'Search the web for information',
|
||||
parameters: z.object({
|
||||
query: z.string().describe('The query to search the web for.'),
|
||||
mode: z
|
||||
.enum(['MUST', 'CAN'])
|
||||
.optional()
|
||||
.describe('The mode to search the web for.'),
|
||||
}),
|
||||
execute: async ({ query, mode }) => {
|
||||
const { key } = config.copilot.exa;
|
||||
const exa = new Exa(key);
|
||||
const result = await exa.searchAndContents(query, {
|
||||
numResults: 10,
|
||||
summary: true,
|
||||
livecrawl: mode === 'MUST' ? 'always' : undefined,
|
||||
});
|
||||
return result.results.map(data => ({
|
||||
title: data.title,
|
||||
url: data.url,
|
||||
summary: data.summary,
|
||||
favicon: data.favicon,
|
||||
publishedDate: data.publishedDate,
|
||||
author: data.author,
|
||||
}));
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user