Spaces:
Configuration error
Configuration error
Download app.py from ZentryxOS/roblox-ai-server: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/ZentryxOS/roblox-ai-server/resolve/main/app.py
- Command line
-
hf download hf://spaces/ZentryxOS/roblox-ai-server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ZentryxOS/roblox-ai-server/resolve/main/app.py
1.01 kB
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| import requests | |
| import os | |
| app = FastAPI() | |
| OPENROUTER_API_KEY = os.environ["OPENROUTER_API_KEY"] | |
| API_URL = "https://openrouter.ai/api/v1/chat/completions" | |
| class Prompt(BaseModel): | |
| prompt: str | |
| def ai_endpoint(data: Prompt): | |
| headers = { | |
| "Authorization": f"Bearer {OPENROUTER_API_KEY}", | |
| "HTTP-Referer": "https://huggingface.co", | |
| "X-Title": "Roblox AI Server", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "model": "google/gemini-3-flash-preview", | |
| "messages": [ | |
| {"role": "user", "content": data.prompt} | |
| ], | |
| "max_tokens": 200 | |
| } | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| result = response.json() | |
| if "response" in result: | |
| return {"reply": result["response"]} | |
| if "choices" in result: | |
| return {"reply": result["choices"][0]["message"]["content"]} | |
| return {"reply": str(result)} | |