Skip to content

Commit

Permalink
CS - first api hookups.
Browse files Browse the repository at this point in the history
  • Loading branch information
justabot committed Nov 24, 2024
1 parent 666d5c1 commit b3d5718
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/client-direct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b3d5718

Please sign in to comment.