From b3d57180274fe3a41d67529fc994f39c8b37cff4 Mon Sep 17 00:00:00 2001 From: justabot Date: Sun, 24 Nov 2024 12:11:24 -0500 Subject: [PATCH] CS - first api hookups. --- packages/client-direct/src/index.ts | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/packages/client-direct/src/index.ts b/packages/client-direct/src/index.ts index 7ddc5fa233..ec6eb1badd 100644 --- a/packages/client-direct/src/index.ts +++ b/packages/client-direct/src/index.ts @@ -266,6 +266,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) {