CognxSafeTrack commited on
Commit ·
3ec3d38
1
Parent(s): 1fe7477
build: force deep rebuild v4 with improved logging
Browse files- Dockerfile +1 -1
- apps/api/src/routes/ai.ts +2 -3
- apps/api/src/services/ai/openai-provider.ts +13 -2
Dockerfile
CHANGED
|
@@ -41,7 +41,7 @@ EXPOSE 7860
|
|
| 41 |
ENV PORT=7860
|
| 42 |
|
| 43 |
# Force Docker cache invalidation - bump date to trigger clean rebuild
|
| 44 |
-
ENV REBUILD_DATE="2026-02-
|
| 45 |
|
| 46 |
# Start the API directly with tsx
|
| 47 |
CMD ["sh", "-c", "tsx apps/api/src/index.ts"]
|
|
|
|
| 41 |
ENV PORT=7860
|
| 42 |
|
| 43 |
# Force Docker cache invalidation - bump date to trigger clean rebuild
|
| 44 |
+
ENV REBUILD_DATE="2026-02-24-v4-debug"
|
| 45 |
|
| 46 |
# Start the API directly with tsx
|
| 47 |
CMD ["sh", "-c", "tsx apps/api/src/index.ts"]
|
apps/api/src/routes/ai.ts
CHANGED
|
@@ -93,11 +93,10 @@ export async function aiRoutes(fastify: FastifyInstance) {
|
|
| 93 |
});
|
| 94 |
|
| 95 |
const { audioBase64, filename } = bodySchema.parse(request.body);
|
| 96 |
-
|
| 97 |
-
console.log(`[AI] Transcribing audio: ${filename}`);
|
| 98 |
-
|
| 99 |
const buffer = Buffer.from(audioBase64, 'base64');
|
| 100 |
|
|
|
|
|
|
|
| 101 |
try {
|
| 102 |
const { buffer: audioToTranscribe, format } = await convertToMp3IfNeeded(buffer, filename);
|
| 103 |
console.log(`[AI] Calling transcribeAudio for format: ${format}`);
|
|
|
|
| 93 |
});
|
| 94 |
|
| 95 |
const { audioBase64, filename } = bodySchema.parse(request.body);
|
|
|
|
|
|
|
|
|
|
| 96 |
const buffer = Buffer.from(audioBase64, 'base64');
|
| 97 |
|
| 98 |
+
console.log(`[AI] 🚀 DEPLOY V4 - Transcribing: ${filename} (size: ${buffer.length})`);
|
| 99 |
+
|
| 100 |
try {
|
| 101 |
const { buffer: audioToTranscribe, format } = await convertToMp3IfNeeded(buffer, filename);
|
| 102 |
console.log(`[AI] Calling transcribeAudio for format: ${format}`);
|
apps/api/src/services/ai/openai-provider.ts
CHANGED
|
@@ -18,7 +18,12 @@ export class OpenAIProvider implements LLMProvider {
|
|
| 18 |
private openai: OpenAI;
|
| 19 |
|
| 20 |
constructor(apiKey: string) {
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
async generateStructuredData<T>(prompt: string, schema: z.ZodSchema<T>): Promise<T> {
|
|
@@ -68,7 +73,13 @@ export class OpenAIProvider implements LLMProvider {
|
|
| 68 |
});
|
| 69 |
return response.text;
|
| 70 |
} catch (err: any) {
|
| 71 |
-
console.error('[OPENAI] ❌
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
if (err?.status === 429 || err?.code === 'insufficient_quota') {
|
| 73 |
console.warn('[OPENAI] 429 on transcribeAudio');
|
| 74 |
throw new QuotaExceededError();
|
|
|
|
| 18 |
private openai: OpenAI;
|
| 19 |
|
| 20 |
constructor(apiKey: string) {
|
| 21 |
+
console.log('[OPENAI] Initializing SDK with custom fetch wrapper...');
|
| 22 |
+
this.openai = new OpenAI({
|
| 23 |
+
apiKey,
|
| 24 |
+
timeout: 30_000, // 30s timeout for audio/STT
|
| 25 |
+
maxRetries: 2,
|
| 26 |
+
});
|
| 27 |
}
|
| 28 |
|
| 29 |
async generateStructuredData<T>(prompt: string, schema: z.ZodSchema<T>): Promise<T> {
|
|
|
|
| 73 |
});
|
| 74 |
return response.text;
|
| 75 |
} catch (err: any) {
|
| 76 |
+
console.error('[OPENAI] ❌ Connection or API Error:', {
|
| 77 |
+
name: err?.name,
|
| 78 |
+
message: err?.message,
|
| 79 |
+
status: err?.status,
|
| 80 |
+
code: err?.code,
|
| 81 |
+
stack: err?.stack
|
| 82 |
+
});
|
| 83 |
if (err?.status === 429 || err?.code === 'insufficient_quota') {
|
| 84 |
console.warn('[OPENAI] 429 on transcribeAudio');
|
| 85 |
throw new QuotaExceededError();
|