Chris Ellerson
commited on
Commit
·
3f90b63
1
Parent(s):
68ed57f
initial commit of agent with score of 60
Browse files
README.md
CHANGED
|
@@ -102,6 +102,27 @@ AGENT_TIMEOUT=120 # Timeout in seconds for API calls
|
|
| 102 |
AGENT_API_BASE=https://api.groq.com/openai/v1 # For X.AI when using OpenAIServerModel
|
| 103 |
```
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
## Usage
|
| 106 |
|
| 107 |
### Running the Agent
|
|
|
|
| 102 |
AGENT_API_BASE=https://api.groq.com/openai/v1 # For X.AI when using OpenAIServerModel
|
| 103 |
```
|
| 104 |
|
| 105 |
+
### Hugging Face Spaces Setup
|
| 106 |
+
|
| 107 |
+
When deploying to Hugging Face Spaces, you need to add your API keys as secrets:
|
| 108 |
+
|
| 109 |
+
1. Go to your Space's Settings → Repository Secrets
|
| 110 |
+
2. Add the following secrets (add at least one of these API keys):
|
| 111 |
+
- `HUGGINGFACEHUB_API_TOKEN` - Your Hugging Face API token
|
| 112 |
+
- `OPENAI_API_KEY` - Your OpenAI API key
|
| 113 |
+
- `XAI_API_KEY` - Your X.AI/Grok API key
|
| 114 |
+
|
| 115 |
+
3. Add additional configuration secrets as needed:
|
| 116 |
+
- `AGENT_MODEL_TYPE` - Model type (e.g., "OpenAIServerModel")
|
| 117 |
+
- `AGENT_MODEL_ID` - Model ID to use (e.g., "gpt-4o")
|
| 118 |
+
- `AGENT_TEMPERATURE` - Temperature setting (e.g., "0.2")
|
| 119 |
+
- `AGENT_VERBOSE` - Set to "true" for detailed logging
|
| 120 |
+
|
| 121 |
+
4. For X.AI's API, also set:
|
| 122 |
+
- `XAI_API_BASE` - The API base URL
|
| 123 |
+
|
| 124 |
+

|
| 125 |
+
|
| 126 |
## Usage
|
| 127 |
|
| 128 |
### Running the Agent
|
app.py
CHANGED
|
@@ -5,6 +5,25 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
from core_agent import GAIAAgent
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
| 10 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -15,6 +34,9 @@ class BasicAgent:
|
|
| 15 |
def __init__(self):
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
# Initialize the GAIAAgent with local execution
|
| 19 |
try:
|
| 20 |
# Load environment variables if dotenv is available
|
|
@@ -26,58 +48,101 @@ class BasicAgent:
|
|
| 26 |
print("python-dotenv not installed, continuing with environment as is")
|
| 27 |
|
| 28 |
# Try to load API keys from environment
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# If we have at least one API key, use a model-based approach
|
| 32 |
-
if
|
| 33 |
-
# Default model parameters
|
| 34 |
-
model_type = os.
|
| 35 |
-
model_id = os.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
if
|
| 38 |
# Use X.AI API with OpenAIServerModel
|
|
|
|
| 39 |
self.gaia_agent = GAIAAgent(
|
| 40 |
model_type="OpenAIServerModel",
|
| 41 |
model_id="grok-3-latest", # X.AI's model
|
| 42 |
-
api_key=
|
| 43 |
-
api_base=
|
| 44 |
-
temperature=
|
| 45 |
executor_type="local",
|
| 46 |
-
verbose=
|
| 47 |
)
|
| 48 |
-
print("Using OpenAIServerModel with X.AI API")
|
| 49 |
-
elif model_type == "HfApiModel" and
|
| 50 |
# Use Hugging Face API
|
| 51 |
self.gaia_agent = GAIAAgent(
|
| 52 |
model_type="HfApiModel",
|
| 53 |
model_id=model_id,
|
| 54 |
-
api_key=
|
| 55 |
-
temperature=
|
| 56 |
executor_type="local",
|
| 57 |
-
verbose=
|
| 58 |
)
|
| 59 |
print(f"Using HfApiModel with model_id: {model_id}")
|
| 60 |
-
|
| 61 |
# Default to OpenAI API
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
print(f"Using OpenAIServerModel with model_id: {model_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
else:
|
| 72 |
-
# No API keys available,
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
)
|
| 80 |
-
print("Warning: No API keys found. Using a basic local execution setup.")
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
print(f"Error initializing GAIAAgent: {e}")
|
|
@@ -124,6 +189,12 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 124 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 125 |
try:
|
| 126 |
agent = BasicAgent()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
except Exception as e:
|
| 128 |
print(f"Error instantiating agent: {e}")
|
| 129 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from core_agent import GAIAAgent
|
| 7 |
|
| 8 |
+
# Debug function to show available environment variables
|
| 9 |
+
def debug_environment():
|
| 10 |
+
"""Print available environment variables related to API keys (with values hidden)"""
|
| 11 |
+
debug_vars = [
|
| 12 |
+
"HF_API_TOKEN", "HUGGINGFACEHUB_API_TOKEN",
|
| 13 |
+
"OPENAI_API_KEY", "XAI_API_KEY",
|
| 14 |
+
"AGENT_MODEL_TYPE", "AGENT_MODEL_ID",
|
| 15 |
+
"AGENT_TEMPERATURE", "AGENT_VERBOSE"
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
print("=== DEBUG: Environment Variables ===")
|
| 19 |
+
for var in debug_vars:
|
| 20 |
+
if os.environ.get(var):
|
| 21 |
+
# Hide actual values for security
|
| 22 |
+
print(f"{var}: [SET]")
|
| 23 |
+
else:
|
| 24 |
+
print(f"{var}: [NOT SET]")
|
| 25 |
+
print("===================================")
|
| 26 |
+
|
| 27 |
# (Keep Constants as is)
|
| 28 |
# --- Constants ---
|
| 29 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 34 |
def __init__(self):
|
| 35 |
print("BasicAgent initialized.")
|
| 36 |
|
| 37 |
+
# Call debug function to show available environment variables
|
| 38 |
+
debug_environment()
|
| 39 |
+
|
| 40 |
# Initialize the GAIAAgent with local execution
|
| 41 |
try:
|
| 42 |
# Load environment variables if dotenv is available
|
|
|
|
| 48 |
print("python-dotenv not installed, continuing with environment as is")
|
| 49 |
|
| 50 |
# Try to load API keys from environment
|
| 51 |
+
# Check both HF_API_TOKEN and HUGGINGFACEHUB_API_TOKEN (HF Spaces uses HF_API_TOKEN)
|
| 52 |
+
hf_token = os.environ.get("HF_API_TOKEN") or os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
| 53 |
+
openai_key = os.environ.get("OPENAI_API_KEY")
|
| 54 |
+
xai_key = os.environ.get("XAI_API_KEY")
|
| 55 |
|
| 56 |
# If we have at least one API key, use a model-based approach
|
| 57 |
+
if hf_token or openai_key or xai_key:
|
| 58 |
+
# Default model parameters - read directly from environment
|
| 59 |
+
model_type = os.environ.get("AGENT_MODEL_TYPE", "OpenAIServerModel")
|
| 60 |
+
model_id = os.environ.get("AGENT_MODEL_ID", "gpt-4o")
|
| 61 |
+
temperature = float(os.environ.get("AGENT_TEMPERATURE", "0.2"))
|
| 62 |
+
verbose = os.environ.get("AGENT_VERBOSE", "false").lower() == "true"
|
| 63 |
+
|
| 64 |
+
print(f"Agent config - Model Type: {model_type}, Model ID: {model_id}")
|
| 65 |
|
| 66 |
+
if xai_key:
|
| 67 |
# Use X.AI API with OpenAIServerModel
|
| 68 |
+
api_base = os.environ.get("XAI_API_BASE", "https://api.x.ai/v1")
|
| 69 |
self.gaia_agent = GAIAAgent(
|
| 70 |
model_type="OpenAIServerModel",
|
| 71 |
model_id="grok-3-latest", # X.AI's model
|
| 72 |
+
api_key=xai_key,
|
| 73 |
+
api_base=api_base,
|
| 74 |
+
temperature=temperature,
|
| 75 |
executor_type="local",
|
| 76 |
+
verbose=verbose
|
| 77 |
)
|
| 78 |
+
print(f"Using OpenAIServerModel with X.AI API at {api_base}")
|
| 79 |
+
elif model_type == "HfApiModel" and hf_token:
|
| 80 |
# Use Hugging Face API
|
| 81 |
self.gaia_agent = GAIAAgent(
|
| 82 |
model_type="HfApiModel",
|
| 83 |
model_id=model_id,
|
| 84 |
+
api_key=hf_token,
|
| 85 |
+
temperature=temperature,
|
| 86 |
executor_type="local",
|
| 87 |
+
verbose=verbose
|
| 88 |
)
|
| 89 |
print(f"Using HfApiModel with model_id: {model_id}")
|
| 90 |
+
elif openai_key:
|
| 91 |
# Default to OpenAI API
|
| 92 |
+
api_base = os.environ.get("AGENT_API_BASE")
|
| 93 |
+
kwargs = {
|
| 94 |
+
"model_type": "OpenAIServerModel",
|
| 95 |
+
"model_id": model_id,
|
| 96 |
+
"api_key": openai_key,
|
| 97 |
+
"temperature": temperature,
|
| 98 |
+
"executor_type": "local",
|
| 99 |
+
"verbose": verbose
|
| 100 |
+
}
|
| 101 |
+
if api_base:
|
| 102 |
+
kwargs["api_base"] = api_base
|
| 103 |
+
print(f"Using custom API base: {api_base}")
|
| 104 |
+
|
| 105 |
+
self.gaia_agent = GAIAAgent(**kwargs)
|
| 106 |
print(f"Using OpenAIServerModel with model_id: {model_id}")
|
| 107 |
+
else:
|
| 108 |
+
# Fallback to using whatever token we have
|
| 109 |
+
print("WARNING: Using fallback initialization with available token")
|
| 110 |
+
if hf_token:
|
| 111 |
+
self.gaia_agent = GAIAAgent(
|
| 112 |
+
model_type="HfApiModel",
|
| 113 |
+
model_id="mistralai/Mistral-7B-Instruct-v0.2",
|
| 114 |
+
api_key=hf_token,
|
| 115 |
+
temperature=temperature,
|
| 116 |
+
executor_type="local",
|
| 117 |
+
verbose=verbose
|
| 118 |
+
)
|
| 119 |
+
elif openai_key:
|
| 120 |
+
self.gaia_agent = GAIAAgent(
|
| 121 |
+
model_type="OpenAIServerModel",
|
| 122 |
+
model_id="gpt-3.5-turbo",
|
| 123 |
+
api_key=openai_key,
|
| 124 |
+
temperature=temperature,
|
| 125 |
+
executor_type="local",
|
| 126 |
+
verbose=verbose
|
| 127 |
+
)
|
| 128 |
+
else:
|
| 129 |
+
self.gaia_agent = GAIAAgent(
|
| 130 |
+
model_type="OpenAIServerModel",
|
| 131 |
+
model_id="grok-3-latest",
|
| 132 |
+
api_key=xai_key,
|
| 133 |
+
api_base=os.environ.get("XAI_API_BASE", "https://api.x.ai/v1"),
|
| 134 |
+
temperature=temperature,
|
| 135 |
+
executor_type="local",
|
| 136 |
+
verbose=verbose
|
| 137 |
+
)
|
| 138 |
else:
|
| 139 |
+
# No API keys available, log the error
|
| 140 |
+
print("ERROR: No API keys found. Please set at least one of these environment variables:")
|
| 141 |
+
print("- HUGGINGFACEHUB_API_TOKEN or HF_API_TOKEN")
|
| 142 |
+
print("- OPENAI_API_KEY")
|
| 143 |
+
print("- XAI_API_KEY")
|
| 144 |
+
self.gaia_agent = None
|
| 145 |
+
print("WARNING: No API keys found. Agent will not be able to answer questions.")
|
|
|
|
|
|
|
| 146 |
|
| 147 |
except Exception as e:
|
| 148 |
print(f"Error initializing GAIAAgent: {e}")
|
|
|
|
| 189 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 190 |
try:
|
| 191 |
agent = BasicAgent()
|
| 192 |
+
|
| 193 |
+
# Check if agent is properly initialized
|
| 194 |
+
if not agent.gaia_agent:
|
| 195 |
+
print("ERROR: Agent was not properly initialized")
|
| 196 |
+
return "ERROR: Agent was not properly initialized. Check the logs for details on missing API keys or configuration.", None
|
| 197 |
+
|
| 198 |
except Exception as e:
|
| 199 |
print(f"Error instantiating agent: {e}")
|
| 200 |
return f"Error initializing agent: {e}", None
|