Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shriyansh Agnihotri committed Jan 14, 2025
1 parent 3d5fb50 commit 86981ec
Show file tree
Hide file tree
Showing 29 changed files with 294 additions and 845 deletions.
26 changes: 26 additions & 0 deletions env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
LLM_MODEL_NAME=PUT YOUR MODEL NAME HERE, for example: gpt-4o, gpt-4o
LLM_MODEL_API_KEY=PUT YOUR MODEL API KEY HERE
# LLM_MODEL_BASE_URL=IF YOU ARE USING OpenAI, remove this line, otherwise add the base URL, for example: https://api.groq.com/openai/v1

# If you want to use json file for config (see sample agents_llm_config.json and the Readme)
# AGENTS_LLM_CONFIG_FILE=agents_llm_config.json
# AGENTS_LLM_CONFIG_FILE_REF_KEY=The key for the config stanza to use from the file
# PROJECT_SOURCE_ROOT=folder where to save data.

# optional
# CDP_ENDPOINT_URL=ws://localhost:9222/devtools/browser/b12de40a-fc1c-4ebb-81d9-046e901f376d

TOKENIZERS_PARALLELISM=false
MODE=prod
HEADLESS=false
RECORD_VIDEO=false
TAKE_SCREENSHOTS=true
BROWSER_TYPE=chromium
CAPTURE_NETWORK=true
HF_HOME=./.cache
# select the device from this file https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json
# RUN_DEVICE="iPhone 15 Pro Max"
# GEO_API_KEY=
# GEO_PROVIDER=maps_co

# LOAD_EXTRA_TOOLS=true
31 changes: 8 additions & 23 deletions testzeus_hercules/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def sequential_process() -> None:
feature_file_name = os.path.basename(input_gherkin_file_path)

result_of_tests = []
final_result_file_name = (
f"{CONF.get_junit_xml_base_path()}/{feature_file_name}_result.xml"
)
final_result_file_name = f"{CONF.get_junit_xml_base_path()}/{feature_file_name}_result.xml"
add_event(EventType.RUN, EventData(detail="Total Runs: " + str(len(list_of_feats))))
for feat in list_of_feats:
file_path = feat["output_file"]
Expand Down Expand Up @@ -77,9 +75,7 @@ def sequential_process() -> None:
for key, value in agent.client.total_usage_summary.items():
if key == "total_cost":
# Sum total_cost across agents
cost_metrics["total_cost"] = (
cost_metrics.get("total_cost", 0) + value
)
cost_metrics["total_cost"] = cost_metrics.get("total_cost", 0) + value
elif isinstance(value, dict):
if ag_name not in cost_metrics:
cost_metrics[ag_name] = {}
Expand All @@ -92,20 +88,12 @@ def sequential_process() -> None:
}

cost_metrics[ag_name][key]["cost"] += value.get("cost", 0)
cost_metrics[ag_name][key]["prompt_tokens"] += value.get(
"prompt_tokens", 0
)
cost_metrics[ag_name][key][
"completion_tokens"
] += value.get("completion_tokens", 0)
cost_metrics[ag_name][key]["total_tokens"] += value.get(
"total_tokens", 0
)
cost_metrics[ag_name][key]["prompt_tokens"] += value.get("prompt_tokens", 0)
cost_metrics[ag_name][key]["completion_tokens"] += value.get("completion_tokens", 0)
cost_metrics[ag_name][key]["total_tokens"] += value.get("total_tokens", 0)
else:
# For unexpected keys, just add them as-is
cost_metrics[ag_name][key] = (
cost_metrics.get(key, 0) + value
)
cost_metrics[ag_name][key] = cost_metrics.get(key, 0) + value

execution_time = runner.execution_time
if runner.result and runner.result.chat_history:
Expand Down Expand Up @@ -134,17 +122,14 @@ def sequential_process() -> None:
proofs_video_path=runner.browser_manager.get_latest_video_path(),
network_logs_path=runner.browser_manager.request_response_log_file,
logs_path=CONF.get_source_log_folder_path(stake_id),
planner_thoughts_path=CONF.get_source_log_folder_path(stake_id)
+ "/chat_messages.json",
planner_thoughts_path=CONF.get_source_log_folder_path(stake_id) + "/chat_messages.json",
)
)
JUnitXMLGenerator.merge_junit_xml(result_of_tests, final_result_file_name)
logger.info(f"Results published in junitxml file: {final_result_file_name}")

# building html from junitxml
final_result_html_file_name = (
f"{CONF.get_junit_xml_base_path()}/{feature_file_name}_result.html"
)
final_result_html_file_name = f"{CONF.get_junit_xml_base_path()}/{feature_file_name}_result.html"
prepare_html([final_result_file_name, final_result_html_file_name])
logger.info(f"Results published in html file: {final_result_html_file_name}")

Expand Down
61 changes: 15 additions & 46 deletions testzeus_hercules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,11 @@ def __init__(self, config_dict: dict, ignore_env: bool = False):
# -------------------------------------------------------------------------

@classmethod
def from_dict(
cls, config_dict: dict, ignore_env: bool = False
) -> "BaseConfigManager":
def from_dict(cls, config_dict: dict, ignore_env: bool = False) -> "BaseConfigManager":
return cls(config_dict, ignore_env=ignore_env)

@classmethod
def from_json(
cls, json_file_path: str, ignore_env: bool = False
) -> "BaseConfigManager":
def from_json(cls, json_file_path: str, ignore_env: bool = False) -> "BaseConfigManager":
with open(json_file_path, "r", encoding="utf-8") as f:
config_dict = json.load(f)
return cls(config_dict, ignore_env=ignore_env)
Expand All @@ -82,12 +78,8 @@ def _parse_arguments(self) -> None:
Parse Hercules-specific command-line arguments
and place them into the environment for consistency.
"""
parser = argparse.ArgumentParser(
description="Hercules: The World's First Open-Source AI Agent for End-to-End Testing"
)
parser.add_argument(
"--input-file", type=str, help="Path to the input file.", required=False
)
parser = argparse.ArgumentParser(description="Hercules: The World's First Open-Source AI Agent for End-to-End Testing")
parser.add_argument("--input-file", type=str, help="Path to the input file.", required=False)
parser.add_argument(
"--output-path",
type=str,
Expand Down Expand Up @@ -194,22 +186,13 @@ def _check_llm_config(self) -> None:
llm_model_name = self._config.get("LLM_MODEL_NAME")
llm_model_api_key = self._config.get("LLM_MODEL_API_KEY")
agents_llm_config_file = self._config.get("AGENTS_LLM_CONFIG_FILE")
agents_llm_config_file_ref_key = self._config.get(
"AGENTS_LLM_CONFIG_FILE_REF_KEY"
)
agents_llm_config_file_ref_key = self._config.get("AGENTS_LLM_CONFIG_FILE_REF_KEY")

if (llm_model_name and llm_model_api_key) and (
agents_llm_config_file or agents_llm_config_file_ref_key
):
logger.error(
"Provide either LLM_MODEL_NAME and LLM_MODEL_API_KEY together, "
"or AGENTS_LLM_CONFIG_FILE and AGENTS_LLM_CONFIG_FILE_REF_KEY together, not both."
)
if (llm_model_name and llm_model_api_key) and (agents_llm_config_file or agents_llm_config_file_ref_key):
logger.error("Provide either LLM_MODEL_NAME and LLM_MODEL_API_KEY together, " "or AGENTS_LLM_CONFIG_FILE and AGENTS_LLM_CONFIG_FILE_REF_KEY together, not both.")
exit(1)

if (not llm_model_name or not llm_model_api_key) and (
not agents_llm_config_file or not agents_llm_config_file_ref_key
):
if (not llm_model_name or not llm_model_api_key) and (not agents_llm_config_file or not agents_llm_config_file_ref_key):
logger.error(
"Either LLM_MODEL_NAME and LLM_MODEL_API_KEY must be set together, "
"or AGENTS_LLM_CONFIG_FILE and AGENTS_LLM_CONFIG_FILE_REF_KEY must be set together. "
Expand All @@ -233,24 +216,12 @@ def _finalize_defaults(self) -> None:
"INPUT_GHERKIN_FILE_PATH",
os.path.join(project_source_root, "input/test.feature"),
)
self._config.setdefault(
"JUNIT_XML_BASE_PATH", os.path.join(project_source_root, "output")
)
self._config.setdefault(
"TEST_DATA_PATH", os.path.join(project_source_root, "test_data")
)
self._config.setdefault(
"SCREEN_SHOT_PATH", os.path.join(project_source_root, "proofs")
)
self._config.setdefault(
"PROJECT_TEMP_PATH", os.path.join(project_source_root, "temp")
)
self._config.setdefault(
"SOURCE_LOG_FOLDER_PATH", os.path.join(project_source_root, "log_files")
)
self._config.setdefault(
"TMP_GHERKIN_PATH", os.path.join(project_source_root, "gherkin_files")
)
self._config.setdefault("JUNIT_XML_BASE_PATH", os.path.join(project_source_root, "output"))
self._config.setdefault("TEST_DATA_PATH", os.path.join(project_source_root, "test_data"))
self._config.setdefault("SCREEN_SHOT_PATH", os.path.join(project_source_root, "proofs"))
self._config.setdefault("PROJECT_TEMP_PATH", os.path.join(project_source_root, "temp"))
self._config.setdefault("SOURCE_LOG_FOLDER_PATH", os.path.join(project_source_root, "log_files"))
self._config.setdefault("TMP_GHERKIN_PATH", os.path.join(project_source_root, "gherkin_files"))

# Extra environment defaults from original code
if "HF_HOME" not in self._config:
Expand Down Expand Up @@ -473,9 +444,7 @@ def __init__(self, config_dict: dict, ignore_env: bool = False):
super().__init__(config_dict=config_dict, ignore_env=ignore_env)

@classmethod
def instance(
cls, config_dict: Optional[dict] = None, ignore_env: bool = False
) -> "SingletonConfigManager":
def instance(cls, config_dict: Optional[dict] = None, ignore_env: bool = False) -> "SingletonConfigManager":
"""
Return the shared instance. If an instance does not already exist,
create one using config_dict (or empty dict if None is supplied).
Expand Down
2 changes: 1 addition & 1 deletion testzeus_hercules/core/agents/api_nav_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from testzeus_hercules.core.agents.base_nav_agent import BaseNavAgent
from testzeus_hercules.core.extra_tools.geo_tools import *
from testzeus_hercules.core.memory.state_handler import *
from testzeus_hercules.core.tools.api_calls import *
from testzeus_hercules.core.extra_tools.geo_tools import *
from testzeus_hercules.utils.logger import logger


Expand Down
22 changes: 6 additions & 16 deletions testzeus_hercules/core/agents/browser_nav_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import autogen # type: ignore
from testzeus_hercules.core.agents.base_nav_agent import BaseNavAgent
from testzeus_hercules.core.extra_tools.geo_tools import *
from testzeus_hercules.core.memory.prompt_compressor import add_text_compressor
from testzeus_hercules.core.memory.state_handler import *
from testzeus_hercules.core.memory.static_ltm import get_user_ltm
Expand Down Expand Up @@ -34,7 +35,6 @@
from testzeus_hercules.core.tools.set_slider_value import *
from testzeus_hercules.core.tools.tool_registry import tool_registry
from testzeus_hercules.core.tools.upload_file import *
from testzeus_hercules.core.extra_tools.geo_tools import *
from testzeus_hercules.telemetry import EventData, EventType, add_event
from testzeus_hercules.utils.logger import logger

Expand All @@ -57,37 +57,27 @@ def register_tools(self) -> None:
# )(enter_text_and_click)
# self.nav_executor.register_for_execution()(enter_text_and_click)

self.agent.register_for_llm(
description=LLM_PROMPTS["GET_DOM_WITH_CONTENT_TYPE_PROMPT"]
)(get_dom_with_content_type)
self.agent.register_for_llm(description=LLM_PROMPTS["GET_DOM_WITH_CONTENT_TYPE_PROMPT"])(get_dom_with_content_type)
self.nav_executor.register_for_execution()(get_dom_with_content_type)

self.agent.register_for_llm(description=LLM_PROMPTS["CLICK_PROMPT"])(
click_element
)
self.agent.register_for_llm(description=LLM_PROMPTS["CLICK_PROMPT"])(click_element)
self.nav_executor.register_for_execution()(click_element)

self.agent.register_for_llm(description=LLM_PROMPTS["GET_URL_PROMPT"])(geturl)
self.nav_executor.register_for_execution()(geturl)

self.agent.register_for_llm(description=LLM_PROMPTS["BULK_ENTER_TEXT_PROMPT"])(
bulk_enter_text
)
self.agent.register_for_llm(description=LLM_PROMPTS["BULK_ENTER_TEXT_PROMPT"])(bulk_enter_text)
self.nav_executor.register_for_execution()(bulk_enter_text)

# self.agent.register_for_llm(description=LLM_PROMPTS["ENTER_TEXT_PROMPT"])(
# entertext
# )
# self.nav_executor.register_for_execution()(entertext)

self.agent.register_for_llm(
description=LLM_PROMPTS["PRESS_KEY_COMBINATION_PROMPT"]
)(press_key_combination)
self.agent.register_for_llm(description=LLM_PROMPTS["PRESS_KEY_COMBINATION_PROMPT"])(press_key_combination)
self.nav_executor.register_for_execution()(press_key_combination)

self.agent.register_for_llm(
description=LLM_PROMPTS["EXTRACT_TEXT_FROM_PDF_PROMPT"]
)(extract_text_from_pdf)
self.agent.register_for_llm(description=LLM_PROMPTS["EXTRACT_TEXT_FROM_PDF_PROMPT"])(extract_text_from_pdf)
self.nav_executor.register_for_execution()(extract_text_from_pdf)

self.agent.register_for_llm(description=LLM_PROMPTS["HOVER_PROMPT"])(hover)
Expand Down
Loading

0 comments on commit 86981ec

Please sign in to comment.