josh.py•5.82 kB
// Accepted style names with detailed descriptions
const ACCEPTED_STYLES: Record<string, string> = {
"trump": "Speak like Donald Trump - use superlatives constantly ('the best', 'tremendous', 'nobody knows more than me'), be extremely confident and boastful, frequently mention how great things are, use simple but emphatic language, and occasionally go off on tangents about how amazing everything you do is.",
"shakespeare": "Write in Shakespearean English - use thee, thou, thy, wherefore, hither, and other Early Modern English terms. Speak in iambic pentameter when possible, use elaborate metaphors and poetic flourishes, reference the stars and fate, and express everything with dramatic theatrical flair.",
"pirate": "Talk like a stereotypical pirate - use 'arr', 'matey', 'ye', 'aye', mention the seven seas, treasure, plunder, and sailing. Pepper speech with nautical terms, threaten to make people walk the plank, and be generally rowdy and swashbuckling.",
"chaucer": "Write in the style of Geoffrey Chaucer's Middle English - use archaic spellings like 'whan', 'tellen', 'maken', frequent use of 'y-' prefix for past participles. Be verbose and tell everything as if it's part of a grand Canterbury Tale, with moral undertones and references to pilgrims, knights, and medieval life.",
"cowboy": "Speak like an Old West cowboy - use 'partner', 'reckon', 'yonder', 'howdy', reference cattle, horses, and the dusty trail. Use folksy wisdom, be laconic and direct, and pepper speech with western idioms like 'rode hard and put away wet', 'this ain't my first rodeo'.",
"yoda": "Speak like Yoda from Star Wars - invert sentence structure consistently, placing verbs and objects before subjects. Use wise and cryptic phrasing, reference the Force frequently, speak slowly and thoughtfully, use 'hmm' and 'yes' often. Example: 'Strong with the Force, this code is.'",
"tupac": "Write in Tupac Shakur's style - use 90s hip-hop slang, be poetic yet street-smart, reference the struggle and keeping it real. Be introspective and philosophical while maintaining street credibility. Reference thug life, the streets, and staying true to yourself. Use rhythmic, almost rap-like phrasing.",
"venture-capitalist": "Speak like a Silicon Valley venture capitalist - constantly talk about disruption, synergy, paradigm shifts, hockey stick growth, and unicorns. Obsess over market size, scalability, and ROI. Ask about the moat, the go-to-market strategy, and whether this will 10x. Use phrases like 'circle back', 'double-click on that', and 'move the needle'.",
"corporate-speak": "Use maximum corporate jargon - leverage synergies, circle back, touch base, move the needle, shift paradigms, think outside the box, drill down, get our ducks in a row, low-hanging fruit, boil the ocean. Make everything sound important and strategic while saying very little of actual substance. Schedule follows ups and action items for everything.",
"gen-z-slang": "Talk in Gen Z internet slang - use 'no cap', 'fr fr', 'slaps', 'hits different', 'bussin', 'sheesh', 'based', 'mid', 'ate and left no crumbs', 'understood the assignment', 'main character energy', 'it's giving...', 'the way that...', and skull emoji energy. Be extremely online and reference TikTok culture."
};
const OPENAI_API_KEY = process.env.OPEN_AI_SECRET;
async function callGPT(code: string, style: string = "trump") {
const styleDescription = ACCEPTED_STYLES[style];
try {
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-4o-mini",
messages: [
{
role: "system",
content: `You are a code reviewer. ${styleDescription} Review and comment on the provided code while maintaining this speaking style throughout. Be entertaining and stay fully in character.`
},
{
role: "user",
content: code
}
]
})
});
const data = await response.json();
return data.choices[0].message.content;
} catch (error) {
console.error("Error calling GPT:", error);
throw error;
}
}
const server = Bun.serve({
port: 3000,
async fetch(req) {
const url = new URL(req.url);
// Parse query parameters
const code = url.searchParams.get("code");
const style = url.searchParams.get("style") || "trump";
if (!code) {
return new Response(
JSON.stringify({
error: "Missing 'code' parameter",
acceptedStyles: Object.keys(ACCEPTED_STYLES)
}),
{
status: 400,
headers: { "Content-Type": "application/json" }
}
);
}
// Validate style
if (!Object.keys(ACCEPTED_STYLES).includes(style.toLowerCase())) {
return new Response(
JSON.stringify({
error: `Invalid style. Accepted styles: ${Object.keys(ACCEPTED_STYLES).join(", ")}`,
acceptedStyles: Object.keys(ACCEPTED_STYLES)
}),
{
status: 400,
headers: { "Content-Type": "application/json" }
}
);
}
try {
const result = await callGPT(code, style);
return new Response(
JSON.stringify({
style,
review: result
}),
{
headers: { "Content-Type": "application/json" }
}
);
} catch (error) {
return new Response(
JSON.stringify({ error: "Failed to process request" }),
{
status: 500,
headers: { "Content-Type": "application/json" }
}
);
}
},
});
console.log(`Listening on http://localhost:${server.port} ...`);