Upload examples/gpt52_example.py with huggingface_hub
Browse files- examples/gpt52_example.py +31 -0
examples/gpt52_example.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
GPT-5.2 API Example via NexaAPI
|
| 3 |
+
Get your free API key at: https://nexa-api.com
|
| 4 |
+
Install: pip install nexaapi
|
| 5 |
+
"""
|
| 6 |
+
from nexaapi import NexaAPI
|
| 7 |
+
|
| 8 |
+
# Initialize client - get your key at https://nexa-api.com
|
| 9 |
+
client = NexaAPI(api_key='YOUR_API_KEY')
|
| 10 |
+
|
| 11 |
+
# Basic text generation
|
| 12 |
+
response = client.chat.completions.create(
|
| 13 |
+
model='gpt-5.2',
|
| 14 |
+
messages=[
|
| 15 |
+
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
| 16 |
+
{'role': 'user', 'content': 'Explain quantum computing in simple terms'}
|
| 17 |
+
]
|
| 18 |
+
)
|
| 19 |
+
print("GPT-5.2 Response:")
|
| 20 |
+
print(response.choices[0].message.content)
|
| 21 |
+
|
| 22 |
+
# Coding example
|
| 23 |
+
code_response = client.chat.completions.create(
|
| 24 |
+
model='gpt-5.2',
|
| 25 |
+
messages=[{
|
| 26 |
+
'role': 'user',
|
| 27 |
+
'content': 'Write a Python function to sort a list of dictionaries by a key'
|
| 28 |
+
}]
|
| 29 |
+
)
|
| 30 |
+
print("\nCode Generation:")
|
| 31 |
+
print(code_response.choices[0].message.content)
|