8000 fix: update workspace read/write method, so it's clear it only supports plain text format by tybalex · Pull Request #487 · obot-platform/tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: update workspace read/write method, so it's clear it only supports plain text format #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions workspace-files/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var (
MaxFileSize = 250_000
)

var unsupportedFileTypes = []string{
".pdf", ".docx", ".doc", ".pptx", ".ppt", ".xlsx", ".xls", ".jpg", ".png", ".gif", ".mp3", ".mp4", ".zip", ".rar",
}

func main() {
if len(os.Args) == 1 {
fmt.Printf(`
Expand Down Expand Up @@ -169,6 +173,14 @@ func list(ctx context.Context, filename string) error {
}

func read(ctx context.Context, filename string) error {

// Check for common binary file types that are not supported. Less common types should be caught by the utf8.Valid() check
for _, ext := range unsupportedFileTypes {
if strings.HasSuffix(strings.ToLower(filename), ext) {
return fmt.Errorf("reading files with extension %s is not supported", ext)
}
}

client, err := gptscript.NewGPTScript()
if err != nil {
return err
Expand All @@ -192,6 +204,13 @@ func read(ctx context.Context, filename string) error {
}

func write(ctx context.Context, filename, content string) error {
// Check if the file extension is unsupported
for _, ext := range unsupportedFileTypes {
if strings.HasSuffix(strings.ToLower(filename), ext) {
return fmt.Errorf("writing to files with extension %s is not supported", ext)
}
}

client, err := gptscript.NewGPTScript()
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions workspace-files/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ to read and write in their user interface. You can collaborate with the user by
Do not ask first to create files in the workspace. Immediately write contents to the workspace as opposed to describing
the contents to the user. If the user changes a file, they will inform you that content has changed, with the new
contents of the file.
Do NOT copy non-plain text files to .txt to read them. This won't make them readable.

List of files in workspace:
$FILES
Expand All @@ -38,14 +39,14 @@ Params: dir: The directory to list files from

---
Name: workspace_read
Description: Read the contents of a file in the workspace
Description: Read the contents of a file in the workspace. Supports only plain text formats (e.g., .txt, .md).
Params: filename: The filename to read

#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool read

---
Name: workspace_write
Description: Write contents to a file, overwriting the existing file if it exists.
Description: Writes content to a file, replacing any existing content if the file already exists. Supports only plain text formats (e.g., .txt, .md).
Params: filename: The filename to write to
Params: content: The contents to write to the file

Expand Down
Loading
0