diff --git a/src/codergpt/explainer/explainer.py b/src/codergpt/explainer/explainer.py index 48bea1b..da1d7b7 100644 --- a/src/codergpt/explainer/explainer.py +++ b/src/codergpt/explainer/explainer.py @@ -109,6 +109,13 @@ def explain(self, path: Union[str, Path], function: Optional[str] = None, classn response = self.chain.invoke({"input": f"Explain the following code: \n\n```\n{code}\n```"}) # Pretty print the response print(f"Explanation for '{classname}':\n{response.content}") + else: + # Explain full code + with open(path, "r") as file: + code = file.read() + response = self.chain.invoke({"input": f"Explain the following code: \n\n```\n{code}\n```"}) + # Pretty print the response + print(f"Explanation for the code:\n{response.content}") # # Ensure path is a string or Path object for consistency # if isinstance(path, str):