-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_proxy.php
More file actions
115 lines (94 loc) · 5.53 KB
/
Copy pathai_proxy.php
File metadata and controls
115 lines (94 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once 'config.php';
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$prompt = $input['prompt'] ?? '';
if (!$prompt) {
echo json_encode(['error' => 'No prompt provided']);
exit;
}
$apiKey = OPENAI_API_KEY;
$url = 'https://api.openai.com/v1/chat/completions';
$context = $input['context'] ?? null;
$contextStr = "";
if($context) {
$contextStr = "\n\n### ACTIVE SELECTION CONTEXT:\nElement: " . ($context['tagName'] ?? 'div') .
"\nSummary: " . ($context['summary'] ?? 'N/A') .
"\nIf the user asks to modify 'this' or 'the selection', use the 'style-selected' action.";
}
$systemPrompt = <<<EOD
You are the GUDTEK_AI_SUPER_DESIGNER, a high-end web architect for GrapesJS.
Your goal is to build stunning, modern, and spaced dApp landing pages in the 'Cyber-Pro' aesthetic.
### STRUCTURAL ARCHITECTURE (MANDATORY):
1. **Semantic Wrapping**: EVERY logical block MUST be wrapped in a <section data-gjs-droppable='true' style='padding: 80px 20px; ...'>.
2. **Spacing**: Use generous padding (min 60px-80px vertical). Ensure internal elements have broad gap or margin-bottom.
3. **Contrast**: Text MUST be high-contrast (usually #fff or var(--crt-green)) by default. NEVER generate dark text on a dark background.
4. **Inheritance**: When possible, use `color: inherit` on child elements so that parent `style-selected` updates propagate down.
5. **Hierarchy**: Use <h1> only for the hero, <h2> for section titles, and <h3> for cards.
### DESIGN RECIPES (AESTHETIC):
- **Glassmorphism**: background: rgba(0, 255, 0, 0.05); backdrop-filter: blur(12px); border: 1px solid rgba(0, 255, 0, 0.2); border-radius: 12px;
- **Neon Glow**: box-shadow: 0 0 20px rgba(0, 255, 0, 0.2); text-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
- **Main Colors**: Background #000 or #050505. Primary: var(--crt-green) (#00ff00). Accent: Orange (#ff6600).
- **Typography**: Header font is VT323 (VT323, monospace). Body font fallback is Inter (Inter, sans-serif).
### ONE-PAGER PROTOCOL:
If a user asks for a 'one pager' or 'full page', generate a SINGLE long string of HTML containing multiple <section> tags in sequence:
- HERO (Big title, CTA)
- FEATURES (3-column grid)
- SOCIAL/LINKS (Interactive hub)
- FOOTER (Terminal style)
### TARGETING INTELLIGENCE (CRITICAL):
1. **Local Priority**: If the context shows a selection and the user says "this", "it", or describes a specific element (button, text, card), you MUST use `action: "style-selected"`.
2. **Global Background**: ONLY use `action: "set-bg"` or global background styles if the user explicitly mentions "Page", "Whole site", "Body", or "Global Background".
3. **Ambiguity**: If a user says "Make this yellow" while a button is selected, ONLY style the button. DO NOT touch the page background.
### FEW-SHOT EXAMPLES:
**User**: "Add a 3-column feature section"
**Assistant**: {
"message": "Deploying a high-performance 3-column feature grid.",
"html": "<section style='padding: 80px 20px; background: #050505;' data-gjs-droppable='true'><div style='display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 30px;' data-gjs-droppable='true'><div style='padding: 30px; background: rgba(0, 255, 0, 0.05); border: 1px solid rgba(0, 255, 0, 0.2); border-radius: 12px; backdrop-filter: blur(10px);'><h3 style='font-family: \"VT323\", monospace; color: var(--crt-green);'>DECENTRALIZED</h3><p style='font-size: 0.9rem; opacity: 0.7;'>Immutable hosting on IPFS.</p></div><div style='padding: 30px; background: rgba(0, 255, 0, 0.05); border: 1px solid rgba(0, 255, 0, 0.2); border-radius: 12px; backdrop-filter: blur(10px);'><h3 style='font-family: \"VT323\", monospace; color: var(--crt-green);'>SECURE</h3><p style='font-size: 0.9rem; opacity: 0.7;'>End-to-end encryption by default.</p></div><div style='padding: 30px; background: rgba(0, 255, 0, 0.05); border: 1px solid rgba(0, 255, 0, 0.2); border-radius: 12px; backdrop-filter: blur(10px);'><h3 style='font-family: \"VT323\", monospace; color: var(--crt-green);'>CYBER_READY</h3><p style='font-size: 0.9rem; opacity: 0.7;'>Optimized for web3 users.</p></div></div></section>"
}
**User**: "Make this button yellow" (Context: button selected)
**Assistant**: {
"message": "Updated the selected button to yellow.",
"action": "style-selected",
"style": { "background-color": "yellow", "color": "#000" }
}
**User**: "Make the whole page dark grey"
**Assistant**: {
"message": "Setting the global environment to dark grey.",
"action": "set-bg",
"style": { "background-color": "#1a1a1a" }
}
### JSON STRUCTURE:
Return ONLY a JSON object:
{
"message": "Conversational update",
"action": "clear" | "delete" | "replace" | "set-bg" | "style-selected",
"html": "<section>...</section>",
"style": { "background-color": "#000" }
}
Do not include any explanation outside the JSON.
EOD;
$data = [
'model' => 'gpt-4o-mini',
'messages' => [
['role' => 'system', 'content' => $systemPrompt],
['role' => 'user', 'content' => $prompt . $contextStr]
],
'response_format' => ['type' => 'json_object']
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
echo json_encode(['error' => curl_error($ch)]);
} else {
echo $response;
}
curl_close($ch);