-
Notifications
You must be signed in to change notification settings - Fork 17
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 #416 from whtsupbab3/332-generate-bounty-idea
332 generate bounty idea
- Loading branch information
Showing
3 changed files
with
104 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
DATABASE_URL="postgresql://…" | ||
ADMINS="0x…,0x…,0x…" | ||
ADMINS="0x…,0x…,0x…" | ||
OPENAI_API_KEY="sk-…" |
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,45 @@ | ||
const prompt = `Generate unique, creative, and fun bounty ideas for the "Pics or It Didn't Happen" (poidh) website. Each bounty should encourage users to engage in amusing, interesting, or surprising activities that can be easily documented with a photo, screenshot, or video. | ||
Ensure the ideas are diverse, spanning different themes such as real-life actions, contributions, playful tasks, or simple creative(could be developer) projects. | ||
Ideas must remain achievable and enjoyable for users of all skill levels. A user should share result either in video or in photo. Include: | ||
Title: A short, catchy description of the bounty (max 50 characters). | ||
Description: A clear and engaging explanation of what the user must do to complete the bounty (max 350 characters). | ||
Return the ideas in JSON format like this: | ||
{ 'title': '...', 'description': '...' }.`; | ||
|
||
export async function POST(): Promise<Response> { | ||
const OPENAI_API_KEY = process.env.OPENAI_API_KEY; | ||
if (!OPENAI_API_KEY) { | ||
throw new Error('Missing OpenAI API key'); | ||
} | ||
|
||
const response = await fetch('https://api.openai.com/v1/chat/completions', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${OPENAI_API_KEY}`, | ||
}, | ||
body: JSON.stringify({ | ||
model: 'gpt-4-turbo', | ||
messages: [ | ||
{ | ||
role: 'system', | ||
content: prompt, | ||
}, | ||
{ | ||
role: 'user', | ||
content: 'Generate a bounty idea for a person to do.', | ||
}, | ||
], | ||
max_tokens: 100, | ||
temperature: 1, | ||
response_format: { type: 'json_object' }, | ||
}), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Error: ${response.status}`); | ||
} | ||
|
||
const data = await response.json(); | ||
return Response.json(data.choices[0].message.content); | ||
} |
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