GPT Vision - OpenAIVisionChain

This commit is contained in:
vinodkiran
2023-11-25 16:39:02 +05:30
parent 17198d8524
commit c96572e10f
3 changed files with 388 additions and 0 deletions
+26
View File
@@ -403,6 +403,19 @@ export class App {
return res.json(obj)
})
// Check if chatflow valid for uploads
this.app.get('/api/v1/chatflows-uploads/:id', async (req: Request, res: Response) => {
const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
id: req.params.id
})
if (!chatflow) return res.status(404).send(`Chatflow ${req.params.id} not found`)
const obj = {
allowUploads: this.shouldAllowUploads(chatflow)
}
return res.json(obj)
})
// ----------------------------------------
// ChatMessage
// ----------------------------------------
@@ -1241,6 +1254,19 @@ export class App {
})
}
private uploadAllowedNodes = ['OpenAIVisionChain']
private shouldAllowUploads(result: ChatFlow): boolean {
const flowObj = JSON.parse(result.flowData)
let allowUploads = false
flowObj.nodes.forEach((node: IReactFlowNode) => {
if (this.uploadAllowedNodes.indexOf(node.data.type) > -1) {
logger.debug(`[server]: Found Eligible Node ${node.data.type}, Allowing Uploads.`)
allowUploads = true
}
})
return allowUploads
}
/**
* Validate API Key
* @param {Request} req