Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tests/test_text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

TEST_NAME = "Pollinations Unity text response"
API_URL = "https://text.pollinations.ai/openai"
REQUEST_HEADERS = {
"Content-Type": "application/json",
# Pollinations expects requests to identify the Unity AI Lab origin when
# using the OpenAI-compatible endpoint. Without these headers the service
# replies with HTTP 402 (Payment Required) even though the public endpoint
# is free to use. Supplying Origin/Referer makes the intent explicit and
# avoids the erroneous billing prompt.
"Origin": "https://unityailab.com",
"Referer": "https://unityailab.com/",
"User-Agent": "ShittyVoiceTest/1.0",
}


def run() -> Dict[str, Any]:
Expand All @@ -24,7 +35,12 @@ def run() -> Dict[str, Any]:
}

try:
response = requests.post(API_URL, json=payload, timeout=20)
response = requests.post(
API_URL,
json=payload,
headers=REQUEST_HEADERS,
timeout=20,
)
duration = time.perf_counter() - start
response.raise_for_status()
data = response.json()
Expand Down