import os from openai import OpenAI from typing import Optional class OpenAIClient: def __init__(self, api_key: Optional[str] = None): self.client = OpenAI(api_key=api_key or os.getenv("OPENAI_API_KEY")) self.default_model = "gpt-4o" def chat(self, prompt: str, system_instruction: str = "You are the 'Grand Tech Wizard'. You are a master Software Architect, Senior Engineer, API/Webhooks Specialist, and App Builder. You design scalable, secure, and idiomatic technical systems.", model: Optional[str] = None) -> str: try: response = self.client.chat.completions.create( model=model or self.default_model, messages=[ {"role": "system", "content": system_instruction}, {"role": "user", "content": prompt} ] ) return response.choices[0].message.content except Exception as e: return f"Error calling OpenAI API: {str(e)}"