Skip to content

Commit

Permalink
added abspath
Browse files Browse the repository at this point in the history
  • Loading branch information
shhlife committed Nov 21, 2024
1 parent 2f58baf commit 183468b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions griptape/media_viewer/tools/media_viewer_tool/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ class MediaViewerTool(BaseTool):
def show_file(self, params: dict) -> TextArtifact | ErrorArtifact:
# get the file path from the parameters
file_path = params["values"]["file_path"]
absolute_path = os.path.abspath(file_path)
try:
if sys.platform.startswith("darwin"): # macOS
subprocess.call(("open", file_path))
subprocess.call(("open", absolute_path))
elif os.name == "nt": # Windows
os.startfile(file_path)
os.startfile(absolute_path)
elif os.name == "posix": # Linux/Unix
subprocess.call(("xdg-open", file_path))
subprocess.call(("xdg-open", absolute_path))
else:
print("Unsupported OS.")
return TextArtifact(f"File displayed: {file_path}")
return TextArtifact(f"File displayed: {absolute_path}")
except Exception as e:
return TextArtifact(str(e))

0 comments on commit 183468b

Please sign in to comment.