💻 Examples
Chat Completion Example
from openai import AsyncOpenAI
client = AsyncOpenAI(
api_key='fresed-...',
base_url='https://fresedgpt.space/v1'
)
async def test_create_chat_completion():
stream = await client.chat.completions.create(
messages=[{'role': 'user', 'content': 'hi'}],
model='gpt-4',
stream=True
)
async for chunk in stream:
print(chunk.choices[0].delta.content or '', end='')
if __name__ == '__main__':
import asyncio
asyncio.run(test_create_chat_completion())
Image Generation Example
from openai import OpenAI
client = OpenAI(base_url='https://fresedgpt.space/v1', api_key='fresed-...')
response = client.images.generate(
model="midjourney",
prompt="a white siamese cat",
size="1024x1024"
)
print(response)
Speech Generation Example
from openai import OpenAI
client = OpenAI(
api_key='fresed-...',
base_url='https://fresedgpt.space/v1'
)
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="hi"
)
print(response)
response.stream_to_file("output.mp3")
Temporary Email Example
import httpx
import asyncio
BASE_URL = "https://fresedgpt.space/v1"
API_KEY = "fresed-..."
async def generate_temp_mail():
async with httpx.AsyncClient() as client:
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = await client.post(f"{BASE_URL}/temp_mail/generate", headers=headers)
if response.status_code == 200:
data = response.json()
print("Generated Email:", data["email"])
print("Identifier:", data["identifier"])
return data["identifier"]
else:
print("Failed to generate email:", response.text)
return None
async def get_temp_mail_messages(identifier):
async with httpx.AsyncClient() as client:
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
response = await client.get(f"{BASE_URL}/temp_mail/messages/{identifier}", headers=headers)
if response.status_code == 200:
messages = response.json()["messages"]
print("Messages:", messages)
else:
print("Failed to get messages:", response.text)
async def main():
identifier = await generate_temp_mail()
if identifier:
input("Press Enter to check for messages...")
await get_temp_mail_messages(identifier)
if __name__ == "__main__":
asyncio.run(main())
Suno
import requests
import json
import time
# URL for creating a request to the API
create_url = "https://fresedgpt.space/v1/music/generation"
# URL for checking the status of the request to the API
status_url = "https://fresedgpt.space/v1/music/status/"
# Headers for authorization
headers = {
'Authorization': 'Bearer fresed-...',
'Content-Type': 'application/json'
}
# Request body with parameters
payload = {
"prompt": "Create a beautiful song",
"make_instrumental": False # or False if instrumental is not required
}
# Convert the request body to a JSON string
data = json.dumps(payload)
# Send a POST request to the API to create a task
response = requests.post(create_url, headers=headers, data=data)
if response.status_code == 200:
request_id = response.json().get("request_id")
print(f"Task created successfully. Task ID: {request_id}")
# Check the status of the task every 10 seconds
while True:
status_response = requests.get(f"{status_url}{request_id}", headers=headers)
if status_response.status_code == 200:
status_data = status_response.json()
if status_data.get("status") == "complete":
print("Music generated successfully:", status_data.get("result"))
break
else:
print("Task is in progress...")
else:
print("Error getting task status:", status_response.status_code, status_response.text)
time.sleep(10)
else:
print("Error:", response.status_code, response.text)
Last updated