-
-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Add Scavio tool node #6595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
scavio-ai
wants to merge
4
commits into
FlowiseAI:main
Choose a base branch
from
scavio-ai:feat/scavio-tool-node
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+234
−0
Open
Add Scavio tool node #6595
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { INodeParams, INodeCredential } from '../src/Interface' | ||
|
|
||
| class ScavioApi implements INodeCredential { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| description: string | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Scavio API' | ||
| this.name = 'scavioApi' | ||
| this.version = 1.0 | ||
| this.description = | ||
| 'Scavio is a real-time search API for AI agents. Get an API key at https://dashboard.scavio.dev' | ||
| this.inputs = [ | ||
| { | ||
| label: 'Scavio API Key', | ||
| name: 'scavioApiKey', | ||
| type: 'password' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { credClass: ScavioApi } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| import { Tool } from '@langchain/core/tools' | ||
| import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' | ||
| import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' | ||
| import { secureAxiosRequest } from '../../../src/httpSecurity' | ||
|
|
||
| interface ScavioSearchParams { | ||
| apiKey: string | ||
| searchType?: string | ||
| countryCode?: string | ||
| language?: string | ||
| device?: string | ||
| lightRequest?: boolean | ||
| page?: number | ||
| } | ||
|
|
||
| class ScavioSearchTool extends Tool { | ||
| name = 'scavio_search' | ||
| description = | ||
| 'Real-time web search via Scavio. Input should be a plain search query string. Returns Google results (title, url, description) as JSON.' | ||
|
|
||
| apiKey: string | ||
| searchType?: string | ||
| countryCode?: string | ||
| language?: string | ||
| device?: string | ||
| lightRequest?: boolean | ||
| page?: number | ||
|
|
||
| constructor(fields: ScavioSearchParams) { | ||
| super() | ||
| this.apiKey = fields.apiKey | ||
| this.searchType = fields.searchType | ||
| this.countryCode = fields.countryCode | ||
| this.language = fields.language | ||
| this.device = fields.device | ||
| this.lightRequest = fields.lightRequest | ||
| this.page = fields.page | ||
| } | ||
|
|
||
| async _call(input: string): Promise<string> { | ||
| const body: Record<string, any> = { query: input } | ||
| if (this.searchType) body.search_type = this.searchType | ||
| if (this.countryCode) body.country_code = this.countryCode | ||
| if (this.language) body.language = this.language | ||
| if (this.device) body.device = this.device | ||
| if (this.lightRequest !== undefined) body.light_request = this.lightRequest | ||
| if (this.page) body.page = this.page | ||
|
|
||
| try { | ||
| const response = await secureAxiosRequest({ | ||
| method: 'POST', | ||
| url: 'https://api.scavio.dev/api/v2/google', | ||
| data: body, | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: `Bearer ${this.apiKey}` | ||
| } | ||
| }) | ||
| if (response.status >= 400) { | ||
| return `Scavio API error (${response.status}): ${JSON.stringify(response.data).slice(0, 2000)}` | ||
| } | ||
| const data = response.data | ||
| const results = Array.isArray(data?.organic_results) ? data.organic_results : [] | ||
| if (!results.length) return JSON.stringify(data).slice(0, 4000) | ||
| return JSON.stringify( | ||
| results.map((r: any) => ({ title: r.title, url: r.link, description: r.snippet })), | ||
| null, | ||
| 2 | ||
| ) | ||
| } catch (error: any) { | ||
| const status = error?.response?.status | ||
| const detail = error?.response?.data ? JSON.stringify(error.response.data) : error?.message | ||
| return `Scavio API error${status ? ` (${status})` : ''}: ${detail}` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class Scavio_Tools implements INode { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| description: string | ||
| type: string | ||
| icon: string | ||
| category: string | ||
| baseClasses: string[] | ||
| credential: INodeParams | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Scavio' | ||
| this.name = 'scavioAPI' | ||
| this.version = 1.0 | ||
| this.type = 'Scavio' | ||
| this.icon = 'scavio.svg' | ||
| this.category = 'Tools' | ||
| this.description = | ||
| 'Real-time search API for AI agents - Google, YouTube, Amazon, Walmart, Reddit, TikTok, and Instagram as clean JSON' | ||
| this.inputs = [ | ||
| { | ||
| label: 'Search Type', | ||
| name: 'searchType', | ||
| type: 'options', | ||
| options: [ | ||
| { label: 'Classic', name: 'classic' }, | ||
| { label: 'News', name: 'news' }, | ||
| { label: 'Images', name: 'images' } | ||
| ], | ||
| default: 'classic', | ||
| description: 'Google search vertical', | ||
| additionalParams: true, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Country Code', | ||
| name: 'countryCode', | ||
| type: 'string', | ||
| placeholder: 'us', | ||
| description: 'Two-letter country code, e.g. us', | ||
| additionalParams: true, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Language', | ||
| name: 'language', | ||
| type: 'string', | ||
| placeholder: 'en', | ||
| description: 'Two-letter language code, e.g. en', | ||
| additionalParams: true, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Device', | ||
| name: 'device', | ||
| type: 'options', | ||
| options: [ | ||
| { label: 'Desktop', name: 'desktop' }, | ||
| { label: 'Mobile', name: 'mobile' } | ||
| ], | ||
| default: 'desktop', | ||
| additionalParams: true, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Light Request', | ||
| name: 'lightRequest', | ||
| type: 'boolean', | ||
| default: true, | ||
| description: 'Cheaper, lighter response (1 credit instead of 2)', | ||
| additionalParams: true, | ||
| optional: true | ||
| }, | ||
| { | ||
| label: 'Page', | ||
| name: 'page', | ||
| type: 'number', | ||
| default: 1, | ||
| description: 'Result page number (1-based)', | ||
| additionalParams: true, | ||
| optional: true | ||
| } | ||
| ] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['scavioApi'] | ||
| } | ||
| this.baseClasses = [this.type, ...getBaseClasses(Tool)] | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const scavioApiKey = getCredentialParam('scavioApiKey', credentialData, nodeData) | ||
| if (!scavioApiKey) { | ||
| throw new Error('Scavio API Key is missing. Please connect your Scavio API credential.') | ||
| } | ||
|
|
||
| const searchType = nodeData.inputs?.searchType as string | ||
| const countryCode = nodeData.inputs?.countryCode as string | ||
| const language = nodeData.inputs?.language as string | ||
| const device = nodeData.inputs?.device as string | ||
| const lightRequest = nodeData.inputs?.lightRequest as boolean | ||
| const page = nodeData.inputs?.page as number | ||
|
|
||
| return new ScavioSearchTool({ | ||
| apiKey: scavioApiKey, | ||
| searchType, | ||
| countryCode, | ||
| language, | ||
| device, | ||
| lightRequest, | ||
| page | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: Scavio_Tools } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended to validate that the
scavioApiKeyis present during the node's initialization. Throwing a clear error when the API key is missing prevents silent failures or confusing runtime errors when the tool is executed.References