chore: add undici as a dependency

This commit is contained in:
2025-11-29 21:26:22 +08:00
parent 823df2cbf6
commit edd0a85439
6 changed files with 2437 additions and 100 deletions
+13 -5
View File
@@ -6,6 +6,12 @@ import { downloadFile } from "@/lib/minio";
import { extractAudio } from "../media";
import { z } from "zod";
import { zodResponseFormat } from "openai/helpers/zod";
import { ProxyAgent, setGlobalDispatcher } from "undici";
const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
if (proxy) {
setGlobalDispatcher(new ProxyAgent(proxy));
}
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
@@ -49,14 +55,16 @@ async function transcriptAudio(audio: Buffer | string) {
});
const data = completion.choices?.[0]?.message
if (!data) {
console.log("转写结果", data.content);
if (!data || !data.content) {
throw new Error("No STT result returned from model");
}
const parsed = SttSchema.safeParse(data?.content).data;
if (!parsed) {
throw new Error("Failed to parse STT result with zod");
try {
return JSON.parse(data.content) as SttResult;
} catch (e) {
throw new Error("Failed to parse STT result JSON");
}
return parsed;
}
export async function transcriptAweme(awemeId: string): Promise<SttResult> {
+1
View File
@@ -1,3 +1,4 @@
export const runtime = "nodejs";
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
import type { FeedItem, FeedResponse } from '@/app/types/feed';