Spaces:
Sleeping
Sleeping
ashishMenon05 commited on
Commit ·
0815f50
1
Parent(s): f309cb4
fix: resolve _default_roles scope error in config.py
Browse files- backend/config.py +50 -48
backend/config.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
from pathlib import Path
|
| 3 |
from dotenv import load_dotenv
|
|
@@ -15,59 +16,60 @@ elif (ROOT_DIR / "default.env").exists():
|
|
| 15 |
else:
|
| 16 |
load_dotenv() # Fallback to standard search
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
class Settings:
|
| 19 |
# OLLAMA
|
| 20 |
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434/v1")
|
| 21 |
OLLAMA_API_KEY = os.getenv("OLLAMA_API_KEY", "ollama")
|
| 22 |
|
| 23 |
-
# AGENTS (Dynamic N-Agent Support
|
| 24 |
-
import json
|
| 25 |
-
_built_in_roles = ["INVESTIGATOR", "VALIDATOR", "FORENSIC_ANALYST", "NETWORK_ENGINEER", "SYSTEM_ADMIN", "SECURITY_ARCHITECT", "COMPLIANCE_OFFICER"]
|
| 26 |
-
_default_roles = ["INVESTIGATOR", "VALIDATOR", "FORENSIC_ANALYST", "NETWORK_ENGINEER"]
|
| 27 |
-
|
| 28 |
-
def _build_agents_from_env():
|
| 29 |
-
agents = []
|
| 30 |
-
suffix_map = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9}
|
| 31 |
-
for suffix, idx in suffix_map.items():
|
| 32 |
-
model_key = f"AGENT_{suffix.upper()}_MODEL"
|
| 33 |
-
provider_key = f"AGENT_{suffix.upper()}_PROVIDER"
|
| 34 |
-
role_key = f"AGENT_{suffix.upper()}_ROLE"
|
| 35 |
-
prompt_key = f"AGENT_{suffix.upper()}_SYSTEM_PROMPT"
|
| 36 |
-
temp_key = f"AGENT_{suffix.upper()}_TEMPERATURE"
|
| 37 |
-
|
| 38 |
-
model = os.getenv(model_key, "")
|
| 39 |
-
if model:
|
| 40 |
-
role_idx = idx % len(_default_roles)
|
| 41 |
-
agents.append({
|
| 42 |
-
"id": f"agent_{suffix}",
|
| 43 |
-
"model": model,
|
| 44 |
-
"provider": os.getenv(provider_key, "ollama"),
|
| 45 |
-
"role": os.getenv(role_key, _default_roles[role_idx]),
|
| 46 |
-
"system_prompt": os.getenv(prompt_key, ""),
|
| 47 |
-
"temperature": float(os.getenv(temp_key, str(0.7 - idx * 0.05)))
|
| 48 |
-
})
|
| 49 |
-
|
| 50 |
-
if not agents:
|
| 51 |
-
agents = [
|
| 52 |
-
{
|
| 53 |
-
"id": "agent_a",
|
| 54 |
-
"model": os.getenv("AGENT_A_MODEL", "meta-llama/Llama-3.1-8B-Instruct"),
|
| 55 |
-
"provider": os.getenv("AGENT_A_PROVIDER", "hf"),
|
| 56 |
-
"role": "INVESTIGATOR",
|
| 57 |
-
"system_prompt": "",
|
| 58 |
-
"temperature": 0.7
|
| 59 |
-
},
|
| 60 |
-
{
|
| 61 |
-
"id": "agent_b",
|
| 62 |
-
"model": os.getenv("AGENT_B_MODEL", "meta-llama/Llama-3.2-1B-Instruct"),
|
| 63 |
-
"provider": os.getenv("AGENT_B_PROVIDER", "hf"),
|
| 64 |
-
"role": "VALIDATOR",
|
| 65 |
-
"system_prompt": "",
|
| 66 |
-
"temperature": 0.6
|
| 67 |
-
}
|
| 68 |
-
]
|
| 69 |
-
return agents
|
| 70 |
-
|
| 71 |
try:
|
| 72 |
AGENTS_JSON = os.getenv("AGENTS_JSON")
|
| 73 |
AGENTS = json.loads(AGENTS_JSON) if AGENTS_JSON else _build_agents_from_env()
|
|
|
|
| 1 |
+
import json
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
from dotenv import load_dotenv
|
|
|
|
| 16 |
else:
|
| 17 |
load_dotenv() # Fallback to standard search
|
| 18 |
|
| 19 |
+
# Helper data for agent configuration
|
| 20 |
+
_BUILT_IN_ROLES = ["INVESTIGATOR", "VALIDATOR", "FORENSIC_ANALYST", "NETWORK_ENGINEER", "SYSTEM_ADMIN", "SECURITY_ARCHITECT", "COMPLIANCE_OFFICER"]
|
| 21 |
+
_DEFAULT_ROLES = ["INVESTIGATOR", "VALIDATOR", "FORENSIC_ANALYST", "NETWORK_ENGINEER"]
|
| 22 |
+
|
| 23 |
+
def _build_agents_from_env():
|
| 24 |
+
import json
|
| 25 |
+
agents = []
|
| 26 |
+
suffix_map = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9}
|
| 27 |
+
for suffix, idx in suffix_map.items():
|
| 28 |
+
model_key = f"AGENT_{suffix.upper()}_MODEL"
|
| 29 |
+
provider_key = f"AGENT_{suffix.upper()}_PROVIDER"
|
| 30 |
+
role_key = f"AGENT_{suffix.upper()}_ROLE"
|
| 31 |
+
prompt_key = f"AGENT_{suffix.upper()}_SYSTEM_PROMPT"
|
| 32 |
+
temp_key = f"AGENT_{suffix.upper()}_TEMPERATURE"
|
| 33 |
+
|
| 34 |
+
model = os.getenv(model_key, "")
|
| 35 |
+
if model:
|
| 36 |
+
role_idx = idx % len(_DEFAULT_ROLES)
|
| 37 |
+
agents.append({
|
| 38 |
+
"id": f"agent_{suffix}",
|
| 39 |
+
"model": model,
|
| 40 |
+
"provider": os.getenv(provider_key, "ollama"),
|
| 41 |
+
"role": os.getenv(role_key, _DEFAULT_ROLES[role_idx]),
|
| 42 |
+
"system_prompt": os.getenv(prompt_key, ""),
|
| 43 |
+
"temperature": float(os.getenv(temp_key, str(0.7 - idx * 0.05)))
|
| 44 |
+
})
|
| 45 |
+
|
| 46 |
+
if not agents:
|
| 47 |
+
agents = [
|
| 48 |
+
{
|
| 49 |
+
"id": "agent_a",
|
| 50 |
+
"model": os.getenv("AGENT_A_MODEL", "meta-llama/Llama-3.1-8B-Instruct"),
|
| 51 |
+
"provider": os.getenv("AGENT_A_PROVIDER", "hf"),
|
| 52 |
+
"role": "INVESTIGATOR",
|
| 53 |
+
"system_prompt": "",
|
| 54 |
+
"temperature": 0.7
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"id": "agent_b",
|
| 58 |
+
"model": os.getenv("AGENT_B_MODEL", "meta-llama/Llama-3.2-1B-Instruct"),
|
| 59 |
+
"provider": os.getenv("AGENT_B_PROVIDER", "hf"),
|
| 60 |
+
"role": "VALIDATOR",
|
| 61 |
+
"system_prompt": "",
|
| 62 |
+
"temperature": 0.6
|
| 63 |
+
}
|
| 64 |
+
]
|
| 65 |
+
return agents
|
| 66 |
+
|
| 67 |
class Settings:
|
| 68 |
# OLLAMA
|
| 69 |
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434/v1")
|
| 70 |
OLLAMA_API_KEY = os.getenv("OLLAMA_API_KEY", "ollama")
|
| 71 |
|
| 72 |
+
# AGENTS (Dynamic N-Agent Support)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
try:
|
| 74 |
AGENTS_JSON = os.getenv("AGENTS_JSON")
|
| 75 |
AGENTS = json.loads(AGENTS_JSON) if AGENTS_JSON else _build_agents_from_env()
|