feat(market-intel): Implement fully functional, optimized backend
- Refactored market_intel_orchestrator.py for direct Gemini API (v1) calls.\n- Updated model to gemini-2.5-pro for enhanced capabilities.\n- Implemented minimal stdout logging for improved traceability within Docker.\n- Optimized Dockerfile and introduced market-intel.requirements.txt for leaner, faster builds.\n- Ensured end-to-end communication from React frontend through Node.js bridge to Python backend is fully functional.
This commit is contained in:
@@ -15,15 +15,15 @@ app.use(bodyParser.json()); // Parst JSON-Anfragen
|
||||
|
||||
// API-Endpunkt für generateSearchStrategy
|
||||
app.post('/api/generate-search-strategy', async (req, res) => {
|
||||
console.log(`[${new Date().toISOString()}] HIT: /api/generate-search-strategy`);
|
||||
const { referenceUrl, contextContent } = req.body;
|
||||
|
||||
if (!referenceUrl || !contextContent) {
|
||||
console.error('Validation Error: Missing referenceUrl or contextContent.');
|
||||
return res.status(400).json({ error: 'Missing referenceUrl or contextContent' });
|
||||
}
|
||||
|
||||
// Temporäre Datei für contextContent erstellen
|
||||
const tempContextFilePath = path.join(__dirname, 'tmp', `context_${Date.now()}.md`);
|
||||
// Sicherstellen, dass das tmp-Verzeichnis existiert
|
||||
const tmpDir = path.join(__dirname, 'tmp');
|
||||
if (!fs.existsSync(tmpDir)) {
|
||||
fs.mkdirSync(tmpDir);
|
||||
@@ -31,18 +31,18 @@ app.post('/api/generate-search-strategy', async (req, res) => {
|
||||
|
||||
try {
|
||||
fs.writeFileSync(tempContextFilePath, contextContent);
|
||||
console.log(`Successfully wrote context to ${tempContextFilePath}`);
|
||||
|
||||
// Python-Skript aufrufen
|
||||
// Achtung: Hier muss der korrekte Pfad zur venv und zum Python-Skript angegeben werden.
|
||||
// Für den Container oder lokalen Betrieb muss dies entsprechend angepasst werden.
|
||||
// Aktuell gehen wir davon aus, dass das Python-Skript im Hauptverzeichnis liegt.
|
||||
const pythonProcess = spawn(
|
||||
path.join(__dirname, '..', '.venv', 'bin', 'python3'), // Pfad zur venv python3
|
||||
[path.join(__dirname, '..', 'market_intel_orchestrator.py'), '--mode', 'generate_strategy', '--reference_url', referenceUrl, '--context_file', tempContextFilePath],
|
||||
{
|
||||
env: { ...process.env, PYTHONPATH: path.join(__dirname, '..', '.venv', 'lib', 'python3.11', 'site-packages') }
|
||||
}
|
||||
);
|
||||
const pythonExecutable = path.join(__dirname, '..', '.venv', 'bin', 'python3');
|
||||
const pythonScript = path.join(__dirname, '..', 'market_intel_orchestrator.py');
|
||||
const scriptArgs = [pythonScript, '--mode', 'generate_strategy', '--reference_url', referenceUrl, '--context_file', tempContextFilePath];
|
||||
|
||||
console.log(`Spawning command: ${pythonExecutable}`);
|
||||
console.log(`With arguments: ${JSON.stringify(scriptArgs)}`);
|
||||
|
||||
const pythonProcess = spawn(pythonExecutable, scriptArgs, {
|
||||
env: { ...process.env, PYTHONPATH: path.join(__dirname, '..', '.venv', 'lib', 'python3.11', 'site-packages') }
|
||||
});
|
||||
|
||||
let pythonOutput = '';
|
||||
let pythonError = '';
|
||||
@@ -56,11 +56,17 @@ app.post('/api/generate-search-strategy', async (req, res) => {
|
||||
});
|
||||
|
||||
pythonProcess.on('close', (code) => {
|
||||
// Temporäre Datei löschen
|
||||
console.log(`Python script finished with exit code: ${code}`);
|
||||
console.log(`--- STDOUT ---`);
|
||||
console.log(pythonOutput);
|
||||
console.log(`--- STDERR ---`);
|
||||
console.log(pythonError);
|
||||
console.log(`----------------`);
|
||||
|
||||
fs.unlinkSync(tempContextFilePath);
|
||||
|
||||
if (code !== 0) {
|
||||
console.error(`Python script exited with code ${code}: ${pythonError}`);
|
||||
console.error(`Python script exited with error.`);
|
||||
return res.status(500).json({ error: 'Python script failed', details: pythonError });
|
||||
}
|
||||
try {
|
||||
@@ -73,8 +79,7 @@ app.post('/api/generate-search-strategy', async (req, res) => {
|
||||
});
|
||||
|
||||
pythonProcess.on('error', (err) => {
|
||||
console.error('Failed to start python process:', err);
|
||||
// Temporäre Datei löschen, falls sie existiert
|
||||
console.error('FATAL: Failed to start python process itself.', err);
|
||||
if (fs.existsSync(tempContextFilePath)) {
|
||||
fs.unlinkSync(tempContextFilePath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user