Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea generator in shipyard #1047

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"fmt": "prettier --write ."
},
"dependencies": {
"@ai-sdk/openai": "^1.0.11",
"@hackclub/icons": "^0.0.15",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-popover": "^1.1.2",
Expand All @@ -24,6 +25,7 @@
"@vercel/kv": "^3.0.0",
"@vercel/postgres": "^0.10.0",
"@vercel/speed-insights": "^1.0.12",
"ai": "^4.0.22",
"airtable": "^0.12.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
Expand Down
89 changes: 89 additions & 0 deletions src/app/api/ideagen/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// // Enable streaming responses
// export const runtime = 'edge'

// export async function POST(req) {
// try {
// const { prompt } = await req.json()

// if (!prompt) {
// return NextResponse.json({ error: 'Prompt is required' }, { status: 400 })
// }

// const apiKey = process.env.OPENAI_API_KEY
// if (!apiKey) {
// throw new Error('Missing OpenAI API key in environment variables')
// }

// const response = await fetch('https://api.openai.com/v1/chat/completions', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// Authorization: `Bearer ${apiKey}`,
// },
// body: JSON.stringify({
// model: 'gpt-4-turbo',
// messages: [
// {
// role: 'system',
// content:
// 'You are an embedded model that takes a project idea and outputs an action plan of how one could go about building it to a creative developer, preferably in about 4 bullet points. Do not preface your answer. There is no option to converse - your first answer will be displayed on the website. Do not wafffle. Keep it concise and technical.',
// },
// {
// role: 'user',
// content: prompt,
// },
// ],
// stream: true,
// }),
// })

// if (!response.ok) {
// throw new Error(
// `OpenAI API error: ${response.status} ${response.statusText}`,
// )
// }

// // Create a TransformStream for handling the response
// console.log({ stream })

// // Return the stream with the appropriate header
// return new Response(stream, {
// headers: {
// 'Content-Type': 'text/event-stream',
// 'Cache-Control': 'no-cache',
// Connection: 'keep-alive',
// },
// })
// } catch (error) {
// console.error('Error:', error)
// return NextResponse.json({ error: error.message }, { status: 500 })
// }
// }

import { streamText } from 'ai'
import { openai } from '@ai-sdk/openai'

// This method must be named GET
export async function POST(request) {
const response = await streamText({
model: openai('gpt-4o'),
messages: [
{
role: 'system',
content:
'You are an embedded model that takes a project idea and outputs an action plan of how one could go about building it to a creative developer, preferably in about 4 bullet points. Your explaination should not include dumb stuff like "testing" but should describe the subsystems and how they will fit together. Do not preface your answer. There is no option to converse - your first answer will be displayed on the website. Do not wafffle. Use plaintext only. No markdown. Keep it extremely concise and technical. Remember to number the bullet points!',
},
{
role: 'user',
content: (await request.json()).msg,
},
],
stream: true,
})
// Respond with the stream
return response.toTextStreamResponse({
headers: {
'Content-Type': 'text/event-stream',
},
})
}
Loading
Loading