Update models.js
Browse files
models.js
CHANGED
@@ -120,70 +120,32 @@ kamu adalah asisten yang mengerti perasaan manusia. buat quotes tentang kesediha
|
|
120 |
`;
|
121 |
|
122 |
export const PythonToJS = `
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
if params:
|
135 |
-
js_code += "const queryParams = " + str(params).replace("'", '"') + ";\n"
|
136 |
-
url += "?"+ "&".join([f"{k}={v}" for k, v in params.items()])
|
137 |
-
|
138 |
-
js_code += f"request({{'uri': url, method: method, json: jsonData}}, function (err, res, body) {{\n"
|
139 |
-
js_code += " if (err) return console.error(err);\n"
|
140 |
-
js_code += " console.log(body);\n"
|
141 |
-
js_code += "});"
|
142 |
-
|
143 |
-
return js_code
|
144 |
-
|
145 |
-
# Contoh pemakaian
|
146 |
-
method = "GET"
|
147 |
-
url = "https://example.com/api"
|
148 |
-
json_data = {"key": "value"}
|
149 |
-
params = {"param1": "value1"}
|
150 |
-
|
151 |
-
print(python_to_js(method, url, json_data, params))
|
152 |
-
\`\`\`
|
153 |
`;
|
154 |
|
155 |
export const JsToPython = `
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
if (queryParams) {
|
169 |
-
pythonCode += params = {JSON.stringify(queryParams)}\n; // $
|
170 |
-
pythonCode += "url += '?' + '&'.join([f'{k}={v}' for k, v in params.items()])\n";
|
171 |
-
}
|
172 |
-
|
173 |
-
pythonCode += response = requests.request(method, url, json=json_data)\n;
|
174 |
-
pythonCode += print(response.json())\n;
|
175 |
-
|
176 |
-
return pythonCode;
|
177 |
-
}
|
178 |
-
|
179 |
-
// Contoh pemakaian
|
180 |
-
const method = "GET";
|
181 |
-
const url = "https://example.com/api";
|
182 |
-
const jsonData = { key: "value" };
|
183 |
-
const queryParams = { param1: "value1" };
|
184 |
-
|
185 |
-
console.log(jsToPython(method, url, jsonData, queryParams));
|
186 |
-
\`\`\`
|
187 |
`;
|
188 |
|
189 |
const GptModelOld = (prompt) => ({
|
|
|
120 |
`;
|
121 |
|
122 |
export const PythonToJS = `
|
123 |
+
Kamu adalah asisten coding yang ahli dalam mengonversi kode Python ke JavaScript.
|
124 |
+
Fokus pada bagian requests API. Gunakan library 'axios' di JavaScript sebagai pengganti 'requests' di Python.
|
125 |
+
Jaga agar struktur dan fungsi tetap sama.
|
126 |
+
|
127 |
+
Contoh:
|
128 |
+
Python:
|
129 |
+
response = requests.get('https://api.example.com/data', headers={'Authorization': 'Bearer token'})
|
130 |
+
JS:
|
131 |
+
axios.get('https://api.example.com/data', { headers: {'Authorization': 'Bearer token'} })
|
132 |
+
.then(response => console.log(response.data))
|
133 |
+
.catch(error => console.error(error));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
`;
|
135 |
|
136 |
export const JsToPython = `
|
137 |
+
Kamu adalah asisten coding yang ahli dalam mengonversi kode JavaScript ke Python.
|
138 |
+
Fokus pada bagian requests API. Gunakan library 'requests' di Python sebagai pengganti 'axios' di JavaScript.
|
139 |
+
Jaga agar struktur dan fungsi tetap sama.
|
140 |
+
|
141 |
+
Contoh:
|
142 |
+
JS:
|
143 |
+
axios.get('https://api.example.com/data', { headers: {'Authorization': 'Bearer token'} })
|
144 |
+
.then(response => console.log(response.data))
|
145 |
+
.catch(error => console.error(error));
|
146 |
+
Python:
|
147 |
+
response = requests.get('https://api.example.com/data', headers={'Authorization': 'Bearer token'})
|
148 |
+
print(response.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
`;
|
150 |
|
151 |
const GptModelOld = (prompt) => ({
|