Spaces:
Running
Running
Refactor load_config to support multiple environment variable names for API key and update default model
Browse files
agents.py
CHANGED
@@ -7,10 +7,15 @@ from together import Together
|
|
7 |
|
8 |
# Load configuration from config.json or environment variables
|
9 |
def load_config():
|
10 |
-
#
|
|
|
11 |
together_api_key = os.environ.get("TOGETHER_API_KEY", "")
|
12 |
|
13 |
-
# If not found
|
|
|
|
|
|
|
|
|
14 |
if not together_api_key:
|
15 |
try:
|
16 |
config_path = os.path.join(os.path.dirname(__file__), "config.json")
|
@@ -23,10 +28,13 @@ def load_config():
|
|
23 |
except Exception as e:
|
24 |
print(f"Error loading config.json: {str(e)}")
|
25 |
|
|
|
|
|
|
|
26 |
# Return a config dictionary with the API key from environment variable
|
27 |
return {
|
28 |
"together_ai_token": together_api_key,
|
29 |
-
"model": "meta-llama/Llama-
|
30 |
}
|
31 |
|
32 |
# Get API key and model from config
|
|
|
7 |
|
8 |
# Load configuration from config.json or environment variables
|
9 |
def load_config():
|
10 |
+
# Try to get API key from environment variables (for Hugging Face deployment)
|
11 |
+
# Check both possible environment variable names
|
12 |
together_api_key = os.environ.get("TOGETHER_API_KEY", "")
|
13 |
|
14 |
+
# If not found with TOGETHER_API_KEY, try together_ai_token (the name used in your HF secret)
|
15 |
+
if not together_api_key:
|
16 |
+
together_api_key = os.environ.get("together_ai_token", "")
|
17 |
+
|
18 |
+
# If still not found in environment, try to load from config.json (for local development)
|
19 |
if not together_api_key:
|
20 |
try:
|
21 |
config_path = os.path.join(os.path.dirname(__file__), "config.json")
|
|
|
28 |
except Exception as e:
|
29 |
print(f"Error loading config.json: {str(e)}")
|
30 |
|
31 |
+
# Print debug information
|
32 |
+
print(f"API key found: {'Yes' if together_api_key else 'No'}")
|
33 |
+
|
34 |
# Return a config dictionary with the API key from environment variable
|
35 |
return {
|
36 |
"together_ai_token": together_api_key,
|
37 |
+
"model": "meta-llama/Llama-3.3-70B-Instruct-Turbo" # Using the model from your config.json
|
38 |
}
|
39 |
|
40 |
# Get API key and model from config
|