Skip to content

Commit c462428

Browse files
committed
Fix small Next.js x TypeScript nits
1 parent b37bf49 commit c462428

File tree

8 files changed

+27
-42
lines changed

8 files changed

+27
-42
lines changed

app/api/assistants/files/route.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import OpenAI from "openai";
2-
import { assistantId } from "../../../assistant-config";
3-
4-
const openai = new OpenAI();
1+
import { assistantId } from "@/app/assistant-config";
2+
import { openai } from "@/app/openai";
53

64
// upload file to assistant's vector store
75
export async function POST(request) {
@@ -41,7 +39,7 @@ export async function GET() {
4139
};
4240
})
4341
);
44-
return new Response(JSON.stringify(filesArray));
42+
return Response.json(filesArray);
4543
}
4644

4745
// delete file from assistant's vector store

app/api/assistants/route.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import OpenAI from "openai";
2-
const openai = new OpenAI();
1+
import { openai } from "@/app/openai";
32

43
export const runtime = "nodejs";
54

@@ -35,5 +34,5 @@ export async function POST() {
3534
{ type: "file_search" },
3635
],
3736
});
38-
return new Response(JSON.stringify({ assistantId: assistant.id }));
37+
return Response.json({ assistantId: assistant.id });
3938
}

app/api/assistants/threads/[threadId]/actions/route.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import OpenAI from "openai";
2-
const openai = new OpenAI();
3-
4-
export const runtime = "nodejs";
1+
import { openai } from "@/app/openai";
52

63
// Send a new message to a thread
7-
export async function POST(request, { params }) {
8-
const body = await request.json();
9-
const toolCallOutputs = body.toolCallOutputs;
10-
const runId = body.runId;
11-
const threadId = params.threadId;
4+
export async function POST(request, { params: { threadId } }) {
5+
const { toolCallOutputs, runId } = await request.json();
126

137
const stream = openai.beta.threads.runs.submitToolOutputsStream(
148
threadId,

app/api/assistants/threads/[threadId]/messages/route.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import OpenAI from "openai";
2-
import { assistantId } from "../../../../../assistant-config";
3-
const openai = new OpenAI();
1+
import { assistantId } from "@/app/assistant-config";
2+
import { openai } from "@/app/openai";
43

54
export const runtime = "nodejs";
65

76
// Send a new message to a thread
8-
export async function POST(request, { params }) {
9-
const body = await request.json();
10-
const content = body.content;
11-
const threadId = params.threadId;
7+
export async function POST(request, { params: { threadId } }) {
8+
const { content } = await request.json();
129

1310
await openai.beta.threads.messages.create(threadId, {
1411
role: "user",

app/api/assistants/threads/route.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import OpenAI from "openai";
2-
const openai = new OpenAI();
1+
import { openai } from "@/app/openai";
32

43
export const runtime = "nodejs";
54

65
// Create a new thread
76
export async function POST() {
87
const thread = await openai.beta.threads.create();
9-
return new Response(JSON.stringify({ threadId: thread.id }));
8+
return Response.json({ threadId: thread.id });
109
}

app/openai.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import OpenAI from "openai";
2+
3+
export const openai = new OpenAI();

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
"@types/node": "20.12.7",
2020
"@types/react": "18.2.79",
2121
"typescript": "5.4.5"
22+
},
23+
"prettier": {
24+
"singleQuote": false
2225
}
2326
}

tsconfig.json

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"compilerOptions": {
3-
"lib": [
4-
"dom",
5-
"dom.iterable",
6-
"esnext"
7-
],
3+
"lib": ["dom", "dom.iterable", "esnext"],
84
"allowJs": true,
95
"skipLibCheck": true,
106
"strict": false,
@@ -20,15 +16,11 @@
2016
{
2117
"name": "next"
2218
}
23-
]
19+
],
20+
"paths": {
21+
"@/*": ["./*"]
22+
}
2423
},
25-
"include": [
26-
"next-env.d.ts",
27-
".next/types/**/*.ts",
28-
"**/*.ts",
29-
"**/*.tsx"
30-
],
31-
"exclude": [
32-
"node_modules"
33-
]
24+
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
25+
"exclude": ["node_modules"]
3426
}

0 commit comments

Comments
 (0)