Ragai1 commited on
Commit
42e5a5f
·
verified ·
1 Parent(s): a4aad4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -10,9 +10,6 @@ from tools.final_answer import FinalAnswerTool
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
-
14
- api_key = os.getenv("NEWSAPI_API_KEY")
15
-
16
  @tool
17
  def get_ai_news(keyword: str, language: str = "en", page_size: int=5) -> str:
18
  """Fetches the latest news articles related to Artificial Intelligence or a specified keyword.
@@ -22,8 +19,10 @@ def get_ai_news(keyword: str, language: str = "en", page_size: int=5) -> str:
22
  language: The language of the articles (e.g., "en" for English, "es" for Spanish).
23
  page_size: The number of top articles to retrieve (max 10 for free tier effective use).
24
  """
25
- if not api_key:
26
- return "Error: NewsAPI.org API key not configured. Please add it as NEWSAPI_API_KEY secret."
 
 
27
 
28
  url = "https://newsapi.org/v2/everything"
29
  params = {
 
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
 
13
  @tool
14
  def get_ai_news(keyword: str, language: str = "en", page_size: int=5) -> str:
15
  """Fetches the latest news articles related to Artificial Intelligence or a specified keyword.
 
19
  language: The language of the articles (e.g., "en" for English, "es" for Spanish).
20
  page_size: The number of top articles to retrieve (max 10 for free tier effective use).
21
  """
22
+ try:
23
+ api_key = os.getenv("NEWSAPI_API_KEY")
24
+ if not api_key:
25
+ return "Error: NewsAPI.org API key not configured. Please add it as NEWSAPI_API_KEY secret."
26
 
27
  url = "https://newsapi.org/v2/everything"
28
  params = {