۴) نمونه درخواستها (چند زبان)
const ENDPOINT = 'https://platonia.co/wp-json/platonia-dev/v1/proxy';
const USER_KEY = 'pltn_xxx...'; // کلید پلاتونیا
async function askGPT(message) {
const payload = {
openai_path: 'chat/completions',
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: 'You are a helpful assistant. پاسخها را فارسی بده.' },
{ role: 'user', content: message }
],
temperature: 0.5
};
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + USER_KEY
},
body: JSON.stringify(payload)
});
const data = await res.json();
if (!res.ok) throw new Error((data && (data.message || data.error)) || 'Request failed');
return data.choices?.[0]?.message?.content || data.choices?.[0]?.text || '';
}
askGPT('یک لطیفه کوتاه بگو').then(console.log).catch(console.error);
const ENDPOINT = 'https://platonia.co/wp-json/platonia-dev/v1/proxy';
const USER_KEY = 'pltn_xxx...';
async function askReasoning(message) {
const payload = {
openai_path: 'responses',
model: 'o1', // یا 'o3' یا 'gpt-5' (اگر در دسترس شماست)
instructions: 'You are a helpful assistant. پاسخها را فارسی بده.',
input: [
{
role: 'user',
content: [{ type: 'input_text', text: message }]
}
],
max_output_tokens: 800
// دقت کنید temperature ارسال نکنید
// برای o1/o3 میتوانید اضافه کنید: reasoning: { effort: 'medium' }
};
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + USER_KEY
},
body: JSON.stringify(payload)
});
const data = await res.json();
if (!res.ok) throw new Error((data && (data.message || (data.error && data.error.message))) || 'Request failed');
// استخراج متن از ساختار responses
if (typeof data.output_text === 'string' && data.output_text.trim() !== '') return data.output_text;
if (Array.isArray(data.output) && data.output.length) {
const parts = [];
data.output.forEach(out => {
(out.content || []).forEach(seg => {
if (seg.type === 'output_text' && typeof seg.text === 'string') parts.push(seg.text);
else if (typeof seg.text === 'string') parts.push(seg.text);
});
});
if (parts.length) return parts.join('\n');
}
return '';
}
askReasoning('در سه خط توضیح بده رگرسیون خطی چیست').then(console.log).catch(console.error);
const axios = require('axios');
const ENDPOINT = 'https://platonia.co/wp-json/platonia-dev/v1/proxy';
const USER_KEY = 'pltn_xxx...';
async function callChat() {
const payload = {
openai_path: 'chat/completions',
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: 'You are a helpful assistant. پاسخ فارسی بده.' },
{ role: 'user', content: 'چطور backoff نمایی را پیادهسازی کنم؟' }
],
temperature: 0.5
};
const { data } = await axios.post(ENDPOINT, payload, {
headers: { Authorization: `Bearer ${USER_KEY}` }
});
console.log(data.choices?.[0]?.message?.content || '');
}
callChat().catch(console.error);
import requests
ENDPOINT = 'https://platonia.co/wp-json/platonia-dev/v1/proxy'
USER_KEY = 'pltn_xxx...'
payload = {
'openai_path': 'chat/completions',
'model': 'gpt-4o-mini',
'messages': [
{'role': 'system', 'content': 'You are a helpful assistant. پاسخ فارسی بده.'},
{'role': 'user', 'content': 'سه مزیت استفاده از گیتوی پلاتونیا چیست؟'}
],
'temperature': 0.6
}
r = requests.post(ENDPOINT, json=payload, headers={'Authorization': f'Bearer {USER_KEY}'})
data = r.json()
if not r.ok:
raise SystemExit(data.get('message') or data.get('error') or 'Request failed')
print(data['choices'][0]['message']['content'])
'chat/completions',
'model' => 'gpt-4o-mini',
'messages' => [
['role'=>'system','content'=>'You are a helpful assistant. فارسی جواب بده.'],
['role'=>'user','content'=>'یک نکته درباره ریتلیمیتها بگو.']
],
'temperature' => 0.5
];
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . $userKey
],
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 90
]);
$resp = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($resp, true);
if ($http < 200 || $http >= 300) {
die(($data['message'] ?? $data['error'] ?? 'Request failed'));
}
echo $data['choices'][0]['message']['content'] ?? '';
curl -X POST https://platonia.co/wp-json/platonia-dev/v1/proxy \
-H "Authorization: Bearer pltn_xxx..." \
-H "Content-Type: application/json" \
-d '{
"openai_path":"responses",
"model":"o1",
"instructions":"You are a helpful assistant. پاسخ فارسی بده.",
"input":[{"role":"user","content":[{"type":"input_text","text":"دو کاربرد مدلهای reasoning را نام ببر"}]}],
"max_output_tokens":600
}'
– Backoff نمایی (نمونه ساده JS):
async function withBackoff(fn, max=5) {
let delay = 800;
for (let i=0;isetTimeout(r, delay * (1 + Math.random())));
delay *= 2;
}
}
}
'https://platonia.co/wp-json/platonia-dev/v1/proxy',
'model' => 'gpt-4o-mini',
'system_prompt' => 'You are a helpful assistant. پاسخها را تا حد امکان به زبان فارسی ارائه بده.',
'temperature' => '0.5',
], $atts, 'platonia_dev_chatbot');
$container_id = 'pdc_' . wp_generate_uuid4();
$endpoint = esc_url_raw($atts['endpoint']);
ob_start();
?>
Platonia Dev - Chatbot Tester
آماده
کلید باید همان کلید اختصاصی Platonia Dev باشد. در LocalStorage مرورگر ذخیره میشود.