gptscript
gptscript copied to clipboard
standardize on env vars for py libs
details to come. just clearing out todos from notes
Not sure if this is related to your intention for this issue, but here's a case that's frustrating when working with arguments and inline python:
Consider this example:
Name: Text inline python args
Args: foo: an argument
#!python3
print(os.environ['foo'])
I would expect I can call it this way but it fails because the arguments are not populated in the environment. However, this same script would work if it were call as a tool from another gptscript:
gptscript testpy.gpt --foo bar
15:57:28 started [main] [input=--foo bar]
15:57:28 sent [main]
Traceback (most recent call last):
File "/tmp/gptscript1115266740", line 1, in <module>
print(os.environ['foo'])
^^
NameError: name 'os' is not defined. Did you forget to import 'os'?
15:57:28 failed to run tool [text inline python args] cmd [/usr/local/bin/python3 /tmp/gptscript1115266740]: exit status 1
2024/03/28 15:57:28 ERROR: Traceback (most recent call last):
File "/tmp/gptscript1115266740", line 1, in <module>
print(os.environ['foo'])
^^
NameError: name 'os' is not defined. Did you forget to import 'os'?
: exit status 1
Calling the same script works all the time this way:
$ foo=bar gptscript testpy.gpt
16:01:39 started [main]
16:01:39 sent [main]
16:01:39 ended [main]
OUTPUT:
bar