yugapurush commited on
Commit
2bffb3f
·
1 Parent(s): 09eaf22

try try try

Browse files
Files changed (2) hide show
  1. doli4.py +17 -0
  2. requirements.txt +1 -1
doli4.py CHANGED
@@ -23,6 +23,12 @@ def get_api_keys():
23
  openai_key = os.getenv("OPENAI_API_KEY")
24
  dolibarr_key = os.getenv("DOLIBARR_API_KEY")
25
 
 
 
 
 
 
 
26
  return openai_key, dolibarr_key
27
 
28
 
@@ -530,6 +536,12 @@ Current date: """ + datetime.now().strftime("%Y-%m-%d")
530
  content = content.split('</think>')[-1].strip() if '</think>' in content else content
531
  return content if content else "I couldn't process that request."
532
 
 
 
 
 
 
 
533
  except Exception as e:
534
  logger.error(f"Error in chat: {e}")
535
  return f"Sorry, I encountered an error: {str(e)}"
@@ -543,6 +555,11 @@ def create_openai_agent_interface():
543
 
544
  OPENAI_API_KEY, DOLIBARR_API_KEY = get_api_keys()
545
 
 
 
 
 
 
546
  if not OPENAI_API_KEY or not DOLIBARR_API_KEY:
547
  raise ValueError("API keys not found. Please set them in Hugging Face Secrets or .env file")
548
 
 
23
  openai_key = os.getenv("OPENAI_API_KEY")
24
  dolibarr_key = os.getenv("DOLIBARR_API_KEY")
25
 
26
+ # Add more specific error messages
27
+ if not openai_key:
28
+ raise ValueError("OPENAI_API_KEY not found in environment variables or .env file")
29
+ if not dolibarr_key:
30
+ raise ValueError("DOLIBARR_API_KEY not found in environment variables or .env file")
31
+
32
  return openai_key, dolibarr_key
33
 
34
 
 
536
  content = content.split('</think>')[-1].strip() if '</think>' in content else content
537
  return content if content else "I couldn't process that request."
538
 
539
+ except openai.APIConnectionError as e:
540
+ logger.error(f"OpenAI API Connection Error: {e}")
541
+ return "Sorry, I'm having trouble connecting to OpenAI. Please check if the API key is valid and the service is available."
542
+ except openai.AuthenticationError as e:
543
+ logger.error(f"OpenAI API Authentication Error: {e}")
544
+ return "Sorry, there's an authentication error with the OpenAI API. Please check if the API key is correct."
545
  except Exception as e:
546
  logger.error(f"Error in chat: {e}")
547
  return f"Sorry, I encountered an error: {str(e)}"
 
555
 
556
  OPENAI_API_KEY, DOLIBARR_API_KEY = get_api_keys()
557
 
558
+ # Add logging to verify keys (but don't log the actual keys)
559
+ logger.info("API Keys loaded successfully")
560
+ logger.info(f"OpenAI API Key length: {len(OPENAI_API_KEY) if OPENAI_API_KEY else 0}")
561
+ logger.info(f"Dolibarr API Key length: {len(DOLIBARR_API_KEY) if DOLIBARR_API_KEY else 0}")
562
+
563
  if not OPENAI_API_KEY or not DOLIBARR_API_KEY:
564
  raise ValueError("API keys not found. Please set them in Hugging Face Secrets or .env file")
565
 
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  gradio
2
- openai
3
  python-dotenv
4
  requests
5
  anthropic
 
1
  gradio
2
+ openai>=1.0.0
3
  python-dotenv
4
  requests
5
  anthropic