Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-playwright-nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
disflyer authored Jun 15, 2023
2 parents 1bb65e7 + 74993db commit 661295a
Show file tree
Hide file tree
Showing 20 changed files with 416 additions and 183 deletions.
8 changes: 6 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.

**Setup**
**Flow**
If applicable, add exported flow in order to help replicating the problem.

- OS: [e.g. iOS, Windows, Linux]
**Setup**
- Installation [e.g. docker, `npx flowise start`, `yarn start`]
- Flowise Version [e.g. 1.2.11]
- OS: [e.g. macOS, Windows, Linux]
- Browser [e.g. chrome, safari]

**Additional context**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ class MultiPromptChain_Chains implements INode {
promptTemplates.push(prompt.systemMessage)
}

const chain = MultiPromptChain.fromPrompts(model, promptNames, promptDescriptions, promptTemplates, undefined, {
verbose: process.env.DEBUG === 'true' ? true : false
} as any)
const chain = MultiPromptChain.fromLLMAndPrompts(model, {
promptNames,
promptDescriptions,
promptTemplates,
llmChainOpts: { verbose: process.env.DEBUG === 'true' ? true : false }
})

return chain
}
Expand All @@ -61,7 +64,7 @@ class MultiPromptChain_Chains implements INode {
const obj = { input }

if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId, 2)
const res = await chain.call(obj, [handler])
return res?.text
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ class MultiRetrievalQAChain_Chains implements INode {
name: 'vectorStoreRetriever',
type: 'VectorStoreRetriever',
list: true
},
{
label: 'Return Source Documents',
name: 'returnSourceDocuments',
type: 'boolean',
optional: true
}
]
}

async init(nodeData: INodeData): Promise<any> {
const model = nodeData.inputs?.model as BaseLanguageModel
const vectorStoreRetriever = nodeData.inputs?.vectorStoreRetriever as VectorStoreRetriever[]
const returnSourceDocuments = nodeData.inputs?.returnSourceDocuments as boolean

const retrieverNames = []
const retrieverDescriptions = []
const retrievers = []
Expand All @@ -49,23 +57,29 @@ class MultiRetrievalQAChain_Chains implements INode {
retrievers.push(vs.vectorStore.asRetriever((vs.vectorStore as any).k ?? 4))
}

const chain = MultiRetrievalQAChain.fromRetrievers(model, retrieverNames, retrieverDescriptions, retrievers, undefined, {
verbose: process.env.DEBUG === 'true' ? true : false
} as any)

const chain = MultiRetrievalQAChain.fromLLMAndRetrievers(model, {
retrieverNames,
retrieverDescriptions,
retrievers,
retrievalQAChainOpts: { verbose: process.env.DEBUG === 'true' ? true : false, returnSourceDocuments }
})
return chain
}

async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string | ICommonObject> {
const chain = nodeData.instance as MultiRetrievalQAChain
const returnSourceDocuments = nodeData.inputs?.returnSourceDocuments as boolean

const obj = { input }

if (options.socketIO && options.socketIOClientId) {
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId)
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId, 2, returnSourceDocuments)
const res = await chain.call(obj, [handler])
if (res.text && res.sourceDocuments) return res
return res?.text
} else {
const res = await chain.call(obj)
if (res.text && res.sourceDocuments) return res
return res?.text
}
}
Expand Down
24 changes: 14 additions & 10 deletions packages/components/nodes/chatmodels/ChatOpenAI/ChatOpenAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ class ChatOpenAI_ChatModels implements INode {
name: 'gpt-4'
},
{
label: 'gpt-4-0314',
name: 'gpt-4-0314'
label: 'gpt-4-0613',
name: 'gpt-4-0613'
},
{
label: 'gpt-4-32k-0314',
name: 'gpt-4-32k-0314'
label: 'gpt-4-32k',
name: 'gpt-4-32k'
},
{
label: 'gpt-4-0613',
name: 'gpt-4-0613'
label: 'gpt-4-32k-0613',
name: 'gpt-4-32k-0613'
},
{
label: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo'
},
{
label: 'gpt-3.5-turbo-0301',
name: 'gpt-3.5-turbo-0301'
},
{
label: 'gpt-3.5-turbo-0613',
name: 'gpt-3.5-turbo-0613'
},
{
label: 'gpt-3.5-turbo-16k',
name: 'gpt-3.5-turbo-16k'
},
{
label: 'gpt-3.5-turbo-16k-0613',
name: 'gpt-3.5-turbo-16k-0613'
}
],
default: 'gpt-3.5-turbo',
Expand Down
122 changes: 122 additions & 0 deletions packages/components/nodes/documentloaders/Puppeteer/Puppeteer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { INode, INodeData, INodeParams } from '../../../src/Interface'
import { TextSplitter } from 'langchain/text_splitter'
import { PuppeteerWebBaseLoader } from 'langchain/document_loaders/web/puppeteer'
import { test } from 'linkifyjs'
import { getAvailableURLs } from '../../../src'

class Puppeteer_DocumentLoaders implements INode {
label: string
name: string
description: string
type: string
icon: string
category: string
baseClasses: string[]
inputs: INodeParams[]

constructor() {
this.label = 'Puppeteer Web Scraper'
this.name = 'puppeteerWebScraper'
this.type = 'Document'
this.icon = 'puppeteer.svg'
this.category = 'Document Loaders'
this.description = `Load data from webpages`
this.baseClasses = [this.type]
this.inputs = [
{
label: 'URL',
name: 'url',
type: 'string'
},
{
label: 'Text Splitter',
name: 'textSplitter',
type: 'TextSplitter',
optional: true
},
{
label: 'Web Scrape for Relative Links',
name: 'webScrape',
type: 'boolean',
optional: true,
additionalParams: true
},
{
label: 'Web Scrape Links Limit',
name: 'limit',
type: 'number',
default: 10,
optional: true,
additionalParams: true
},
{
label: 'Metadata',
name: 'metadata',
type: 'json',
optional: true,
additionalParams: true
}
]
}

async init(nodeData: INodeData): Promise<any> {
const textSplitter = nodeData.inputs?.textSplitter as TextSplitter
const metadata = nodeData.inputs?.metadata
const webScrape = nodeData.inputs?.webScrape as boolean
let limit = nodeData.inputs?.limit as string

let url = nodeData.inputs?.url as string
url = url.trim()
if (!test(url)) {
throw new Error('Invalid URL')
}

const puppeteerLoader = async (url: string): Promise<any> => {
let docs = []
const loader = new PuppeteerWebBaseLoader(url)
if (textSplitter) {
docs = await loader.loadAndSplit(textSplitter)
} else {
docs = await loader.load()
}
return docs
}

let availableUrls: string[]
let docs = []
if (webScrape) {
if (!limit) limit = '10'
availableUrls = await getAvailableURLs(url, parseInt(limit))
for (let i = 0; i < availableUrls.length; i++) {
try {
docs.push(...(await puppeteerLoader(availableUrls[i])))
} catch (error) {
console.error('Error loading url with puppeteer. URL: ', availableUrls[i], 'Error: ', error)
continue
}
}
} else {
docs = await puppeteerLoader(url)
}

if (metadata) {
const parsedMetadata = typeof metadata === 'object' ? metadata : JSON.parse(metadata)
let finaldocs = []
for (const doc of docs) {
const newdoc = {
...doc,
metadata: {
...doc.metadata,
...parsedMetadata
}
}
finaldocs.push(newdoc)
}
return finaldocs
}

return docs
}
}

module.exports = { nodeClass: Puppeteer_DocumentLoaders }
14 changes: 14 additions & 0 deletions packages/components/nodes/documentloaders/Puppeteer/puppeteer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"node-fetch": "^2.6.11",
"pdf-parse": "^1.1.1",
"playwright": "^1.35.0",
"puppeteer": "^20.7.1",
"weaviate-ts-client": "^1.1.0",
"ws": "^8.9.0",
"html-to-text": "^9.0.5"
Expand Down
Loading

0 comments on commit 661295a

Please sign in to comment.