update pay function
This commit is contained in:
43
boilerplate-chakra-pro-main/app/api/chatAPI/route.ts
Normal file
43
boilerplate-chakra-pro-main/app/api/chatAPI/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user