Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -809,17 +809,17 @@ app.add_middleware(
|
|
| 809 |
# Initialize OpenAI client with HF secret
|
| 810 |
try:
|
| 811 |
# Get API key from HF secrets
|
| 812 |
-
hf_token = os.environ.get("HF_TOKEN")
|
| 813 |
if hf_token:
|
| 814 |
api = HfApi(token=hf_token)
|
| 815 |
try:
|
| 816 |
-
openai_api_key = os.environ.get("OPENAI_API_KEY")
|
| 817 |
if not openai_api_key:
|
| 818 |
logger.error("OPENAI_API_KEY not found in environment variables")
|
| 819 |
raise ValueError("OPENAI_API_KEY not found")
|
| 820 |
|
| 821 |
-
# Configure OpenAI
|
| 822 |
-
client = OpenAI(api_key=openai_api_key)
|
| 823 |
|
| 824 |
# Test the API key
|
| 825 |
test_response = client.chat.completions.create(
|
|
@@ -856,8 +856,8 @@ try:
|
|
| 856 |
if not api_key:
|
| 857 |
raise ValueError("OPENAI_API_KEY not found in environment variables")
|
| 858 |
|
| 859 |
-
# Configure OpenAI
|
| 860 |
-
client = OpenAI(api_key=api_key)
|
| 861 |
|
| 862 |
# Test the API key
|
| 863 |
test_response = client.chat.completions.create(
|
|
|
|
| 809 |
# Initialize OpenAI client with HF secret
|
| 810 |
try:
|
| 811 |
# Get API key from HF secrets
|
| 812 |
+
hf_token = os.environ.get("HF_TOKEN", "").strip()
|
| 813 |
if hf_token:
|
| 814 |
api = HfApi(token=hf_token)
|
| 815 |
try:
|
| 816 |
+
openai_api_key = os.environ.get("OPENAI_API_KEY", "").strip()
|
| 817 |
if not openai_api_key:
|
| 818 |
logger.error("OPENAI_API_KEY not found in environment variables")
|
| 819 |
raise ValueError("OPENAI_API_KEY not found")
|
| 820 |
|
| 821 |
+
# Configure OpenAI with cleaned API key
|
| 822 |
+
client = OpenAI(api_key=openai_api_key.strip())
|
| 823 |
|
| 824 |
# Test the API key
|
| 825 |
test_response = client.chat.completions.create(
|
|
|
|
| 856 |
if not api_key:
|
| 857 |
raise ValueError("OPENAI_API_KEY not found in environment variables")
|
| 858 |
|
| 859 |
+
# Configure OpenAI with cleaned API key
|
| 860 |
+
client = OpenAI(api_key=api_key.strip())
|
| 861 |
|
| 862 |
# Test the API key
|
| 863 |
test_response = client.chat.completions.create(
|