eroha-agentapi / engine /model.py
Yermek68's picture
Add EngineModel abstraction
2efe391 verified
import httpx
from engine.config import EngineConfig
class EngineModel:
@staticmethod
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)}"