Spaces:
Sleeping
Sleeping
| import httpx | |
| from engine.config import EngineConfig | |
| class EngineModel: | |
| async def generate(prompt: str) -> str: | |
| if not EngineConfig.OPENAI_API_KEY: | |
| return "β OPENAI_API_KEY not found" | |
| headers = { | |
| "Authorization": f"Bearer {EngineConfig.OPENAI_API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "model": EngineConfig.MODEL_NAME, | |
| "messages": [ | |
| {"role": "system", "content": "You are Eroha, a strategic AI operating core."}, | |
| {"role": "user", "content": prompt} | |
| ], | |
| "temperature": EngineConfig.TEMPERATURE | |
| } | |
| try: | |
| async with httpx.AsyncClient(timeout=30) as client: | |
| response = await client.post( | |
| "https://api.openai.com/v1/chat/completions", | |
| headers=headers, | |
| json=payload | |
| ) | |
| if response.status_code != 200: | |
| return f"β API Error: {response.text}" | |
| data = response.json() | |
| return data["choices"][0]["message"]["content"] | |
| except Exception as e: | |
| return f"β Internal error: {str(e)}" | |