update pay function

This commit is contained in:
2025-11-22 11:41:56 +08:00
parent a4b634abff
commit d8e4c737c5
397 changed files with 19572 additions and 9326 deletions

View File

@@ -0,0 +1,43 @@
import { ChatBody } from '@/types/types';
import { OpenAIStream } from '@/utils/streams/chatStream';
export const runtime = 'edge';
export async function GET(req: Request): Promise<Response> {
try {
const { inputMessage, model, apiKey } = (await req.json()) as ChatBody;
let apiKeyFinal;
if (apiKey) {
apiKeyFinal = apiKey;
} else {
apiKeyFinal = process.env.NEXT_PUBLIC_OPENAI_API_KEY;
}
const stream = await OpenAIStream(inputMessage, model, apiKeyFinal);
return new Response(stream);
} catch (error) {
console.error(error);
return new Response('Error', { status: 500 });
}
}
export async function POST(req: Request): Promise<Response> {
try {
const { inputMessage, model, apiKey } = (await req.json()) as ChatBody;
let apiKeyFinal;
if (apiKey) {
apiKeyFinal = apiKey;
} else {
apiKeyFinal = process.env.NEXT_PUBLIC_OPENAI_API_KEY;
}
const stream = await OpenAIStream(inputMessage, model, apiKeyFinal);
return new Response(stream);
} catch (error) {
console.error(error);
return new Response('Error', { status: 500 });
}
}