From 07a93f58db42c1048fa7cab3c823f65a765d6e3e Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Fri, 9 Feb 2024 12:58:26 -0600 Subject: [PATCH] Add explanation for full code. --- src/codergpt/explainer/explainer.py | 7 +++++++ 1 file changed, 7 insertions(+) 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):