chore: add undici as a dependency
This commit is contained in:
+13
-5
@@ -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,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';
|
||||
|
||||
Reference in New Issue
Block a user