Spaces:
Runtime error
Runtime error
Create LLM/llm.py
Browse files- LLM/llm.py +24 -0
LLM/llm.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openai import OpenAI
|
2 |
+
import os
|
3 |
+
|
4 |
+
|
5 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
6 |
+
|
7 |
+
|
8 |
+
def generate_reply(prompt, model="gpt-3.5-turbo"):
|
9 |
+
try:
|
10 |
+
response = client.chat.completions.create(
|
11 |
+
model=model,
|
12 |
+
messages=[
|
13 |
+
{
|
14 |
+
"role": "system",
|
15 |
+
"content": "You are a smart assistant that understands and responds in the same language the user writes, whether Arabic or English."
|
16 |
+
},
|
17 |
+
{"role": "user", "content": prompt},
|
18 |
+
],
|
19 |
+
temperature=0.7,
|
20 |
+
max_tokens=500,
|
21 |
+
)
|
22 |
+
return response.choices[0].message.content
|
23 |
+
except Exception as e:
|
24 |
+
return f"An error occurred: {str(e)}"
|