-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from autonomys/project-refactor
Refactor auto-content-creator
- Loading branch information
Showing
21 changed files
with
4,773 additions
and
490 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Dependencies | ||
node_modules | ||
.pnp | ||
.pnp.js | ||
|
||
# Build outputs | ||
dist | ||
build | ||
out | ||
|
||
# Environment files | ||
.env | ||
.env.local | ||
.env.*.local | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories | ||
.idea | ||
.vscode | ||
*.swp | ||
*.swo | ||
|
||
# OS files | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Database | ||
*.sqlite | ||
*.sqlite3 | ||
|
||
# Test coverage | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Base stage for all services | ||
FROM node:20-alpine as base | ||
WORKDIR /app | ||
COPY package.json yarn.lock ./ | ||
COPY agents/package.json ./agents/ | ||
COPY backend/package.json ./backend/ | ||
COPY frontend/package.json ./frontend/ | ||
RUN yarn install --frozen-lockfile | ||
|
||
# Agents build stage | ||
FROM base as agents-build | ||
COPY agents ./agents | ||
COPY tsconfig.base.json ./ | ||
RUN yarn workspace @auto-content/agents build | ||
|
||
# Backend build stage | ||
FROM base as backend-build | ||
COPY backend ./backend | ||
COPY tsconfig.base.json ./ | ||
RUN yarn workspace @auto-content/backend build | ||
|
||
# Frontend build stage | ||
FROM base as frontend-build | ||
COPY frontend ./frontend | ||
COPY tsconfig.base.json ./ | ||
RUN yarn workspace @auto-content/frontend build | ||
|
||
# Agents production stage | ||
FROM node:20-alpine as agents | ||
WORKDIR /app | ||
COPY --from=agents-build /app/agents/dist ./dist | ||
COPY --from=agents-build /app/agents/package.json ./ | ||
COPY --from=base /app/node_modules ./node_modules | ||
CMD ["node", "dist/index.js"] | ||
|
||
# Backend production stage | ||
FROM node:20-alpine as backend | ||
WORKDIR /app | ||
COPY --from=backend-build /app/backend/dist ./dist | ||
COPY --from=backend-build /app/backend/package.json ./ | ||
COPY --from=base /app/node_modules ./node_modules | ||
CMD ["node", "dist/index.js"] | ||
|
||
# Frontend production stage | ||
FROM node:20-alpine as frontend | ||
WORKDIR /app | ||
COPY --from=frontend-build /app/frontend/dist ./dist | ||
COPY --from=frontend-build /app/frontend/package.json ./ | ||
COPY --from=base /app/node_modules ./node_modules | ||
CMD ["node", "dist/index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
export const config = { | ||
port: process.env.AGENTS_PORT || 3000, | ||
openaiApiKey: process.env.OPENAI_API_KEY, | ||
serpapiApiKey: process.env.SERPAPI_API_KEY, | ||
model: 'gpt-4o-mini', | ||
environment: process.env.NODE_ENV || 'development', | ||
llmConfig: { | ||
generation: { | ||
temperature: 0.7, | ||
maxTokens: 2000 | ||
}, | ||
reflection: { | ||
temperature: 0.2, | ||
maxTokens: 1000 | ||
}, | ||
research: { | ||
temperature: 0.2, | ||
maxTokens: 1000 | ||
}, | ||
feedback: { | ||
temperature: 0.4, | ||
maxTokens: 1500 | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,34 @@ | ||
import express, { Request, Response, NextFunction } from 'express'; | ||
import { writerAgent } from './writerAgent'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
import { writerRouter } from './routes/writer'; | ||
import logger from './logger'; | ||
import { config } from './config'; | ||
|
||
// Create an Express application | ||
const app = express(); | ||
|
||
// Add JSON parsing middleware | ||
app.use(express.json()); | ||
|
||
// Specify the port number for the server | ||
const port: number = process.env.AGENTS_PORT ? parseInt(process.env.AGENTS_PORT) : 3000; | ||
|
||
// Add this new endpoint for feedback | ||
app.post('/writer/:threadId/feedback', (req: Request, res: Response, next: NextFunction) => { | ||
console.log('Received feedback request:', req.body); | ||
(async () => { | ||
try { | ||
const { feedback } = req.body; | ||
const threadId = req.params.threadId; | ||
const port = config.port; | ||
|
||
if (!feedback) { | ||
return res.status(400).json({ error: 'Feedback is required' }); | ||
} | ||
|
||
console.log('Processing feedback for thread:', threadId); | ||
|
||
const result = await writerAgent.continueDraft({ | ||
threadId, | ||
feedback, | ||
}); | ||
|
||
// Only return the latest content | ||
res.json({ | ||
threadId, | ||
content: result.finalContent | ||
}); | ||
} catch (error) { | ||
console.error('Error in feedback endpoint:', error); | ||
next(error); | ||
} | ||
})(); | ||
}); | ||
|
||
// Modify the original /writer endpoint to return threadId | ||
app.post('/writer', (req: Request, res: Response, next: NextFunction) => { | ||
console.log('Received request body:', req.body); | ||
(async () => { | ||
try { | ||
const { category, topic, contentType, otherInstructions } = req.body; | ||
|
||
if (!category || !topic || !contentType) { | ||
console.log('Category, topic, and contentType are required'); | ||
return res.status(400).json({ error: 'Category, topic, and contentType are required' }); | ||
} | ||
app.use(express.json()); | ||
|
||
const result = await writerAgent.startDraft({ | ||
category, | ||
topic, | ||
contentType, | ||
otherInstructions, | ||
}); | ||
// Routes | ||
app.use('/writer', writerRouter); | ||
|
||
res.json({ | ||
threadId: result.threadId, | ||
finalContent: result.finalContent, | ||
research: result.research, | ||
reflections: result.reflections, | ||
drafts: result.drafts, | ||
feedbackHistory: result.feedbackHistory, | ||
}); | ||
} catch (error) { | ||
console.error('Error in /writer endpoint:', error); | ||
next(error); | ||
} | ||
})(); | ||
// Health check route | ||
app.get('/', (req, res) => { | ||
logger.info('Health check request received'); | ||
res.send('Auto Content Creator Agents Service is running!'); | ||
}); | ||
|
||
// Error handling middleware | ||
app.use((err: Error, req: Request, res: Response, next: NextFunction) => { | ||
console.error(err.stack); | ||
logger.error('Unhandled error:', err); | ||
res.status(500).json({ | ||
error: 'An error occurred while processing your request', | ||
details: err.message, | ||
details: err.message | ||
}); | ||
}); | ||
|
||
// Add a simple route for testing | ||
app.get('/', (req, res) => { | ||
console.log('Received request on root route'); | ||
res.send('Auto Content Creator Backend is running!'); | ||
}); | ||
|
||
// Start the server and listen on the specified port | ||
// Start server | ||
app.listen(port, () => { | ||
// Log a message when the server is successfully running | ||
console.log(`Server is running on http://localhost:${port}`); | ||
logger.info(`Agents service is running on http://localhost:${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import express from 'express'; | ||
import { writerAgent } from '../services/writerAgent'; | ||
import logger from '../logger'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/', (req, res, next) => { | ||
logger.info('Received request to start new draft:', req.body); | ||
(async () => { | ||
try { | ||
const { category, topic, contentType, otherInstructions } = req.body; | ||
|
||
if (!category || !topic || !contentType) { | ||
logger.warn('Missing required fields'); | ||
return res.status(400).json({ error: 'Category, topic, and contentType are required' }); | ||
} | ||
|
||
const result = await writerAgent.startDraft({ | ||
category, | ||
topic, | ||
contentType, | ||
otherInstructions, | ||
}); | ||
|
||
res.json({ | ||
threadId: result.threadId, | ||
finalContent: result.finalContent, | ||
research: result.research, | ||
reflections: result.reflections, | ||
drafts: result.drafts, | ||
feedbackHistory: result.feedbackHistory, | ||
}); | ||
} catch (error) { | ||
logger.error('Error in writer endpoint:', error); | ||
next(error); | ||
} | ||
})(); | ||
}); | ||
|
||
router.post('/:threadId/feedback', (req, res, next) => { | ||
logger.info('Received feedback request:', req.body); | ||
(async () => { | ||
try { | ||
const { feedback } = req.body; | ||
const threadId = req.params.threadId; | ||
|
||
if (!feedback) { | ||
return res.status(400).json({ error: 'Feedback is required' }); | ||
} | ||
|
||
logger.info('Processing feedback for thread:', threadId); | ||
|
||
const result = await writerAgent.continueDraft({ | ||
threadId, | ||
feedback, | ||
}); | ||
|
||
res.json({ | ||
content: result.finalContent | ||
}); | ||
} catch (error) { | ||
logger.error('Error in feedback endpoint:', error); | ||
next(error); | ||
} | ||
})(); | ||
}); | ||
|
||
export const writerRouter = router; |
Oops, something went wrong.