Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
node-version: 22.x
- run: npm ci
- run: npm run audit
- run: npm test
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This an AWS SAM project that takes podcast transcripts generated by [Podwhispere
An example of a Pull Request generated by this project can be found [here](https://github.com/awsbites/aws-bites-site/pull/143).

## GenAI / LLM use
We currently use the [Anthropic Claude V2](https://www.anthropic.com/index/claude-2) Large Language Model (LLM) in Amazon Bedrock
We currently use an [Anthropic Claude](https://www.anthropic.com) Large Language Model (LLM) in Amazon Bedrock

## System Overview

Expand Down
46 changes: 36 additions & 10 deletions lib/summarisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import envs from './envs'
import { createPrompt } from './prompt-template'
import type { Summary, Transcript } from './types'

const MODEL_ID = 'anthropic.claude-v2'
const MODEL_ID = 'eu.anthropic.claude-sonnet-4-20250514-v1:0'

/**
* Based on a Podwhisperer transcript, use the LLM to create an episode summary and chapters
Expand All @@ -15,18 +15,30 @@ export async function createSummary(
options: { bedrockRegion?: string } = {},
): Promise<Summary> {
const { bedrockRegion } = options

const brClient = new BedrockRuntimeClient({
region: bedrockRegion === undefined ? envs.BEDROCK_REGION : bedrockRegion,
region: bedrockRegion ?? envs.BEDROCK_REGION,
})

const prompt = createPrompt(transcript)

const modelInput = JSON.stringify({
prompt,
max_tokens_to_sample: 5000,
anthropic_version: 'bedrock-2023-05-31',
max_tokens: 5000,
temperature: 0.5,
top_k: 250,
top_p: 1,
stop_sequences: [],
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: prompt,
},
],
},
],
})

const invokeModelCommand = new InvokeModelCommand({
Expand All @@ -37,10 +49,24 @@ export async function createSummary(
})

const modelResponse = await brClient.send(invokeModelCommand)
const { completion } = JSON.parse(modelResponse.body.transformToString('utf8'))
const jsonStart: number = completion.indexOf('{')
const jsonEnd: number = completion.lastIndexOf('}')
const jsonPart = completion.substring(jsonStart, jsonEnd + 1)
const summary = JSON.parse(jsonPart)

const raw = await modelResponse.body.transformToString('utf8')
const parsed = JSON.parse(raw) as {
content?: Array<{ type: string; text?: string }>
stop_reason?: string
usage?: unknown
}

const outputText = parsed?.content?.find((c) => c.type === 'text')?.text ?? ''

const jsonStart = outputText.indexOf('{')
const jsonEnd = outputText.lastIndexOf('}')
if (jsonStart === -1 || jsonEnd === -1 || jsonEnd <= jsonStart) {
throw new Error('Model did not return JSON content as expected.')
}

const jsonPart = outputText.substring(jsonStart, jsonEnd + 1)
const summary: Summary = JSON.parse(jsonPart)

return summary
}
Loading