File size: 1,256 Bytes
2efe391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)}"