Write a function that adjusts the system prompt based on user's skill level or preference.
Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer
Implementation:
function createSystemPrompt(userProfile) {
const basePrompt = "You are a helpful AI assistant.";
let dynamicInstruction = "";
if (userProfile.expertise === "expert") {
dynamicInstruction = "Provide concise, technical answers. Assume deep knowledge.";
} else if (userProfile.expertise === "beginner") {
dynamicInstruction = "Explain concepts simply with analogies. Avoid jargon.";
}
if (userProfile.tone === "formal") {
dynamicInstruction += " Maintain a professional tone.";
} else {
dynamicInstruction += " Be conversational and friendly.";
}
return `${basePrompt} ${dynamicInstruction}`;
}
// Usage
// const prompt = createSystemPrompt({ expertise: 'expert', tone: 'formal' });
// openai.chat.completions.create({
// messages: [{ role: "system", content: prompt }, ...]
// });