Spaces:
No application file
No application file
| import os | |
| import openai | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| def load_llm(): | |
| async def llm(prompt: str) -> str: | |
| try: | |
| response = await openai.ChatCompletion.acreate( | |
| model="gpt-4", # or gpt-3.5-turbo | |
| messages=[{"role": "user", "content": prompt}], | |
| temperature=0.2 | |
| ) | |
| return response.choices[0].message["content"].strip() | |
| except Exception as e: | |
| return f"LLM error: {str(e)}" | |
| return llm | |