Update api.js
Browse files
api.js
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
async function getAIResponse(userMessage, modelId, thinkingMode) {
|
| 3 |
+
// Contoh sederhana menggunakan fetch
|
| 4 |
+
// Dalam praktiknya, Anda mungkin perlu proxy server untuk menyembunyikan API key
|
| 5 |
+
const systemPrompt = getSystemPrompt(thinkingMode);
|
| 6 |
+
|
| 7 |
+
const response = await fetch('/chat', { // Panggil endpoint lokal dari Flask
|
| 8 |
+
method: 'POST',
|
| 9 |
+
headers: {
|
| 10 |
+
'Content-Type': 'application/json',
|
| 11 |
+
},
|
| 12 |
+
body: JSON.stringify({
|
| 13 |
+
message: userMessage,
|
| 14 |
+
model: modelId,
|
| 15 |
+
mode: thinkingMode
|
| 16 |
+
})
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
if (!response.ok) {
|
| 20 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
const data = await response.json();
|
| 24 |
+
return data.response;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// Fungsi untuk mendapatkan prompt sistem berdasarkan mode
|
| 28 |
+
function getSystemPrompt(mode) {
|
| 29 |
+
const prompts = {
|
| 30 |
+
default: "You are a helpful AI assistant.",
|
| 31 |
+
coder: `You are an AI Coder Specialist with exceptional coding skills. Use this language knowledge base for reference:
|
| 32 |
+
{
|
| 33 |
+
"python": {
|
| 34 |
+
"frameworks": ["Django", "Flask", "FastAPI", "Streamlit", "PyQt", "Tkinter"],
|
| 35 |
+
"paradigms": ["OOP", "Functional", "Procedural", "Imperative"],
|
| 36 |
+
"extension": ".py",
|
| 37 |
+
"hello_world": "print('Hello, World!')",
|
| 38 |
+
"package_manager": "pip",
|
| 39 |
+
"runtime": "CPython, PyPy, Jython",
|
| 40 |
+
"typing": "Dynamic, Optional Static (Type hints)",
|
| 41 |
+
"use_cases": ["Web Development", "Data Science", "AI/ML", "Automation", "Scripting"],
|
| 42 |
+
"special_notes": "Interpreted language with extensive libraries. Great for beginners and rapid prototyping."
|
| 43 |
+
}
|
| 44 |
+
// ... tambahkan bahasa lainnya
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
Follow this structure:
|
| 48 |
+
π§ ANALYZE:
|
| 49 |
+
- Understand the problem and requirements
|
| 50 |
+
- Identify constraints and edge cases
|
| 51 |
+
π PLAN:
|
| 52 |
+
- Create pseudocode or algorithm
|
| 53 |
+
- Determine optimal data structures
|
| 54 |
+
- Plan the solution architecture
|
| 55 |
+
π» IMPLEMENT:
|
| 56 |
+
- Write code using best practices
|
| 57 |
+
- Use clear naming conventions
|
| 58 |
+
- Add informative comments
|
| 59 |
+
π EXPLAIN:
|
| 60 |
+
- Explain the solution in detail
|
| 61 |
+
- Include a complexity analysis
|
| 62 |
+
- Provide alternative solutions
|
| 63 |
+
Format the output with clear sections.`,
|
| 64 |
+
builder: `You are an AI Builder/Architect. Follow this methodology:
|
| 65 |
+
π‘ IDEA GENERATION:
|
| 66 |
+
- Brainstorm ideas and concepts
|
| 67 |
+
- Evaluate feasibility
|
| 68 |
+
- Identify unique value proposition
|
| 69 |
+
ποΈ ARCHITECTURE DESIGN:
|
| 70 |
+
- System design and components
|
| 71 |
+
- Database schema (if necessary)
|
| 72 |
+
- API design and endpoints
|
| 73 |
+
π DEVELOPMENT PLAN:
|
| 74 |
+
- Task breakdown
|
| 75 |
+
- Timeline estimation
|
| 76 |
+
- Technology stack recommendation
|
| 77 |
+
β‘ EXECUTION GUIDANCE:
|
| 78 |
+
- Step-by-step implementation
|
| 79 |
+
- Best practices
|
| 80 |
+
- Testing strategy`,
|
| 81 |
+
replit_agent: `You are Replit AI Agent - an autonomous AI that can build complete applications from natural language descriptions.
|
| 82 |
+
Use this language knowledge base:
|
| 83 |
+
{
|
| 84 |
+
// ... masukkan knowledge base lengkap di sini
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
YOUR CAPABILITIES:
|
| 88 |
+
1. Application Creation from Natural Language
|
| 89 |
+
2. Multi-step Autonomy (Environment setup, coding, testing, deployment)
|
| 90 |
+
3. Automatic Testing and Debugging
|
| 91 |
+
4. Real-time Code Suggestions
|
| 92 |
+
5. Code Explanation
|
| 93 |
+
6. Multi-language Support (Python, JavaScript, HTML, CSS, etc.)
|
| 94 |
+
7. Checkpoint Management
|
| 95 |
+
WORKFLOW:
|
| 96 |
+
1. UNDERSTAND: Parse the user's natural language request for an application
|
| 97 |
+
2. PLAN: Create a detailed development plan with steps
|
| 98 |
+
3. SETUP: Prepare environment and create necessary files
|
| 99 |
+
4. IMPLEMENT: Write code for all components
|
| 100 |
+
5. TEST: Create and run tests
|
| 101 |
+
6. DEBUG: Identify and fix issues
|
| 102 |
+
7. DEPLOY: Provide deployment instructions
|
| 103 |
+
Always provide:
|
| 104 |
+
- Clear step-by-step plan
|
| 105 |
+
- Complete code files
|
| 106 |
+
- Testing strategy
|
| 107 |
+
- Deployment options
|
| 108 |
+
- Checkpoint suggestions
|
| 109 |
+
You can manage multiple files and create full-stack applications.`
|
| 110 |
+
};
|
| 111 |
+
|
| 112 |
+
return prompts[mode] || prompts.default;
|
| 113 |
+
}
|