Skip to content

Commit f02c70f

Browse files
authored
Merge pull request #139 from chinmay1819/main
feat: added API to generate report
2 parents d5c4f47 + f2f66a7 commit f02c70f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ node_modules
1111
.pnp.js
1212

1313
# Local env files
14-
.env
14+
.env*
1515
.env.local
1616
.env.development.local
1717
.env.test.local

src/api.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cors from 'cors';
22
import express, { Request, Response } from 'express';
33

4-
import { deepResearch, writeFinalAnswer } from './deep-research';
4+
import { deepResearch, writeFinalAnswer,writeFinalReport } from './deep-research';
55

66
const app = express();
77
const port = process.env.PORT || 3051;
@@ -58,6 +58,42 @@ app.post('/api/research', async (req: Request, res: Response) => {
5858
}
5959
});
6060

61+
// generate report API
62+
app.post('/api/generate-report',async(req:Request,res:Response)=>{
63+
try{
64+
const {query,depth = 3,breadth=3 } = req.body;
65+
if(!query){
66+
return res.status(400).json({error:'Query is required'});
67+
}
68+
log('\n Starting research...\n')
69+
const {learnings,visitedUrls} = await deepResearch({
70+
query,
71+
breadth,
72+
depth
73+
});
74+
log(`\n\nLearnings:\n\n${learnings.join('\n')}`);
75+
log(
76+
`\n\nVisited URLs (${visitedUrls.length}):\n\n${visitedUrls.join('\n')}`,
77+
);
78+
const report = await writeFinalReport({
79+
prompt:query,
80+
learnings,
81+
visitedUrls
82+
});
83+
84+
return report
85+
86+
}catch(error:unknown){
87+
console.error("Error in generate report API:",error)
88+
return res.status(500).json({
89+
error:'An error occurred during research',
90+
message:error instanceof Error? error.message: String(error),
91+
})
92+
}
93+
})
94+
95+
96+
6197
// Start the server
6298
app.listen(port, () => {
6399
console.log(`Deep Research API running on port ${port}`);

0 commit comments

Comments
 (0)