gptscript-ai / gpt4-v-vision

9 stars 4 forks source link

Not able to use "~" in file path #2

Open sangee2004 opened 7 months ago

sangee2004 commented 7 months ago

Steps to reproduce the problem:

  1. Clone this repo locally.
  2. Tried to execute the following gptscript with "~" in the filepath.
tools: tool.gpt

Describe the picture in files ~/Downloads/sunrise.jpeg with high fidelity using prompt as describe the picture in detail
 % ls  ~/Downloads/sunrise.jpeg
/Users/sangeethahariharan/Downloads/sunrise.jpeg

Script fails to execute with following errors:

17:08:19 started  [main]
17:08:19 sent     [main]
         content  [1] content | Waiting for model response...
         content  [1] content | tool call tool -> {"detail":"high","images":"file://~/Downloads/sunrise.jpeg","prompt":"describe the picture in detail"}
17:08:21 started  [vision(2)] [input={"detail":"high","images":"file://~/Downloads/sunrise.jpeg","prompt":"describe the picture in detail"}]
17:08:21 sent     [vision(2)]
(node:99468) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
node:fs:581
  return binding.open(
                 ^

Error: ENOENT: no such file or directory, open '~/Downloads/sunrise.jpeg'
    at Object.openSync (node:fs:581:18)
    at Object.readFileSync (node:fs:460:35)
    at resolveImageURL (file:///Users/sangeethahariharan/vision/index.js:89:23)
    at Command.run (file:///Users/sangeethahariharan/vision/index.js:58:20)
    at Command.listener [as _actionHandler] (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:482:17)
    at /Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:1283:65
    at Command._chainOrCall (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:1177:12)
    at Command._parseCommand (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:1283:27)
    at Command.parseAsync (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:935:16)
    at main (file:///Users/sangeethahariharan/vision/index.js:48:17) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '~/Downloads/sunrise.jpeg'
}

Node.js v21.6.2
17:08:21 failed to run tool [vision] cmd [/bin/bash /var/folders/xt/zg5q3qtj07q84xvf0_80pfdh0000gn/T/gptscript2175633379]: exit status 1
2024/02/22 17:08:21 ERROR: (node:99468) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
node:fs:581
  return binding.open(
                 ^

Error: ENOENT: no such file or directory, open '~/Downloads/sunrise.jpeg'
    at Object.openSync (node:fs:581:18)
    at Object.readFileSync (node:fs:460:35)
    at resolveImageURL (file:///Users/sangeethahariharan/vision/index.js:89:23)
    at Command.run (file:///Users/sangeethahariharan/vision/index.js:58:20)
    at Command.listener [as _actionHandler] (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:482:17)
    at /Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:1283:65
    at Command._chainOrCall (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:1177:12)
    at Command._parseCommand (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:1283:27)
    at Command.parseAsync (/Users/sangeethahariharan/vision/node_modules/commander/lib/command.js:935:16)
    at main (file:///Users/sangeethahariharan/vision/index.js:48:17) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '~/Downloads/sunrise.jpeg'
}

Node.js v21.6.2
: exit status 1

Note - Using the file path as /Users/sangeethahariharan/Downloads/sunrise.jpeg works as expected.

sangee2004 commented 7 months ago

The stack trace is slightly different when using vision tool from github repo url:

tools: github.com/gptscript-ai/vision

Describe the picture in file ~/Downloads/sunrise.jpeg for me
gptscript vision.gpt 
17:30:24 started  [main]
17:30:24 sent     [main]
         content  [1] content | Waiting for model response...
         content  [1] content | tool call vision -> {"images":"file ~/Downloads/sunrise.jpeg","prompt":"Describe the picture in detail."}
17:30:27 started  [vision(2)] [input={"images":"file ~/Downloads/sunrise.jpeg","prompt":"Describe the picture in detail."}]
17:30:27 sent     [vision(2)]
node:internal/url:804
    this.#updateContext(bindingUrl.parse(input, base));
                                   ^

TypeError: Invalid URL
    at new URL (node:internal/url:804:36)
    at resolveImageURL (file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:81:15)
    at Command.run (file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:57:20)
    at Command.listener [as _actionHandler] (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:482:17)
    at /Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:1283:65
    at Command._chainOrCall (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:1177:12)
    at Command._parseCommand (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:1283:27)
    at Command.parseAsync (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:935:16)
    at main (file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:47:17)
    at file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:100:1 {
  code: 'ERR_INVALID_URL',
  input: 'file ~/Downloads/sunrise.jpeg'
}

Node.js v21.7.0
17:30:27 failed to run tool [vision] cmd [/usr/bin/env node /Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js Describe the picture in detail. file ~/Downloads/sunrise.jpeg]: exit status 1
2024/03/11 17:30:27 ERROR: node:internal/url:804
    this.#updateContext(bindingUrl.parse(input, base));
                                   ^

TypeError: Invalid URL
    at new URL (node:internal/url:804:36)
    at resolveImageURL (file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:81:15)
    at Command.run (file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:57:20)
    at Command.listener [as _actionHandler] (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:482:17)
    at /Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:1283:65
    at Command._chainOrCall (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:1177:12)
    at Command._parseCommand (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:1283:27)
    at Command.parseAsync (/Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/node_modules/commander/lib/command.js:935:16)
    at main (file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:47:17)
    at file:///Users/sangeethahariharan/Library/Caches/gptscript/repos/46ac5323baf9da743f238a313b5b78608b2d4dbf/node21/index.js:100:1 {
  code: 'ERR_INVALID_URL',
  input: 'file ~/Downloads/sunrise.jpeg'
}

Node.js v21.7.0
: exit status 1