mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Feature/add endpoints for realtime api (#3318)
add endpoints for realtime api
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import { Request, Response, NextFunction } from 'express'
|
||||
import openaiRealTimeService from '../../services/openai-realtime'
|
||||
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
|
||||
import { StatusCodes } from 'http-status-codes'
|
||||
|
||||
const getAgentTools = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (typeof req.params === 'undefined' || !req.params.id) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: openaiRealTimeController.getAgentTools - id not provided!`
|
||||
)
|
||||
}
|
||||
const apiResponse = await openaiRealTimeService.getAgentTools(req.params.id)
|
||||
return res.json(apiResponse)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
const executeAgentTool = async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (typeof req.params === 'undefined' || !req.params.id) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: openaiRealTimeController.executeAgentTool - id not provided!`
|
||||
)
|
||||
}
|
||||
if (!req.body) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: openaiRealTimeController.executeAgentTool - body not provided!`
|
||||
)
|
||||
}
|
||||
if (!req.body.chatId) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: openaiRealTimeController.executeAgentTool - body chatId not provided!`
|
||||
)
|
||||
}
|
||||
if (!req.body.toolName) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: openaiRealTimeController.executeAgentTool - body toolName not provided!`
|
||||
)
|
||||
}
|
||||
if (!req.body.inputArgs) {
|
||||
throw new InternalFlowiseError(
|
||||
StatusCodes.PRECONDITION_FAILED,
|
||||
`Error: openaiRealTimeController.executeAgentTool - body inputArgs not provided!`
|
||||
)
|
||||
}
|
||||
const apiResponse = await openaiRealTimeService.executeAgentTool(
|
||||
req.params.id,
|
||||
req.body.chatId,
|
||||
req.body.toolName,
|
||||
req.body.inputArgs
|
||||
)
|
||||
return res.json(apiResponse)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
getAgentTools,
|
||||
executeAgentTool
|
||||
}
|
||||
Reference in New Issue
Block a user