Skip to content

Fix JSON parsing errors and Docker healthcheck #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
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 docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
networks:
- app-network
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000/health || exit 1"]
test: ["CMD-SHELL", "curl -f http://localhost:3000 || exit 1"]
interval: 30s
timeout: 10s
retries: 5
Expand Down
20 changes: 18 additions & 2 deletions src/routes/api/audio-files/[id]/transcript/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,25 @@ export async function GET({ params, locals }) {
// Parse the transcript
let transcript = [];
try {
transcript = file.transcript ? JSON.parse(file.transcript) : [];
if (file.transcript) {
if (typeof file.transcript === 'string') {
try {
transcript = JSON.parse(file.transcript);
} catch (parseError) {
console.error('Failed to parse transcript string:', parseError);
}
} else if (Array.isArray(file.transcript)) {
transcript = file.transcript;
} else if (typeof file.transcript === 'object') {
// Try to convert object to array if possible
console.warn('Transcript is an object, not an array or string. Attempting to handle.');
transcript = Array.isArray(Object.values(file.transcript))
? Object.values(file.transcript)
: [file.transcript];
}
}
} catch (e) {
console.error('Failed to parse transcript:', e);
console.error('Failed to process transcript:', e);
}

return json({
Expand Down
19 changes: 17 additions & 2 deletions src/routes/api/summarize/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ export async function POST({ request }) {
return new Response('Missing fileId, prompt, or transcript', { status: 400 });
}

// Parse transcript if it's an object instead of a string
let transcriptText;
try {
if (typeof transcript === 'string') {
transcriptText = transcript;
} else if (typeof transcript === 'object') {
// If it's already an object, stringify it for use in the prompt
transcriptText = JSON.stringify(transcript);
} else {
throw new Error(`Invalid transcript format: ${typeof transcript}`);
}
} catch (transcriptError) {
return new Response(`Failed to parse transcript: ${transcriptError.message}`, { status: 400 });
}

const openai = getOpenAI();
if (!openai) {
return new Response('AI client not initialized. Check your OPENAI_BASE_URL, OLLAMA_BASE_URL or OPENAI_API_KEY configuration.', { status: 500 });
Expand All @@ -70,7 +85,7 @@ export async function POST({ request }) {
const messages = [
{
role: 'user',
content: `${prompt}\n\nTranscript:\n${transcript}`
content: `${prompt}\n\nTranscript:\n${transcriptText}`
}
];

Expand Down Expand Up @@ -125,7 +140,7 @@ export async function POST({ request }) {
messages: [
{
role: "user",
content: `${prompt}\n\nTranscript:\n${transcript}`
content: `${prompt}\n\nTranscript:\n${transcriptText}`
}
]
})
Expand Down