-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from replicate/use-next-js-app-router
migrate from Next.js Page router to App router
- Loading branch information
Showing
11 changed files
with
607 additions
and
316 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { NextResponse } from 'next/server'; | ||
import Replicate from 'replicate'; | ||
|
||
const replicate = new Replicate({ | ||
auth: process.env.REPLICATE_API_TOKEN, | ||
}); | ||
|
||
export async function GET(request, {params}) { | ||
const { id } = params; | ||
const prediction = await replicate.predictions.get(id); | ||
|
||
if (prediction?.error) { | ||
return NextResponse.json({ detail: prediction.error }, { status: 500 }); | ||
} | ||
|
||
return NextResponse.json(prediction); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NextResponse } from 'next/server'; | ||
import Replicate from 'replicate'; | ||
|
||
const replicate = new Replicate({ | ||
auth: process.env.REPLICATE_API_TOKEN, | ||
}); | ||
|
||
export async function POST(request) { | ||
if (!process.env.REPLICATE_API_TOKEN) { | ||
throw new Error( | ||
'The REPLICATE_API_TOKEN environment variable is not set. See README.md for instructions on how to set it.' | ||
); | ||
} | ||
|
||
const { prompt } = await request.json(); | ||
|
||
const prediction = await replicate.predictions.create({ | ||
version: '8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f', | ||
input: { prompt }, | ||
}); | ||
|
||
if (prediction?.error) { | ||
return NextResponse.json({ detail: prediction.error }, { status: 500 }); | ||
} | ||
|
||
return NextResponse.json(prediction, { status: 201 }); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import "../styles/globals.css"; | ||
|
||
export default function RootLayout({ | ||
// Layouts must accept a children prop. | ||
// This will be populated with nested layouts or pages | ||
children, | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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
Oops, something went wrong.