Spaces:
Paused
Paused
fix bugs
Browse files- app/golf_swing_rag.py +37 -2
- requirements.txt +1 -4
app/golf_swing_rag.py
CHANGED
|
@@ -245,6 +245,7 @@ class GolfSwingRAG:
|
|
| 245 |
# Initialize client if we found a key
|
| 246 |
if openai_key and openai_key.startswith("sk-"):
|
| 247 |
try:
|
|
|
|
| 248 |
self.openai_client = openai.OpenAI(api_key=openai_key)
|
| 249 |
print("✓ OpenAI client initialized successfully")
|
| 250 |
|
|
@@ -259,11 +260,45 @@ class GolfSwingRAG:
|
|
| 259 |
print("✓ OpenAI client test successful")
|
| 260 |
except Exception as test_e:
|
| 261 |
print(f"⚠️ OpenAI client test failed: {test_e}")
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
except Exception as e:
|
| 265 |
print(f"✗ Error initializing OpenAI client: {e}")
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
else:
|
| 268 |
print("✗ No valid OpenAI API key found (should start with 'sk-')")
|
| 269 |
if openai_key:
|
|
|
|
| 245 |
# Initialize client if we found a key
|
| 246 |
if openai_key and openai_key.startswith("sk-"):
|
| 247 |
try:
|
| 248 |
+
# Simple initialization without extra parameters that might cause conflicts
|
| 249 |
self.openai_client = openai.OpenAI(api_key=openai_key)
|
| 250 |
print("✓ OpenAI client initialized successfully")
|
| 251 |
|
|
|
|
| 260 |
print("✓ OpenAI client test successful")
|
| 261 |
except Exception as test_e:
|
| 262 |
print(f"⚠️ OpenAI client test failed: {test_e}")
|
| 263 |
+
# Try with a different model if gpt-4o-mini fails
|
| 264 |
+
try:
|
| 265 |
+
test_response = self.openai_client.chat.completions.create(
|
| 266 |
+
model="gpt-3.5-turbo",
|
| 267 |
+
messages=[{"role": "user", "content": "Hi"}],
|
| 268 |
+
max_tokens=5
|
| 269 |
+
)
|
| 270 |
+
print("✓ OpenAI client test successful with gpt-3.5-turbo")
|
| 271 |
+
except Exception as test_e2:
|
| 272 |
+
print(f"⚠️ OpenAI client test failed with both models: {test_e2}")
|
| 273 |
+
self.openai_client = None
|
| 274 |
|
| 275 |
except Exception as e:
|
| 276 |
print(f"✗ Error initializing OpenAI client: {e}")
|
| 277 |
+
print(f"Error type: {type(e).__name__}")
|
| 278 |
+
|
| 279 |
+
# Try alternative initialization approach
|
| 280 |
+
try:
|
| 281 |
+
print("Trying alternative OpenAI client initialization...")
|
| 282 |
+
# Import OpenAI directly to avoid potential conflicts
|
| 283 |
+
from openai import OpenAI
|
| 284 |
+
self.openai_client = OpenAI(api_key=openai_key)
|
| 285 |
+
print("✓ Alternative OpenAI client initialization successful")
|
| 286 |
+
|
| 287 |
+
# Test the alternative client
|
| 288 |
+
try:
|
| 289 |
+
test_response = self.openai_client.chat.completions.create(
|
| 290 |
+
model="gpt-3.5-turbo",
|
| 291 |
+
messages=[{"role": "user", "content": "Test"}],
|
| 292 |
+
max_tokens=5
|
| 293 |
+
)
|
| 294 |
+
print("✓ Alternative OpenAI client test successful")
|
| 295 |
+
except Exception as alt_test_e:
|
| 296 |
+
print(f"⚠️ Alternative OpenAI client test failed: {alt_test_e}")
|
| 297 |
+
self.openai_client = None
|
| 298 |
+
|
| 299 |
+
except Exception as alt_e:
|
| 300 |
+
print(f"✗ Alternative OpenAI client initialization also failed: {alt_e}")
|
| 301 |
+
self.openai_client = None
|
| 302 |
else:
|
| 303 |
print("✗ No valid OpenAI API key found (should start with 'sk-')")
|
| 304 |
if openai_key:
|
requirements.txt
CHANGED
|
@@ -6,7 +6,7 @@ numpy==1.24.3
|
|
| 6 |
matplotlib==3.8.2
|
| 7 |
torch==2.2.0
|
| 8 |
torchvision==0.17.0
|
| 9 |
-
openai
|
| 10 |
python-dotenv==1.0.0
|
| 11 |
tqdm==4.66.1
|
| 12 |
streamlit==1.29.0
|
|
@@ -15,8 +15,5 @@ sentence-transformers>=2.2.0
|
|
| 15 |
faiss-cpu>=1.7.0
|
| 16 |
scikit-learn==1.3.2
|
| 17 |
plotly==5.17.0
|
| 18 |
-
langchain==0.1.7
|
| 19 |
-
langchain-openai==0.0.6
|
| 20 |
-
langchain-community==0.0.20
|
| 21 |
tiktoken==0.5.2
|
| 22 |
transformers>=4.20.0
|
|
|
|
| 6 |
matplotlib==3.8.2
|
| 7 |
torch==2.2.0
|
| 8 |
torchvision==0.17.0
|
| 9 |
+
openai>=1.0.0
|
| 10 |
python-dotenv==1.0.0
|
| 11 |
tqdm==4.66.1
|
| 12 |
streamlit==1.29.0
|
|
|
|
| 15 |
faiss-cpu>=1.7.0
|
| 16 |
scikit-learn==1.3.2
|
| 17 |
plotly==5.17.0
|
|
|
|
|
|
|
|
|
|
| 18 |
tiktoken==0.5.2
|
| 19 |
transformers>=4.20.0
|