From 05ad0846f8e0bd5d1df9f4fc9647dc33256b9243 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 10 Feb 2025 12:10:59 -0800 Subject: [PATCH] Consolidated separate tavily blocks into one --- blocks/blocks/tavily.ts | 149 ++++++++++++++++++++-------------------- blocks/index.ts | 8 +-- tools/tavily/types.ts | 29 ++++++++ 3 files changed, 107 insertions(+), 79 deletions(-) create mode 100644 tools/tavily/types.ts diff --git a/blocks/blocks/tavily.ts b/blocks/blocks/tavily.ts index c69957e3b..05aa289ba 100644 --- a/blocks/blocks/tavily.ts +++ b/blocks/blocks/tavily.ts @@ -1,104 +1,70 @@ import { TavilyIcon } from '@/components/icons' -import { ExtractResponse } from '@/tools/tavily/extract' -import { SearchResponse } from '@/tools/tavily/search' +import { TavilyExtractResponse, TavilySearchResponse } from '@/tools/tavily/types' import { BlockConfig } from '../types' -export const TavilySearchBlock: BlockConfig = { - type: 'tavily_search', - toolbar: { - title: 'Tavily Search', - description: 'Search the web using Tavily AI', - bgColor: '#0066FF', - icon: TavilyIcon, - category: 'tools', - }, - tools: { - access: ['tavily_search'], - }, - workflow: { - inputs: { - query: { type: 'string', required: true }, - apiKey: { type: 'string', required: true }, - max_results: { type: 'number', required: false }, - }, - outputs: { - response: { - type: { - query: 'string', - results: 'json', - response_time: 'number', - }, - }, - }, - subBlocks: [ - { - id: 'query', - title: 'Search Query', - type: 'short-input', - layout: 'full', - placeholder: 'Enter your search query...', - }, - { - id: 'max_results', - title: 'Max Results', - type: 'dropdown', - layout: 'half', - options: ['5', '10', '15', '20'], - }, - { - id: 'apiKey', - title: 'API Key', - type: 'short-input', - layout: 'full', - placeholder: 'Enter your Tavily API key', - password: true, - }, - ], - }, -} +type TavilyResponse = TavilySearchResponse | TavilyExtractResponse -export const TavilyExtractBlock: BlockConfig = { - type: 'tavily_extract', +export const TavilyBlock: BlockConfig = { + type: 'tavily_block', toolbar: { - title: 'Tavily Extract', - description: 'Scrape website content', + title: 'Tavily', + description: 'Search and extract information using Tavily AI', bgColor: '#0066FF', icon: TavilyIcon, category: 'tools', }, tools: { - access: ['tavily_extract'], + access: ['tavily_search', 'tavily_extract'], + config: { + tool: (params) => { + switch (params.operation) { + case 'tavily_search': + return 'tavily_search' + case 'tavily_extract': + return 'tavily_extract' + default: + return 'tavily_search' + } + }, + }, }, workflow: { inputs: { - urls: { type: 'string', required: true }, + operation: { type: 'string', required: true }, apiKey: { type: 'string', required: true }, + // Search operation + query: { type: 'string', required: false }, + maxResults: { type: 'number', required: false }, + // Extract operation + urls: { type: 'string', required: false }, extract_depth: { type: 'string', required: false }, }, outputs: { response: { type: { results: 'json', - failed_results: 'any', - response_time: 'number', + answer: 'any', + query: 'string', + content: 'string', + title: 'string', + url: 'string', }, }, }, subBlocks: [ + // Operation selector { - id: 'urls', - title: 'URL', - type: 'short-input', - layout: 'full', - placeholder: 'Enter URL to extract content from...', - }, - { - id: 'extract_depth', - title: 'Extract Depth', + id: 'operation', + title: 'Operation', type: 'dropdown', - layout: 'half', - options: ['basic', 'advanced'], + layout: 'full', + options: [ + { label: 'Search', id: 'tavily_search' }, + { label: 'Extract Content', id: 'tavily_extract' }, + ], + value: () => 'tavily_search', }, + // API Key (common) { id: 'apiKey', title: 'API Key', @@ -107,6 +73,41 @@ export const TavilyExtractBlock: BlockConfig = { placeholder: 'Enter your Tavily API key', password: true, }, + // Search operation inputs + { + id: 'query', + title: 'Search Query', + type: 'long-input', + layout: 'full', + placeholder: 'Enter your search query...', + condition: { field: 'operation', value: 'tavily_search' }, + }, + { + id: 'maxResults', + title: 'Max Results', + type: 'short-input', + layout: 'full', + placeholder: '5', + condition: { field: 'operation', value: 'tavily_search' }, + }, + // Extract operation inputs + { + id: 'urls', + title: 'URL', + type: 'long-input', + layout: 'full', + placeholder: 'Enter URL to extract content from...', + condition: { field: 'operation', value: 'tavily_extract' }, + }, + { + id: 'extract_depth', + title: 'Extract Depth', + type: 'dropdown', + layout: 'full', + options: ['basic', 'advanced'], + value: () => 'basic', + condition: { field: 'operation', value: 'tavily_extract' }, + }, ], }, } diff --git a/blocks/index.ts b/blocks/index.ts index dc39b2be0..ebf439332 100644 --- a/blocks/index.ts +++ b/blocks/index.ts @@ -12,7 +12,7 @@ import { NotionBlock } from './blocks/notion' import { RouterBlock } from './blocks/router' import { SerperBlock } from './blocks/serper' import { SlackMessageBlock } from './blocks/slack' -import { TavilyExtractBlock, TavilySearchBlock } from './blocks/tavily' +import { TavilyBlock } from './blocks/tavily' import { TranslateBlock } from './blocks/translate' import { XBlock } from './blocks/x' import { YouTubeSearchBlock } from './blocks/youtube' @@ -31,8 +31,7 @@ export { GitHubBlock, ConditionBlock, SerperBlock, - TavilySearchBlock, - TavilyExtractBlock, + TavilyBlock, RouterBlock, YouTubeSearchBlock, NotionBlock, @@ -54,8 +53,7 @@ const blocks: Record = { slack_message: SlackMessageBlock, github_repo_info: GitHubBlock, serper_search: SerperBlock, - tavily_search: TavilySearchBlock, - tavily_extract: TavilyExtractBlock, + tavily_block: TavilyBlock, youtube_search: YouTubeSearchBlock, notion_reader: NotionBlock, gmail_block: GmailBlock, diff --git a/tools/tavily/types.ts b/tools/tavily/types.ts new file mode 100644 index 000000000..9751a8acb --- /dev/null +++ b/tools/tavily/types.ts @@ -0,0 +1,29 @@ +import { ToolResponse } from '../types' + +export interface TavilySearchResult { + title: string + url: string + content: string + score: number + images?: string[] + raw_content?: string +} + +export interface TavilySearchResponse extends ToolResponse { + output: { + results: TavilySearchResult[] + answer?: string + query: string + images?: string[] + rawContent?: string + } +} + +export interface TavilyExtractResponse extends ToolResponse { + output: { + content: string + title: string + url: string + rawContent?: string + } +}