| 1 |
import { __ } from '@wordpress/i18n' |
| 2 |
|
| 3 |
const DRAFT_URL = 'https://ai.extendify.com/api/draft' |
| 4 |
// const DRAFT_URL = 'http://localhost:3000/api/draft' |
| 5 |
|
| 6 |
export const completion = async (prompt, promptType, systemMessageKey) => { |
| 7 |
const response = await fetch(`${DRAFT_URL}/completion`, { |
| 8 |
method: 'POST', |
| 9 |
headers: { 'Content-Type': 'application/json' }, |
| 10 |
body: JSON.stringify({ prompt, promptType, systemMessageKey }), |
| 11 |
}) |
| 12 |
|
| 13 |
if (!response.ok) { |
| 14 |
if (response.status === 429) { |
| 15 |
throw new Error(__('Service temporarily unavailable', 'extendify')) |
| 16 |
} |
| 17 |
throw new Error(`Server error: ${response.status}`) |
| 18 |
} |
| 19 |
|
| 20 |
return response |
| 21 |
} |
| 22 |
|