Skip to content

Commit 080cb4c

Browse files
committed
mobile friendly
1 parent b7935c0 commit 080cb4c

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

app/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function Home() {
5050
const controller = new AbortController();
5151
const body: RequestBody = { messages: newMessages, model, apiKey };
5252

53-
const response = await fetch("/api/openai", {
53+
const response = await fetch("/api/chat", {
5454
method: "POST",
5555
headers: {
5656
"Content-Type": "application/json",
@@ -86,8 +86,8 @@ export default function Home() {
8686
};
8787

8888
return (
89-
<main className="container flex-1 w-full flex flex-wrapq">
90-
<div className="flex border flex-col justify-between w-full md:w-1/2">
89+
<main className="container flex-1 w-full flex flex-wrap">
90+
<div className="flex border md:border-r-0 flex-col justify-between w-full md:w-1/2">
9191
<div className="">
9292
<div className="">
9393
{messages.map((message) => {

next.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const nextConfig = {
33
experimental: {
44
appDir: true,
55
},
6-
runtime: "experimental-edge",
76
};
87

98
module.exports = nextConfig;

pages/api/chat.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { OpenAIStream } from "@/lib/utils";
2+
import { type RequestBody } from "@/types/type";
3+
4+
export const config = {
5+
runtime: "edge",
6+
};
7+
8+
export default async function chat(req: Request) {
9+
try {
10+
const { messages, model, apiKey } = (await req.json()) as RequestBody;
11+
12+
const stream = await OpenAIStream(messages, model, apiKey);
13+
14+
return new Response(stream);
15+
} catch (error) {
16+
console.error(error);
17+
return new Response("Error", { status: 500 });
18+
}
19+
}

0 commit comments

Comments
 (0)