uncloseai.com/languages/python/requests/examples.py

100 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""
uncloseai.com API Examples in Python using requests library
Demonstrates direct HTTP calls to Hermes AI, Qwen Coder, and TTS endpoints
"""
import requests
import json
print("=== uncloseai.com Python (requests) Examples ===")
print()
# Example 1: Hermes AI Chat using requests
print("1. Hermes AI - General Purpose Chat (using requests)")
print(" Asking: 'Give a Python Fizzbuzz solution in one line of code?'")
print()
hermes_response = requests.post(
"https://hermes.ai.unturf.com/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer dummy-key"
},
json={
"model": "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic",
"messages": [{"role": "user", "content": "Give a Python Fizzbuzz solution in one line of code?"}],
"temperature": 0.5,
"max_tokens": 150
}
)
if hermes_response.status_code == 200:
print("Response:")
print(hermes_response.json()["choices"][0]["message"]["content"])
else:
print(f"Error: {hermes_response.status_code} - {hermes_response.text}")
print()
print("---")
print()
# Example 2: Qwen 3 Coder using requests
print("2. Qwen 3 Coder - Specialized for Code (using requests)")
print(" Asking: 'Write a Python function to validate an email address'")
print()
qwen_response = requests.post(
"https://qwen.ai.unturf.com/v1/chat/completions",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer dummy-key"
},
json={
"model": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M",
"messages": [{"role": "user", "content": "Write a Python function to validate an email address"}],
"temperature": 0.5,
"max_tokens": 200
}
)
if qwen_response.status_code == 200:
print("Response:")
print(qwen_response.json()["choices"][0]["message"]["content"])
else:
print(f"Error: {qwen_response.status_code} - {qwen_response.text}")
print()
print("---")
print()
# Example 3: Text-to-Speech using requests
print("3. Text-to-Speech Generation (using requests)")
print(" Converting text to speech and saving to speech.mp3")
print()
tts_response = requests.post(
"https://speech.ai.unturf.com/v1/audio/speech",
headers={
"Content-Type": "application/json",
"Authorization": "Bearer YOLO"
},
json={
"model": "tts-1",
"voice": "alloy",
"input": "Hello from Python using requests! Today is a wonderful day to build something people love!"
}
)
if tts_response.status_code == 200:
with open("speech.mp3", "wb") as f:
f.write(tts_response.content)
import os
file_size = os.path.getsize("speech.mp3")
print(f"✓ Speech file created: speech.mp3 ({file_size} bytes)")
else:
print(f"✗ Failed to create speech file: {tts_response.status_code}")
print()
print("=== Examples Complete ===")