-
Notifications
You must be signed in to change notification settings - Fork 469
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 #49 from leerob/update
Update to AI SDK + App Router.
- Loading branch information
Showing
20 changed files
with
1,205 additions
and
2,772 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,39 @@ | ||
import { Configuration, OpenAIApi } from 'openai-edge'; | ||
import { OpenAIStream, StreamingTextResponse } from 'ai'; | ||
|
||
// Create an OpenAI API client (that's edge friendly!) | ||
const config = new Configuration({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
const openai = new OpenAIApi(config); | ||
|
||
// Set the runtime to edge for best performance | ||
export const runtime = 'edge'; | ||
|
||
export async function POST(req: Request) { | ||
const { vibe, bio } = await req.json(); | ||
|
||
// Ask OpenAI for a streaming completion given the prompt | ||
const response = await openai.createChatCompletion({ | ||
model: 'gpt-3.5-turbo', | ||
stream: true, | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: `Generate 2 ${vibe} twitter biographies with no hashtags and clearly labeled "1." and "2.". ${ | ||
vibe === 'Funny' | ||
? "Make sure there is a joke in there and it's a little ridiculous." | ||
: null | ||
} | ||
Make sure each generated biography is less than 160 characters, has short sentences that are found in Twitter bios, and base them on this context: ${bio}${ | ||
bio.slice(-1) === '.' ? '' : '.' | ||
}`, | ||
}, | ||
], | ||
}); | ||
|
||
// Convert the response into a friendly text-stream | ||
const stream = OpenAIStream(response); | ||
// Respond with the stream | ||
return new StreamingTextResponse(stream); | ||
} |
File renamed without changes.
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,38 @@ | ||
import { Analytics } from '@vercel/analytics/react'; | ||
import { Metadata } from 'next'; | ||
import '../styles/globals.css'; | ||
|
||
const title = 'Twitter Bio Generator'; | ||
const description = 'Generate your next Twitter bio in seconds.'; | ||
|
||
export const metadata: Metadata = { | ||
metadataBase: new URL('https://twitterbio.io'), | ||
title, | ||
description, | ||
openGraph: { | ||
title, | ||
description, | ||
locale: 'en_US', | ||
type: 'website', | ||
}, | ||
twitter: { | ||
card: 'summary_large_image', | ||
title, | ||
description, | ||
}, | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
{children} | ||
<Analytics /> | ||
</body> | ||
</html> | ||
); | ||
} |
File renamed without changes
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 was deleted.
Oops, something went wrong.
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.
811ad42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
twitterbio – ./
twitterbio-git-main-randomteam.vercel.app
twitterbio-randomteam.vercel.app
twitterbio.io
www.twitterbio.io