-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_clients.py
More file actions
31 lines (24 loc) · 739 Bytes
/
api_clients.py
File metadata and controls
31 lines (24 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from newsapi import NewsApiClient
import cohere
from dotenv import load_dotenv
import os
load_dotenv()
class ConfigError(Exception):
pass
def get_required_env_var(var_name):
value = os.getenv(var_name)
if not value:
raise ConfigError(f"Missing required environment variable: {var_name}")
return value
def initialize_apis():
try:
news_api_key = get_required_env_var("NEWS_API_KEY")
cohere_api_key = get_required_env_var("COHERE_API_KEY")
return (
NewsApiClient(api_key=news_api_key),
cohere.Client(api_key=cohere_api_key)
)
except ConfigError as e:
print(f"Configuration error: {e}")
raise
newsapi, co = initialize_apis()