diff --git a/packages/client-direct/src/index.ts b/packages/client-direct/src/index.ts index 4920b23180..d86869085b 100644 --- a/packages/client-direct/src/index.ts +++ b/packages/client-direct/src/index.ts @@ -270,6 +270,56 @@ export class DirectClient { res.json({ images: imagesRes }); } ); + + this.app.post( + "/fine-tune", + async (req: express.Request, res: express.Response) => { + try { + const response = await fetch('https://api.bageldb.ai/api/v1/asset', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-API-KEY': `${process.env.BAGEL_API_KEY}` + }, + body: JSON.stringify(req.body) + }); + + const data = await response.json(); + res.json(data); + } catch (error) { + res.status(500).json({ + error: 'Failed to forward request to BagelDB', + details: error.message + }); + } + } + ); + this.app.get( + "/fine-tune/:assetId", + async (req: express.Request, res: express.Response) => { + const assetId = req.params.assetId; + try { + const response = await fetch(`https://api.bageldb.ai/api/v1/asset/${assetId}/download`, { + headers: { + 'X-API-KEY': `${process.env.BAGEL_API_KEY}` + } + }); + + // Forward the content-type header + res.set('Content-Type', response.headers.get('content-type')); + + // Convert ReadableStream to Buffer and send + const arrayBuffer = await response.arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + res.send(buffer); + } catch (error) { + res.status(500).json({ + error: 'Failed to forward request to BagelDB', + details: error.message + }); + } + } + ); } public registerAgent(runtime: AgentRuntime) {