LukeMattingly
commited on
Commit
·
cdc3eac
1
Parent(s):
509c0b5
allow for getting of file contents
Browse files
app.py
CHANGED
@@ -165,6 +165,27 @@ def detect_code_smells(code: str) -> str:
|
|
165 |
except Exception as e:
|
166 |
return f"Error analyzing code: {str(e)}"
|
167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
final_answer = FinalAnswerTool()
|
169 |
|
170 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
@@ -183,7 +204,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
183 |
|
184 |
agent = CodeAgent(
|
185 |
model=model,
|
186 |
-
tools=[final_answer, get_open_pull_requests, find_todo_comments, get_pr_diff, get_pr_files_changed, detect_code_smells ], ## add your tools here (don't remove final answer)
|
187 |
max_steps=6,
|
188 |
verbosity_level=1,
|
189 |
grammar=None,
|
|
|
165 |
except Exception as e:
|
166 |
return f"Error analyzing code: {str(e)}"
|
167 |
|
168 |
+
@tool
|
169 |
+
def get_file_content(github_url: str, file_path: str) -> str:
|
170 |
+
"""Fetches the content of a specific file from the GitHub repository.
|
171 |
+
|
172 |
+
Args:
|
173 |
+
github_url: The URL of the GitHub repository (e.g., 'https://github.com/user/repo').
|
174 |
+
file_path: The relative path of the file within the repository (e.g., 'src/module.py').
|
175 |
+
|
176 |
+
Returns:
|
177 |
+
A string containing the file's content or an error message if retrieval fails.
|
178 |
+
"""
|
179 |
+
try:
|
180 |
+
owner_repo = github_url.replace("https://github.com/", "")
|
181 |
+
api_url = f"https://raw.githubusercontent.com/{owner_repo}/main/{file_path}"
|
182 |
+
response = requests.get(api_url)
|
183 |
+
if response.status_code != 200:
|
184 |
+
return f"Error fetching file content: {response.status_code}"
|
185 |
+
return response.text
|
186 |
+
except Exception as e:
|
187 |
+
return f"Error: {str(e)}"
|
188 |
+
|
189 |
final_answer = FinalAnswerTool()
|
190 |
|
191 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
204 |
|
205 |
agent = CodeAgent(
|
206 |
model=model,
|
207 |
+
tools=[final_answer, get_open_pull_requests, find_todo_comments, get_pr_diff, get_pr_files_changed, detect_code_smells, get_file_content ], ## add your tools here (don't remove final answer)
|
208 |
max_steps=6,
|
209 |
verbosity_level=1,
|
210 |
grammar=None,
|