mirror of
https://github.com/dzhng/deep-research.git
synced 2025-12-26 04:48:06 +08:00
feat: added API to generate report
This commit is contained in:
parent
d5c4f47c54
commit
f2f66a7017
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,7 +11,7 @@ node_modules
|
||||
.pnp.js
|
||||
|
||||
# Local env files
|
||||
.env
|
||||
.env*
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
|
||||
38
src/api.ts
38
src/api.ts
@ -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}`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user