SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Typing improvements for summarizer (#809)
Kilian Lieretd6770dbcff79
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 1f67c38d..dccc9165 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -176,10 +176,10 @@ class AgentConfig(FrozenSerializable):"history_processor",HistoryProcessor.get(self.history_processor, **self.history_processor_args),)- if "WINDOW" in self.env_variables and self.summarizer_config.window_length is not None:+ if "WINDOW" in self.env_variables:window_size = self.env_variables["WINDOW"]if self.summarizer_config.window_length < int(window_size):- msg = f"Summarizer window length is set to {self.summarizer_config.window_length} which is less then the defined window length {window_size}"+ msg = f"Summarizer window length is set to {self.summarizer_config.window_length} which is less than the window length {window_size}"raise ValueError(msg)object.__setattr__(self,diff --git a/sweagent/agent/summarizer.py b/sweagent/agent/summarizer.pyindex 2394bbb8..3c06d8b6 100644--- a/sweagent/agent/summarizer.py+++ b/sweagent/agent/summarizer.py@@ -21,16 +21,16 @@ class SummarizerConfig(FrozenSerializable):"""The configuration for the summarizer"""function: str = "Identity"- window_length: int | None = 105+ window_length: int = 105template: str | None = Nonemodel: ModelArguments | None = Nonesystem_template: str | None = Noneinstance_template: str | None = Nonedef __post_init__(self):- object.__setattr__(self, "function", SummarizeFunction.get(self.function, self.window_length))+ object.__setattr__(self, "function", SummarizeFunction.get(self.function, self.window_length)) # type: ignoreif isinstance(self.model, dict):- object.__setattr__(self, "model", ModelArguments.from_dict(self.summarizer_model))+ object.__setattr__(self, "model", ModelArguments.from_dict(self.summarizer_model)) # type: ignore# ABSTRACT BASE CLASSES@@ -59,7 +59,7 @@ class SummarizeFunction(metaclass=SummarizeFunctionMeta):We use get to generate the right summarizer based on the name of the summarizer."""- def __init__(self, window_length: int | None):+ def __init__(self, window_length: int):self._window_length = window_lengthself.logger = get_logger("summarizer")@@ -74,7 +74,8 @@ class SummarizeFunction(metaclass=SummarizeFunctionMeta):return "".join(c if c.isalnum() else "_" for c in action)[:50]@staticmethod- def _upload_file_to_container(file_content: bytes, file_path_on_container: str, env: SWEEnv):+ def _upload_file_to_container(file_content: str, file_path_on_container: str, env: SWEEnv):+ assert env.container_obj is not Noneenv.communicate(f'mkdir -p "{Path(file_path_on_container).parent}"')with tempfile.NamedTemporaryFile() as fp:fp.write(file_content.encode("utf-8"))@@ -123,7 +124,7 @@ class SimpleSummarizer(SummarizeFunction):"search_dir",]- def __call__(self, input: str, observation: str, env: SWEEnv, model: type[BaseModel]) -> tuple[str, APIStats]:+ def __call__(self, input: str, observation: str, env: SWEEnv, model: BaseModel) -> tuple[str, APIStats]:try:if (any(input.startswith(s) for s in self.block_list_input)