Spaces:
Runtime error
Runtime error
from openai import OpenAI | |
import os | |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) | |
def generate_reply(prompt, model="gpt-3.5-turbo"): | |
try: | |
response = client.chat.completions.create( | |
model=model, | |
messages=[ | |
{ | |
"role": "system", | |
"content": "You are a smart assistant that understands and responds in the same language the user writes, whether Arabic or English." | |
}, | |
{"role": "user", "content": prompt}, | |
], | |
temperature=0.7, | |
max_tokens=500, | |
) | |
return response.choices[0].message.content | |
except Exception as e: | |
return f"An error occurred: {str(e)}" | |