Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
divijmuthu authored Oct 29, 2024
2 parents 91b3cd7 + 4c16dbb commit 6178fcc
Show file tree
Hide file tree
Showing 19 changed files with 697 additions and 361 deletions.
2 changes: 1 addition & 1 deletion berkeley-function-call-leaderboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to the Berkeley Function Calling Leaderboard will be documented in this file.

- [Oct 24, 2024] [#719](https://github.com/ShishirPatil/gorilla/pull/719): Bug fix in the dataset and ground truth for the multi-turn categories.
- [Oct 24, 2024] [#719](https://github.com/ShishirPatil/gorilla/pull/719), [#722](https://github.com/ShishirPatil/gorilla/pull/722): Bug fix in the dataset and ground truth for the multi-turn categories.
- [Oct 17, 2024] [#683](https://github.com/ShishirPatil/gorilla/pull/683): Bug fix for the multi turn categories for ambiguity in action intention and function parameters.
- [Oct 17, 2024] [#709](https://github.com/ShishirPatil/gorilla/pull/709): Rephrase question prompt for Java and JavaScript categories to improve clarity and action intent.
- [Oct 17, 2024] [#708](https://github.com/ShishirPatil/gorilla/pull/708): Update the ground truth for the REST category to be up-to-date with the latest API response structure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def _list_contents(self) -> List[str]:
List the names of all contents in the directory.
Returns:
contents (list): A list of names of the files and subdirectories in the directory.
contents (List[str]): A list of names of the files and subdirectories in the directory.
"""
return list(self.contents.keys())

Expand All @@ -130,9 +130,8 @@ def __eq__(self, other: object) -> bool:
return self.name == other.name and self.contents == other.contents


DEFAULT_STATE = {
"root": Directory("/", None)
}
DEFAULT_STATE = {"root": Directory("/", None)}


class GorillaFileSystem:

Expand Down Expand Up @@ -194,8 +193,7 @@ def _load_scenario(self, scenario: dict, long_context: bool = False) -> None:
if "root" in scenario:
root_dir = Directory(list(scenario["root"].keys())[0], None)
self.root = self._load_directory(
scenario["root"][list(scenario["root"].keys())[0]]["contents"],
root_dir
scenario["root"][list(scenario["root"].keys())[0]]["contents"], root_dir
)
self._current_dir = self.root

Expand Down Expand Up @@ -227,10 +225,10 @@ def _load_directory(
content += FILE_CONTENT_EXTENSION
new_file = File(dir_name, content)
parent.contents[dir_name] = new_file

if is_bottommost and self.long_context:
self._populate_directory(parent, 30)

return parent

def _populate_directory(
Expand Down Expand Up @@ -269,10 +267,10 @@ def ls(self, a: bool = False) -> Dict[str, List[str]]:
List the contents of the current directory.
Args:
a (bool, optional): Show hidden files and directories. Defaults to False.
a (bool): [Optional] Show hidden files and directories. Defaults to False.
Returns:
current_directory_content (list): A list of the contents of the specified directory.
current_directory_content (List[str]): A list of the contents of the specified directory.
"""
contents = self._current_dir._list_contents()
if not a:
Expand Down Expand Up @@ -319,9 +317,6 @@ def mkdir(self, dir_name: str) -> Union[None, Dict[str, str]]:
Args:
dir_name (str): The name of the new directory at current directory. You can only create directory at current directory.
Returns:
None or error (dict): None if successful, or error message if directory already exists.
"""
if not self._validate_file_or_directory_name(dir_name):
return {
Expand All @@ -339,9 +334,6 @@ def touch(self, file_name: str) -> Union[None, Dict[str, str]]:
Args:
file_name (str): The name of the new file in the current directory. file_name is local to the current directory and does not allow path.
Returns:
None or error (dict): None if successful, or error message if file already exists.
"""
if not self._validate_file_or_directory_name(file_name):
return {"error": f"touch: cannot touch '{file_name}': Invalid character"}
Expand All @@ -350,7 +342,7 @@ def touch(self, file_name: str) -> Union[None, Dict[str, str]]:
return {"error": f"touch: cannot touch '{file_name}': File exists"}

self._current_dir._add_file(file_name)
return {}
return None

def echo(
self, content: str, file_name: Optional[str] = None
Expand All @@ -360,7 +352,7 @@ def echo(
Args:
content (str): The content to write or display.
file_name (str, optional): The name of the file at current directory to write the content to. Defaults to None.
file_name (str): [Optional] The name of the file at current directory to write the content to. Defaults to None.
Returns:
terminal_output (str): The content if no file name is provided, or None if written to file.
Expand Down Expand Up @@ -407,17 +399,15 @@ def find(self, path: str = ".", name: Optional[str] = None) -> Dict[str, List[st
This method searches for files and directories within a specified path that match
the given name. If no name is provided, it returns all files and directories
in the specified path and its subdirectories.
Note: This method performs a recursive search through all subdirectories of the given path.
Args:
path (str): The directory path to start the search. Defaults to the current directory (".").
name (Optional[str]): The name of the file or directory to search for. If None, all items are returned.
name (str): [Optional] The name of the file or directory to search for. If None, all items are returned.
Returns:
Dict[str, List[str]]: A dictionary with a single key "matches" containing a list of
matching file and directory paths relative to the given path.
matches (List[str]): A list of matching file and directory paths relative to the given path.
Note:
This method performs a recursive search through all subdirectories of the given path.
"""
matches = []
target_dir = self._current_dir
Expand All @@ -442,7 +432,8 @@ def wc(self, file_name: str, mode: str = "l") -> Dict[str, Union[int, str]]:
mode (str): Mode of operation ('l' for lines, 'w' for words, 'c' for characters).
Returns:
dict: Dictionary containing line count, word count, and byte count.
count (int): The count of the number of lines, words, or characters in the file.
type (str): The type of unit we are counting. [Enum]: ["lines", "words", "characters"]
"""
if mode not in ["l", "w", "c"]:
return {"error": f"wc: invalid mode '{mode}'"}
Expand All @@ -454,15 +445,15 @@ def wc(self, file_name: str, mode: str = "l") -> Dict[str, Union[int, str]]:

if mode == "l":
line_count = len(content.splitlines())
return {"lines": line_count}
return {"count": line_count, "type": "lines"}

elif mode == "w":
word_count = len(content.split())
return {"words": word_count}
return {"count": word_count, "type": "words"}

elif mode == "c":
char_count = len(content)
return {"characters": char_count}
return {"count": char_count, "type": "characters"}

return {"error": f"wc: {file_name}: No such file or directory"}

Expand Down Expand Up @@ -496,7 +487,7 @@ def grep(self, file_name: str, pattern: str) -> Dict[str, List[str]]:
pattern (str): The pattern to search for.
Returns:
matching_lines (list): Lines that match the pattern.
matching_lines (List[str]): Lines that match the pattern.
"""
if file_name in self._current_dir.contents:
file = self._current_dir._get_item(file_name)
Expand All @@ -515,7 +506,7 @@ def xargs(self, command: str, file_name: str = None):
Args:
command (str): The command to execute with arguments.
file_name (str, optional): The file containing arguments. Defaults to None.
file_name (str): [Optional] The file containing arguments. Defaults to None.
Returns:
output (str): The result of the command execution.
Expand All @@ -530,7 +521,7 @@ def xargs(self, command: str, file_name: str = None):
else:
return {"error": f"xargs: {file_name}: No such file or directory"}
else:
return {"error": f"Argument not supported"}
return {"error": f"Argument not supported"}

try:
result = subprocess.run([command] + args, capture_output=True, text=True)
Expand Down Expand Up @@ -637,8 +628,7 @@ def mv(self, source: str, destination: str) -> Dict[str, str]:
Args:
source (str): Source name of the file or directory to move. Source must be local to the current directory.
destination (str): The destination name to move the file or directory to. Destination must be local to the current directory and cannot be a path.
If destination is not an existing directory like when renaming something, destination is the new file name.
destination (str): The destination name to move the file or directory to. Destination must be local to the current directory and cannot be a path. If destination is not an existing directory like when renaming something, destination is the new file name.
Returns:
result (str): The result of the move operation.
Expand All @@ -650,9 +640,11 @@ def mv(self, source: str, destination: str) -> Dict[str, str]:

if not isinstance(item, (File, Directory)):
return {"error": f"mv: cannot move '{source}': Not a file or directory"}

if "/" in destination:
return {"error": f"mv: no path allowed in destination. Only file name and folder name is supported for this operation."}
return {
"error": f"mv: no path allowed in destination. Only file name and folder name is supported for this operation."
}

# Check if the destination is an existing directory
if destination in self._current_dir.contents:
Expand Down Expand Up @@ -762,7 +754,9 @@ def cp(self, source: str, destination: str) -> Dict[str, str]:
return {"error": f"cp: cannot copy '{source}': Not a file or directory"}

if "/" in destination:
return {"error": f"cp: don't allow path in destination. Only file name and folder name is supported for this operation."}
return {
"error": f"cp: don't allow path in destination. Only file name and folder name is supported for this operation."
}
# Check if the destination is an existing directory
if destination in self._current_dir.contents:
dest_item = self._current_dir._get_item(destination)
Expand Down Expand Up @@ -800,7 +794,7 @@ def _navigate_to_directory(
Navigate to a specified directory path from the current directory.
Args:
path (str, optional): The path to navigate to. Defaults to None (current directory).
path (str): [Optional] The path to navigate to. Defaults to None (current directory).
Returns:
target_directory (Directory or dict): The target directory object or error message.
Expand Down
Loading

0 comments on commit 6178fcc

Please sign in to comment.