-
-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Adds two new tool nodes under LangChain > Tools: #6470
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
umerkay
wants to merge
6
commits into
FlowiseAI:main
Choose a base branch
from
umerkay:feature/olostep-tool
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.
+296
−42
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d91d878
Adds two new tool nodes under LangChain > Tools:
umerkay 66e7caa
Update packages/components/package.json
umerkay 9071b96
Update packages/components/nodes/tools/OlostepSearch/OlostepSearch.ts
umerkay 0068c8a
Update packages/components/nodes/tools/OlostepScraper/OlostepScraper.ts
umerkay 9f780f5
Update packages/components/credentials/OlostepApi.credential.ts
umerkay cdacb91
Merge branch 'main' into feature/olostep-tool
umerkay 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,23 @@ | ||
| import { INodeParams, INodeCredential } from '../src/Interface' | ||
|
|
||
| class OlostepApi implements INodeCredential { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Olostep API' | ||
| this.name = 'olostepApi' | ||
| this.version = 1.0 | ||
| this.inputs = [ | ||
| { | ||
| label: 'API Key', | ||
| name: 'apiKey', | ||
| type: 'password' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { credClass: OlostepApi } | ||
129 changes: 129 additions & 0 deletions
129
packages/components/nodes/tools/OlostepScraper/OlostepScraper.ts
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,129 @@ | ||
| import { Tool } from '@langchain/core/tools' | ||
| import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' | ||
| import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' | ||
|
|
||
| class OlostepScraper extends Tool { | ||
| static lc_name() { | ||
| return 'OlostepScraper' | ||
| } | ||
|
|
||
| name = 'olostep_scrape' | ||
|
|
||
| description = 'Fetch and read the content of a web page from a URL.' | ||
|
|
||
| private readonly apiKey: string | ||
| private readonly Olostep: any | ||
| private readonly Format: any | ||
|
|
||
| constructor(apiKey: string, Olostep: any, Format: any, description?: string) { | ||
| super() | ||
| this.apiKey = apiKey | ||
| this.Olostep = Olostep | ||
| this.Format = Format | ||
| if (description) this.description = description | ||
| } | ||
|
|
||
| protected async _call(url: string): Promise<string> { | ||
| if (!url) return 'No URL provided' | ||
|
|
||
| try { | ||
| const client = new this.Olostep({ apiKey: this.apiKey }) | ||
|
|
||
| const result = await client.scrapes.create({ | ||
| url, | ||
| formats: [this.Format.MARKDOWN] | ||
| }) | ||
|
|
||
| return result?.markdown_content || 'No content found' | ||
| } catch (error: any) { | ||
| return `Olostep scrape error: ${error?.message ?? String(error)}` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class OlostepScraperMissingSDK extends Tool { | ||
| static lc_name() { | ||
| return 'OlostepScraperMissingSDK' | ||
| } | ||
|
|
||
| name = 'olostep_scrape' | ||
|
|
||
| description = 'Fetch and read the content of a web page from a URL.' | ||
|
|
||
| private readonly message: string | ||
|
|
||
| constructor(message: string, description?: string) { | ||
| super() | ||
| this.message = message | ||
| if (description) this.description = description | ||
| } | ||
|
|
||
| protected async _call(_url: string): Promise<string> { | ||
| return this.message | ||
| } | ||
| } | ||
|
|
||
| class OlostepScraper_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 = 'Olostep Scraper' | ||
| this.name = 'olostepScraper' | ||
| this.version = 1.0 | ||
| this.type = 'OlostepScraper' | ||
| this.icon = 'olostep.svg' | ||
| this.category = 'Tools' | ||
| this.description = 'Fetch and extract clean Markdown content from any URL using Olostep' | ||
| this.inputs = [ | ||
| { | ||
| name: 'description', | ||
| label: 'Tool Description', | ||
| type: 'string', | ||
| rows: 4, | ||
| optional: true, | ||
| additionalParams: true, | ||
| default: 'Fetch and read the content of a web page from a URL.' | ||
| } | ||
| ] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['olostepApi'] | ||
| } | ||
| this.baseClasses = [this.type, ...getBaseClasses(OlostepScraper)] | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
|
umerkay marked this conversation as resolved.
|
||
| if (!apiKey) { | ||
| throw new Error('API Key is required for Olostep Scraper') | ||
| } | ||
|
|
||
| const description = nodeData.inputs?.description as string | ||
|
|
||
| try { | ||
| const olostepMod: any = await import('olostep') | ||
| const Olostep = olostepMod?.default | ||
| const Format = olostepMod?.Format | ||
| if (!Olostep || !Format) { | ||
| return new OlostepScraperMissingSDK('Olostep SDK is unavailable', description) | ||
| } | ||
| return new OlostepScraper(String(apiKey), Olostep, Format, description) | ||
| } catch (error: any) { | ||
| return new OlostepScraperMissingSDK(`Olostep SDK is not installed: ${error?.message ?? String(error)}`, description) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: OlostepScraper_Tools } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 124 additions & 0 deletions
124
packages/components/nodes/tools/OlostepSearch/OlostepSearch.ts
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,124 @@ | ||
| import { Tool } from '@langchain/core/tools' | ||
| import axios from 'axios' | ||
| import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' | ||
| import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' | ||
|
|
||
| type OlostepLink = { | ||
| url: string | ||
| title: string | ||
| description: string | ||
| } | ||
|
|
||
| class OlostepSearch extends Tool { | ||
| static lc_name() { | ||
| return 'OlostepSearch' | ||
| } | ||
|
|
||
| name = 'olostep_search' | ||
|
|
||
| description = 'Search the web for current information, news, and facts.' | ||
|
|
||
| private readonly apiKey: string | ||
| private readonly numResults: number | ||
|
|
||
| constructor(apiKey: string, numResults = 5, description?: string) { | ||
| super() | ||
| this.apiKey = apiKey | ||
| this.numResults = numResults | ||
| if (description) this.description = description | ||
| } | ||
|
|
||
| protected async _call(query: string): Promise<string> { | ||
| if (!query) return 'No query provided' | ||
|
|
||
| try { | ||
| const response = await axios.post( | ||
| 'https://api.olostep.com/v1/searches', | ||
| { query }, | ||
| { | ||
| headers: { | ||
| Authorization: `Bearer ${this.apiKey}`, | ||
| 'Content-Type': 'application/json' | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| const links = response?.data?.result?.links as OlostepLink[] | undefined | ||
| if (!Array.isArray(links) || links.length === 0) return 'No results found' | ||
|
|
||
| const results = links.slice(0, this.numResults) | ||
| return results.map((r, i) => `${i + 1}. ${r.title}\n${r.description}\nURL: ${r.url}`).join('\n\n') | ||
| } catch (error: any) { | ||
| return `Olostep search error: ${error?.message ?? String(error)}` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class OlostepSearch_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 = 'Olostep Search' | ||
| this.name = 'olostepSearch' | ||
| this.version = 1.0 | ||
| this.type = 'OlostepSearch' | ||
| this.icon = 'olostep.svg' | ||
| this.category = 'Tools' | ||
| this.description = 'Search the web using Olostep and return relevant results with titles, URLs, and descriptions' | ||
| this.inputs = [ | ||
| { | ||
| name: 'numResults', | ||
| label: 'Number of Results', | ||
| type: 'number', | ||
| default: 5, | ||
| optional: true, | ||
| additionalParams: true | ||
| }, | ||
| { | ||
| name: 'description', | ||
| label: 'Tool Description', | ||
| type: 'string', | ||
| rows: 4, | ||
| optional: true, | ||
| additionalParams: true, | ||
| default: 'Search the web for current information, news, and facts.' | ||
| } | ||
| ] | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['olostepApi'] | ||
| } | ||
| this.baseClasses = [this.type, ...getBaseClasses(OlostepSearch)] | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> { | ||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const apiKey = getCredentialParam('apiKey', credentialData, nodeData) | ||
|
umerkay marked this conversation as resolved.
|
||
| if (!apiKey) { | ||
| throw new Error('API Key is required for Olostep Search') | ||
| } | ||
|
|
||
| const numResultsRaw = nodeData.inputs?.numResults as number | string | undefined | ||
| let numResults = 5 | ||
| if (numResultsRaw !== undefined && numResultsRaw !== '') { | ||
| const parsed = parseInt(String(numResultsRaw), 10) | ||
| if (!isNaN(parsed) && parsed > 0) numResults = parsed | ||
| } | ||
| const description = nodeData.inputs?.description as string | ||
|
|
||
| return new OlostepSearch(String(apiKey), numResults, description) | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: OlostepSearch_Tools } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.