Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,5 +3,18 @@ import os
|
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 6 |
-
openai_client = OpenAI(api_key=
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 6 |
+
openai_client = OpenAI(api_key="OPENAI_API_KEY")
|
| 7 |
+
def generate_response(prompt, model_provider, temperature, top_p, max_tokens, repetition_penalty):
|
| 8 |
+
try:
|
| 9 |
+
response = openai_client.chat.completions.create(
|
| 10 |
+
model="gpt-3.5-turbo", # or another model of your choice
|
| 11 |
+
messages=[{"role": "user", "content": prompt}],
|
| 12 |
+
temperature=temperature,
|
| 13 |
+
top_p=top_p,
|
| 14 |
+
max_tokens=max_tokens,
|
| 15 |
+
presence_penalty=repetition_penalty,
|
| 16 |
+
stream=False
|
| 17 |
+
)
|
| 18 |
+
return response.choices[0].message.content.strip()
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"OpenAI API Error: {str(e)}"
|