-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dddcddc
commit 6564431
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
packages/components/nodes/chains/ImageConversationChain/ImageConversationChain.ts
This file contains 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,71 @@ | ||
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' | ||
import { RetrievalQAChain } from 'langchain/chains' | ||
import { BaseRetriever } from 'langchain/schema/retriever' | ||
import { getBaseClasses } from '../../../src/utils' | ||
import { BaseLanguageModel } from 'langchain/base_language' | ||
import { ConsoleCallbackHandler, CustomChainHandler, additionalCallbacks } from '../../../src/handler' | ||
|
||
class ImageConversationChain_Chains implements INode { | ||
label: string | ||
name: string | ||
version: number | ||
type: string | ||
icon: string | ||
category: string | ||
baseClasses: string[] | ||
description: string | ||
inputs: INodeParams[] | ||
|
||
constructor() { | ||
this.label = 'Image Conversation Chain' | ||
this.name = 'imageConversationChain' | ||
this.version = 1.0 | ||
this.type = 'ImageConversationChain' | ||
this.icon = 'image.png' | ||
this.category = 'Chains' | ||
this.description = 'QA chain to answer a question based on the retrieved images' | ||
this.baseClasses = [this.type, ...getBaseClasses(RetrievalQAChain)] | ||
this.inputs = [ | ||
{ | ||
label: 'Image', | ||
name: 'Image', | ||
type: 'Image' | ||
}, | ||
{ | ||
label: 'myBard', | ||
name: 'myBard', | ||
type: 'myBard' | ||
} | ||
] | ||
} | ||
|
||
async init(nodeData: INodeData): Promise<any> { | ||
const myBard = nodeData.inputs?.myBard | ||
const image = nodeData.inputs?.image as string | ||
|
||
//const chain = RetrievalQAChain.fromLLM(model, vectorStoreRetriever, { verbose: process.env.DEBUG === 'true' ? true : false }) | ||
//return chain | ||
} | ||
|
||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> { | ||
const chain = nodeData.instance as RetrievalQAChain | ||
const myBard = nodeData.inputs?.myBard | ||
const image = nodeData.inputs?.image as string | ||
const obj = { | ||
query: input | ||
} | ||
const loggerHandler = new ConsoleCallbackHandler(options.logger) | ||
const callbacks = await additionalCallbacks(nodeData, options) | ||
|
||
if (options.socketIO && options.socketIOClientId) { | ||
const handler = new CustomChainHandler(options.socketIO, options.socketIOClientId) | ||
const res = await chain.call(obj, [loggerHandler, handler, ...callbacks]) | ||
return (await myBard.ask(obj, {image: image})) | ||
} else { | ||
const res = await chain.call(obj, [loggerHandler, ...callbacks]) | ||
return (await myBard.ask(obj, {image: image})) | ||
} | ||
} | ||
} | ||
|
||
module.exports = { nodeClass: ImageConversationChain_Chains } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.