-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added caching for images (need to fix) * added part fetching (needs fixing) * Add more clicky buttons * Add endpoint for project suggestions * Improve project idea prompt * Add project idea section --------- Co-authored-by: Max Wofford <max@maxwofford.com>
- Loading branch information
1 parent
457d5b2
commit ea455cf
Showing
9 changed files
with
358 additions
and
255 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,40 @@ | ||
import OpenAI from 'openai'; | ||
|
||
const generateProjectIdea = async (parts) => { | ||
|
||
let prompt = `I'm running a hardware program around the raspberry pi pico w where high schoolers will build a simple project using the following parts. Please propose a simple project in 1-2 sentences to use as a prompt for the high schoolers to build with: | ||
` | ||
parts.forEach((part) => { | ||
prompt += `- ${part}\n` | ||
}) | ||
|
||
prompt += ` | ||
The project should only involve household items like lamps. The project should only use sensors provided, and use those sensors for their intended use. For example, an accelerometer cannot be used to measure humidity or tilt.` | ||
|
||
// expects OPENAI_API_KEY | ||
const openai = new OpenAI(); | ||
const chatCompletion = await openai.chat.completions.create({ | ||
messages: [{ role: 'user', content: prompt }], | ||
model: 'gpt-3.5-turbo', | ||
}); | ||
|
||
return chatCompletion.choices[0].message.content | ||
} | ||
|
||
export default async function handler(req, res) { | ||
const requestedParts = req.body.parts | ||
|
||
const availablePartsReq = await fetch('https://hackclub.com/api/bin/wokwi/parts') | ||
const availableParts = await availablePartsReq.json() | ||
|
||
// check that the requested parts are in the available parts | ||
const parts = requestedParts.map((requestedPart) => { | ||
return availableParts.find((availablePart) => availablePart.wokwiName === requestedPart)?.name | ||
}) | ||
|
||
const recommendation = await generateProjectIdea(parts) | ||
|
||
res.send({recommendation, parts}) | ||
} | ||
|
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
Oops, something went wrong.