Skip to content

Commit

Permalink
tools
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng committed Sep 6, 2024
1 parent d02ffb2 commit 0b1cb56
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/seer/automation/autofix/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import fnmatch
import logging
import os
import textwrap

from langfuse.decorators import observe
Expand Down Expand Up @@ -176,6 +178,40 @@ def keyword_search(

return result_str

@observe(name="File Search")
@ai_track(description="File Search")
def file_search(
self,
filename: str,
repo_name: str | None = None,
):
"""
Given a filename with extension returns the list of locations where a file with the name is found.
"""
repo_client = self.context.get_repo_client(repo_name=repo_name)
all_paths = repo_client.get_index_file_set()
found = [path for path in all_paths if os.path.basename(path) == filename]
if len(found) == 0:
return f"no file with name {filename} found in repository"
return ",".join(found)

@observe(name="File Search Wildcard")
@ai_track(description="File Search Wildcard")
def file_search_wildcard(
self,
pattern: str,
repo_name: str | None = None,
):
"""
Given a filename pattern with wildcards, returns the list of file paths that match the pattern.
"""
repo_client = self.context.get_repo_client(repo_name=repo_name)
all_paths = repo_client.get_index_file_set()
found = [path for path in all_paths if fnmatch.fnmatch(path, pattern)]
if len(found) == 0:
return f"No files matching pattern '{pattern}' found in repository"
return "\n".join(found)

def get_tools(self):
tools = [
FunctionTool(
Expand Down Expand Up @@ -245,6 +281,40 @@ def get_tools(self):
},
],
),
FunctionTool(
name="file_search",
fn=self.file_search,
description="Searches for a file in the codebase.",
parameters=[
{
"name": "filename",
"type": "string",
"description": "The file to search for.",
},
{
"name": "repo_name",
"type": "string",
"description": "Optional name of the repository to search in if you know it.",
},
],
),
FunctionTool(
name="file_search_wildcard",
fn=self.file_search_wildcard,
description="Searches for files in a folder using a wildcard pattern.",
parameters=[
{
"name": "pattern",
"type": "string",
"description": "The wildcard pattern to match files.",
},
{
"name": "repo_name",
"type": "string",
"description": "Optional name of the repository to search in if you know it.",
},
],
),
]

return tools

0 comments on commit 0b1cb56

Please sign in to comment.