CoolFace
Apppublic

Shrook21/Code-Assistant

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
prompts.py113 linesDownload Raw Back to prompts
1#-------------------------------Classification Prompt-----------------------------
2# def classify_prompt(user_input: str) -> str:
3#     return f"""You are an expert AI assistant. Decide the user's intent: do they want code to be *generated* or *explained*?
4
5# Classify only as:
6# - generate
7# - explain
8
9# Examples:
10# - "write a function to sort a list" → generate
11# - "explain this function: def foo(x): return x+1" → explain
12# - "generate function that add two numbers" → generate
13# - "give me function that..." → generate
14
15# User input:
16# {user_input}
17
18# Expected output: just one word (e.g. generate or explain or something else).
19# """
20def classify_prompt(user_input: str) -> str:
21    return f"""You are an expert coding assistant.
22
23Your task is to classify the user's intent based on their input. Choose one of the following categories:
24
25- generate → if they are asking you to write or create code.
26- explain → if they are asking you to analyze, interpret, or describe existing code.
27- unclear → if the input is ambiguous or irrelevant to code generation or explanation.
28
29Examples:
30- "write a function to sort a list" → generate
31- "explain this function: def foo(x): return x+1" → explain
32- "generate function that adds two numbers" → generate
33- "give me a function that reverses a string" → generate
34- "what is the time complexity of this code?" → explain
35- "I love pizza!" → unclear
36- "what's the best programming language?" → unclear
37- "can you help me?" → unclear
38
39User input:
40{user_input}
41
42Respond with only one word: generate, explain, or unclear.
43"""
44
45#------------------------------------Explanation Prompt----------------------------------------------
46def explain_prompt(code: str) -> str:
47    return f"""You are an expert programmer and technical writer.
48
49Your task is to explain the following Python code in simple terms so that a junior developer or student can understand it.
50
51Explain:
521. What each part does
532. The overall purpose of the code
543. How it works step by step
55
56Be clear and concise.
57
58CODE:
59{code}
60"""
61
62#------------------------------------Generate Prompt----------------------------------------------
63def generate_prompt(user_input: str, context: str) -> str:
64    return f"""You are an expert code generator.
65
66Below are relevant code snippets from previous solutions:
67{context}
68
69Now generate a complete Python function for the following request:
70{user_input}
71
72Requirements:
73- Provide ONLY the function code
74- Include proper function definition with parameters
75- Add a docstring if appropriate
76- Make it ready to use
77"""
78
79#------------------------------------Fallback Prompt----------------------------------------------
80# def fallback_prompt(user_input: str) -> str:
81#     return f"""You are an expert programmer.
82
83# A user gave the following input:
84# \"\"\"{user_input}\"\"\"
85
86# Your task is:
87# 1. Decide if the request is related to code (e.g., asking to generate or explain code).
88# 2. If the input is AMBIGUOUS or unclear, respond with: 
89#    "I don't fully understand your question. Could you please clarify what you want me to do?"
90# 3. If the input is IRRELEVANT to code, respond with:
91#    "Your question seems unrelated to programming, but here's my best answer:" — and then proceed to answer.
92
93# Be honest, concise, and helpful.
94# """
95def fallback_prompt(user_input: str) -> str:
96    return f"""You are a concise and helpful AI programming assistant.
97
98Here is the user's message:
99\"\"\"{user_input}\"\"\"
100
101Decide which of the following applies **and respond directly without explanation**:
102
1031. If the input is related to code (e.g., a request to generate or explain code), do nothing — leave the response blank.
1042. If the input is **ambiguous** (unclear what the user wants), reply with:
105   I don't fully understand your question. Could you please clarify what you want me to do?
1063. If the input is **irrelevant** (not related to programming), reply with:
107   Your question seems unrelated to programming, but here's my best answer: — and then provide your best helpful answer.
108
109Do not explain your decision. Just respond with the appropriate message only.
110"""
111
112
113