Merge pull request #139 from chinmay1819/main

feat: added API to generate report
This commit is contained in:
David Zhang 2025-06-07 15:00:43 +02:00 committed by GitHub
commit f02c70fa7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 2 deletions

2
.gitignore vendored
View File

@ -11,7 +11,7 @@ node_modules
.pnp.js
# Local env files
.env
.env*
.env.local
.env.development.local
.env.test.local

View File

@ -1,7 +1,7 @@
import cors from 'cors';
import express, { Request, Response } from 'express';
import { deepResearch, writeFinalAnswer } from './deep-research';
import { deepResearch, writeFinalAnswer,writeFinalReport } from './deep-research';
const app = express();
const port = process.env.PORT || 3051;
@ -58,6 +58,42 @@ app.post('/api/research', async (req: Request, res: Response) => {
}
});
// generate report API
app.post('/api/generate-report',async(req:Request,res:Response)=>{
try{
const {query,depth = 3,breadth=3 } = req.body;
if(!query){
return res.status(400).json({error:'Query is required'});
}
log('\n Starting research...\n')
const {learnings,visitedUrls} = await deepResearch({
query,
breadth,
depth
});
log(`\n\nLearnings:\n\n${learnings.join('\n')}`);
log(
`\n\nVisited URLs (${visitedUrls.length}):\n\n${visitedUrls.join('\n')}`,
);
const report = await writeFinalReport({
prompt:query,
learnings,
visitedUrls
});
return report
}catch(error:unknown){
console.error("Error in generate report API:",error)
return res.status(500).json({
error:'An error occurred during research',
message:error instanceof Error? error.message: String(error),
})
}
})
// Start the server
app.listen(port, () => {
console.log(`Deep Research API running on port ${port}`);