uncloseai.com/languages/python/examples.py

83 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
uncloseai.com API Examples in Python
Demonstrates Hermes AI, Qwen Coder, and TTS endpoints
"""
from openai import OpenAI
print("=== uncloseai.com Python Examples ===")
print()
# Example 1: Hermes AI Chat (Non-Streaming)
print("1. Hermes AI - General Purpose Chat")
print(" Asking: 'Give a Python Fizzbuzz solution in one line of code?'")
print()
hermes_client = OpenAI(
base_url="https://hermes.ai.unturf.com/v1",
api_key="dummy-key"
)
hermes_response = hermes_client.chat.completions.create(
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
)
print("Response:")
print(hermes_response.choices[0].message.content)
print()
print("---")
print()
# Example 2: Qwen 3 Coder - Specialized Coding Model
print("2. Qwen 3 Coder - Specialized for Code")
print(" Asking: 'Write a Python function to validate an email address'")
print()
qwen_client = OpenAI(
base_url="https://qwen.ai.unturf.com/v1",
api_key="dummy-key"
)
qwen_response = qwen_client.chat.completions.create(
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
)
print("Response:")
print(qwen_response.choices[0].message.content)
print()
print("---")
print()
# Example 3: Text-to-Speech
print("3. Text-to-Speech Generation")
print(" Converting text to speech and saving to speech.mp3")
print()
tts_client = OpenAI(
base_url="https://speech.ai.unturf.com/v1",
api_key="YOLO"
)
with tts_client.audio.speech.with_streaming_response.create(
model="tts-1",
voice="alloy",
input="Hello from Python! Today is a wonderful day to build something people love!"
) as response:
response.stream_to_file("speech.mp3")
import os
if os.path.exists("speech.mp3"):
file_size = os.path.getsize("speech.mp3")
print(f"✓ Speech file created: speech.mp3 ({file_size} bytes)")
else:
print("✗ Failed to create speech file")
print()
print("=== Examples Complete ===")