Skip to content

Commit

Permalink
Fix small Next.js x TypeScript nits
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed May 2, 2024
1 parent b37bf49 commit c462428
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 42 deletions.
8 changes: 3 additions & 5 deletions app/api/assistants/files/route.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import OpenAI from "openai";
import { assistantId } from "../../../assistant-config";

const openai = new OpenAI();
import { assistantId } from "@/app/assistant-config";
import { openai } from "@/app/openai";

// upload file to assistant's vector store
export async function POST(request) {
Expand Down Expand Up @@ -41,7 +39,7 @@ export async function GET() {
};
})
);
return new Response(JSON.stringify(filesArray));
return Response.json(filesArray);
}

// delete file from assistant's vector store
Expand Down
5 changes: 2 additions & 3 deletions app/api/assistants/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import OpenAI from "openai";
const openai = new OpenAI();
import { openai } from "@/app/openai";

export const runtime = "nodejs";

Expand Down Expand Up @@ -35,5 +34,5 @@ export async function POST() {
{ type: "file_search" },
],
});
return new Response(JSON.stringify({ assistantId: assistant.id }));
return Response.json({ assistantId: assistant.id });
}
12 changes: 3 additions & 9 deletions app/api/assistants/threads/[threadId]/actions/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import OpenAI from "openai";
const openai = new OpenAI();

export const runtime = "nodejs";
import { openai } from "@/app/openai";

// Send a new message to a thread
export async function POST(request, { params }) {
const body = await request.json();
const toolCallOutputs = body.toolCallOutputs;
const runId = body.runId;
const threadId = params.threadId;
export async function POST(request, { params: { threadId } }) {
const { toolCallOutputs, runId } = await request.json();

const stream = openai.beta.threads.runs.submitToolOutputsStream(
threadId,
Expand Down
11 changes: 4 additions & 7 deletions app/api/assistants/threads/[threadId]/messages/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import OpenAI from "openai";
import { assistantId } from "../../../../../assistant-config";
const openai = new OpenAI();
import { assistantId } from "@/app/assistant-config";
import { openai } from "@/app/openai";

export const runtime = "nodejs";

// Send a new message to a thread
export async function POST(request, { params }) {
const body = await request.json();
const content = body.content;
const threadId = params.threadId;
export async function POST(request, { params: { threadId } }) {
const { content } = await request.json();

await openai.beta.threads.messages.create(threadId, {
role: "user",
Expand Down
5 changes: 2 additions & 3 deletions app/api/assistants/threads/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import OpenAI from "openai";
const openai = new OpenAI();
import { openai } from "@/app/openai";

export const runtime = "nodejs";

// Create a new thread
export async function POST() {
const thread = await openai.beta.threads.create();
return new Response(JSON.stringify({ threadId: thread.id }));
return Response.json({ threadId: thread.id });
}
3 changes: 3 additions & 0 deletions app/openai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import OpenAI from "openai";

export const openai = new OpenAI();
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"@types/node": "20.12.7",
"@types/react": "18.2.79",
"typescript": "5.4.5"
},
"prettier": {
"singleQuote": false
}
}
22 changes: 7 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"compilerOptions": {
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
Expand All @@ -20,15 +16,11 @@
{
"name": "next"
}
]
],
"paths": {
"@/*": ["./*"]
}
},
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}

0 comments on commit c462428

Please sign in to comment.