Upload examples/gpt52_example.js with huggingface_hub
Browse files- examples/gpt52_example.js +33 -0
examples/gpt52_example.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// GPT-5.2 API Example via NexaAPI
|
| 2 |
+
// Get your free API key at: https://nexa-api.com
|
| 3 |
+
// Install: npm install nexaapi
|
| 4 |
+
|
| 5 |
+
import NexaAPI from 'nexaapi';
|
| 6 |
+
|
| 7 |
+
const client = new NexaAPI({ apiKey: 'YOUR_API_KEY' });
|
| 8 |
+
|
| 9 |
+
async function main() {
|
| 10 |
+
// Basic text generation
|
| 11 |
+
const response = await client.chat.completions.create({
|
| 12 |
+
model: 'gpt-5.2',
|
| 13 |
+
messages: [
|
| 14 |
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
| 15 |
+
{ role: 'user', content: 'Explain quantum computing in simple terms' }
|
| 16 |
+
]
|
| 17 |
+
});
|
| 18 |
+
console.log('GPT-5.2 Response:');
|
| 19 |
+
console.log(response.choices[0].message.content);
|
| 20 |
+
|
| 21 |
+
// Code generation
|
| 22 |
+
const codeResponse = await client.chat.completions.create({
|
| 23 |
+
model: 'gpt-5.2',
|
| 24 |
+
messages: [{
|
| 25 |
+
role: 'user',
|
| 26 |
+
content: 'Write a JavaScript function to sort an array of objects by a property'
|
| 27 |
+
}]
|
| 28 |
+
});
|
| 29 |
+
console.log('\nCode Generation:');
|
| 30 |
+
console.log(codeResponse.choices[0].message.content);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
main();
|