{ "nodes": [ { "id": "summarize-podcast-transcript-with-refinement-0", "name": "When clicking \"Execute Workflow\"", "type": "n8n-nodes-base.manualTrigger", "position": [ -820, 20 ], "parameters": {}, "typeVersion": 1 }, { "id": "summarize-podcast-transcript-with-refinement-1", "name": "LangChain Code", "type": "@n8n/n8n-nodes-langchain.code", "position": [ -380, 20 ], "parameters": { "code": { "execute": { "code": "const { loadSummarizationChain } = require('langchain/chains');\nconst { PromptTemplate } = require('@langchain/core/prompts');\nconst { TokenTextSplitter } = require('langchain/text_splitter');\nconst rows=$input.item.json.transcripts; if(!Array.isArray(rows)||!rows.length||rows.some(x=>typeof x.text!=='string'))throw new Error('No valid transcript');\nconst docs=[{pageContent:rows.map(x=>x.text).join('\\n'),metadata:{source:'SearchApi',responseType:'transcripts'}}];\nconst splitter = new TokenTextSplitter({\n chunkSize: 10000,\n chunkOverlap: 250,\n});\n\nconst docsSummary = await splitter.splitDocuments(docs);\n\nconst llmSummary = await this.getInputConnectionData('ai_languageModel', 0);\n\nconst summaryTemplate = `\nYou are an expert in summarizing YouTube videos.\nYour goal is to create a summary of a podcast.\nBelow you find the transcript of a podcast:\n--------\n{text}\n--------\n\nThe transcript of the podcast will also be used as the basis for a question and answer bot.\nProvide some examples questions and answers that could be asked about the podcast. Make these questions very specific.\n\nTotal output will be a summary of the video and a list of example questions the user could ask of the video.\n\nSUMMARY AND QUESTIONS:\n`;\n\nconst SUMMARY_PROMPT = PromptTemplate.fromTemplate(summaryTemplate);\n\nconst summaryRefineTemplate = `\nYou are an expert in summarizing YouTube videos.\nYour goal is to create a summary of a podcast.\nWe have provided an existing summary up to a certain point: {existing_answer}\n\nBelow you find the transcript of a podcast:\n--------\n{text}\n--------\n\nGiven the new context, refine the summary and example questions.\nThe transcript of the podcast will also be used as the basis for a question and answer bot.\nProvide some examples questions and answers that could be asked about the podcast. Make\nthese questions very specific.\nIf the context isn't useful, return the original summary and questions.\nTotal output will be a summary of the video and a list of example questions the user could ask of the video.\n\nSUMMARY AND QUESTIONS:\n`;\n\nconst SUMMARY_REFINE_PROMPT = PromptTemplate.fromTemplate(\n summaryRefineTemplate\n);\n\nconst summarizeChain = loadSummarizationChain(llmSummary, {\n type: \"refine\",\n verbose: true,\n questionPrompt: SUMMARY_PROMPT,\n refinePrompt: SUMMARY_REFINE_PROMPT,\n});\n\nconst summary = await summarizeChain.run(docsSummary);\n\nreturn [{json: { summary } } ];" } }, "inputs": { "input": [ { "type": "main", "required": true, "maxConnections": 1 }, { "type": "ai_languageModel", "required": true, "maxConnections": 1 } ] }, "outputs": { "output": [ { "type": "main" } ] } }, "typeVersion": 1 }, { "id": "summarize-podcast-transcript-with-refinement-2", "name": "Set YouTube video ID", "type": "n8n-nodes-base.set", "position": [ -600, 20 ], "parameters": { "options": {}, "assignments": { "assignments": [ { "id": "c2dc2944-a7c7-44c3-a805-27a55baa452a", "name": "videoId", "type": "string", "value": "YOUR_YOUTUBE_VIDEO_ID" } ] } }, "typeVersion": 3.4 }, { "id": "summarize-podcast-transcript-with-refinement-3", "name": "OpenAI Chat Model", "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi", "position": [ -340, 220 ], "parameters": { "model": { "__rl": true, "mode": "list", "value": "gpt-4o-mini" }, "options": {} }, "typeVersion": 1.2 }, { "name": "Fetch the transcript", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 0, 0 ], "parameters": { "url": "https://www.searchapi.io/api/v1/search", "authentication": "genericCredentialType", "genericAuthType": "httpQueryAuth", "sendQuery": true, "queryParameters": { "parameters": [ { "name": "engine", "value": "youtube_transcripts" }, { "name": "video_id", "value": "={{ $json.videoId }}" } ] }, "options": {} }, "id": "summarize-podcast-transcript-with-refinement-4" } ], "pinData": {}, "connections": { "OpenAI Chat Model": { "ai_languageModel": [ [ { "node": "LangChain Code", "type": "ai_languageModel", "index": 0 } ] ] }, "Set YouTube video ID": { "main": [ [ { "node": "Fetch the transcript", "type": "main", "index": 0 } ] ] }, "When clicking \"Execute Workflow\"": { "main": [ [ { "node": "Set YouTube video ID", "type": "main", "index": 0 } ] ] }, "Fetch the transcript": { "main": [ [ { "node": "LangChain Code", "type": "main", "index": 0 } ] ] } }, "name": "Summarize Podcast Transcript with Refinement", "active": false }