-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81edbfc
commit 954cea8
Showing
5 changed files
with
53 additions
and
45 deletions.
There are no files selected for viewing
48 changes: 23 additions & 25 deletions
48
examples/next-website/app/api/assistant/file/[fileId]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
import { OpenAI } from "openai"; | ||
import { z } from "zod"; | ||
|
||
import { OpenAI } from 'openai'; | ||
import { z } from 'zod'; | ||
|
||
const routeContextSchema = z.object({ | ||
params: z.object({ | ||
fileId: z.string(), | ||
}), | ||
}) | ||
params: z.object({ | ||
fileId: z.string(), | ||
}), | ||
}); | ||
|
||
export async function GET( | ||
request: Request, | ||
context: z.infer<typeof routeContextSchema> | ||
request: Request, | ||
context: z.infer<typeof routeContextSchema>, | ||
) { | ||
const { params } = routeContextSchema.parse(context); | ||
|
||
const { params } = routeContextSchema.parse(context) | ||
|
||
const openai = new OpenAI({ | ||
// eslint-disable-next-line turbo/no-undeclared-env-vars | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
const openai = new OpenAI({ | ||
// eslint-disable-next-line turbo/no-undeclared-env-vars | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
||
const [file, fileContent] = await Promise.all([ | ||
openai.files.retrieve(params.fileId), | ||
openai.files.content(params.fileId), | ||
]); | ||
const [file, fileContent] = await Promise.all([ | ||
openai.files.retrieve(params.fileId), | ||
openai.files.content(params.fileId), | ||
]); | ||
|
||
return new Response(fileContent.body, { | ||
headers: { | ||
"Content-Disposition": `attachment; filename="${file.filename}"`, | ||
}, | ||
}); | ||
} | ||
return new Response(fileContent.body, { | ||
headers: { | ||
'Content-Disposition': `attachment; filename="${file.filename}"`, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters