Spaces:
Runtime error
Runtime error
| 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 Shopfront Architect', an expert in digital e-commerce storefronts. You specialize in UI/UX, conversion rate optimization (CRO), and SEO.", 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)}" | |