const fs = require('fs'); const path = require('path'); const outputDir = path.join(__dirname, "../../../storage/documents"); if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }); } const SAIA_API_KEY = process.env.SAIA_API_KEY; const SAIA_URL = "https://chat-ai.academiccloud.de/v1/chat/completions"; const module_exports = { name: "qwen3-235b-a22b", type: "llm", displayname: "QWEN 3 235B", description: "Generates documents using QWEN 3 235B via SAIA platform", async function(parameter) { try { console.log("SAIA QWEN 3 235B module invoked with parameters:", parameter); await this.createDocumentFromTranscript( parameter.inputTranscriptPath, parameter.documentTypePath, parameter.language ); } catch (error) { console.error("Error in SAIA QWEN 3 235B module:", error); } }, createDocumentFromTranscript: async function(transcriptPath, documentTypePath, language = "en") { try { const transcript = await fs.promises.readFile(transcriptPath, "utf-8"); const documentType = await fs.promises.readFile(documentTypePath, "utf-8"); const promptText = `${documentType}, in language ${language}, transcript:\n\n${transcript}`; // --- REST CALL --- const response = await fetch(SAIA_URL, { method: "POST", headers: { "Authorization": `Bearer ${SAIA_API_KEY}`, "Accept": "application/json", "Content-Type": "application/json" }, body: JSON.stringify({ model: "qwen3-235b-a22b", // Korrekter Modellname! messages: [ { role: "system", content: "You are a helpful assistant that generates documents from transcripts." }, { role: "user", content: promptText } ], temperature: 0 }) }); if (!response.ok) { const text = await response.text(); throw new Error(`SAIA API error (${response.status}): ${text}`); } const data = await response.json(); const output = data.choices?.[0]?.message?.content || ""; let inputTranscriptName = path.basename(transcriptPath, path.extname(transcriptPath)); console.log(inputTranscriptName); const outPath = path.join(outputDir, `${inputTranscriptName}.md`); fs.writeFileSync(outPath, output, "utf8"); console.log("Generated document written to:", outPath); } catch (error) { console.error("Error generating SAIA content:", error); } } }; module.exports = module_exports; if (require.main === module) { (async () => { const args = process.argv.slice(2); if (args.length < 2) { console.error("Usage: node quen3.js [language]"); console.error("Example: node quen3.js ./transcript.json ./docType.json de"); process.exit(1); } const [transcriptPath, documentTypePath, language] = args; if (!SAIA_API_KEY) { console.error("ERROR: SAIA_API_KEY environment variable is not set!"); console.error("Please set it with: export SAIA_API_KEY='your_api_key_here'"); process.exit(1); } if (!fs.existsSync(transcriptPath)) { console.error(`ERROR: Transcript file not found: ${transcriptPath}`); process.exit(1); } if (!fs.existsSync(documentTypePath)) { console.error(`ERROR: Document type file not found: ${documentTypePath}`); process.exit(1); } console.log("Starting document generation..."); console.log(`Transcript: ${transcriptPath}`); console.log(`Document Type: ${documentTypePath}`); console.log(`Language: ${language || 'en (default)'}`); await module_exports.createDocumentFromTranscript( transcriptPath, documentTypePath, language || 'en' ); console.log("Done!"); })(); }