const apiKey = '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'; const apiUrl = 'https://api.openai.com/v1/engines/gpt-3.5-turbo/completions'; // Hàm để gửi truy vấn đến GPT-3 function sendQueryToGPT3(query) { fetch(apiUrl, { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ prompt: query, max_tokens: 50, // Số lượng từ tối đa trong kết quả }), }) .then(response => response.json()) .then(data => { // Xử lý dữ liệu trả về từ GPT-3 ở đây console.log(data.choices[0].text); }) .catch(error => { console.error('Lỗi khi gửi truy vấn đến GPT-3:', error); }); }
sendQueryToGPT3('Xin chào, GPT-3!');