@@ -128,7 +128,7 @@ print(response)
128
128
129
129
### ` stream_exec(tool) `
130
130
131
- This function streams the execution of a tool and returns the output, error, and process wait function.
131
+ This function streams the execution of a tool and returns the output, error, and process wait function. The streams must be read from.
132
132
133
133
``` python
134
134
from gptscript.command import stream_exec, complex_tool
@@ -151,9 +151,16 @@ the response should be in JSON and match the format:
151
151
""" ,
152
152
)
153
153
154
+ def print_output (out , err ):
155
+ # Error stream has the debug info that is useful to see
156
+ for line in err:
157
+ print (line)
158
+
159
+ for line in out:
160
+ print (line)
161
+
154
162
out, err, wait = stream_exec(tool)
155
- print (out)
156
- print (err)
163
+ print_output(out, err)
157
164
wait()
158
165
```
159
166
@@ -164,9 +171,16 @@ This function streams the execution of a tool from a file and returns the output
164
171
``` python
165
172
from gptscript.command import stream_exec_file
166
173
174
+ def print_output (out , err ):
175
+ # Error stream has the debug info that is useful to see
176
+ for line in err:
177
+ print (line)
178
+
179
+ for line in out:
180
+ print (line)
181
+
167
182
out, err, wait = stream_exec_file(" ./init.gpt" )
168
- print (out)
169
- print (err)
183
+ print_output(out, err)
170
184
wait()
171
185
```
172
186
@@ -179,13 +193,13 @@ from gptscript.tool import FreeForm, Tool
179
193
# Define a simple tool
180
194
simple_tool = FreeForm(
181
195
content = """
182
- What is the capitial of the United States?
196
+ What is the capital of the United States?
183
197
"""
184
198
)
185
199
186
200
# Define a complex tool
187
201
complex_tool = Tool(
188
- tools = " sys.write" ,
202
+ tools = [ " sys.write" ] ,
189
203
json_response = True ,
190
204
cache = False ,
191
205
instructions = """
0 commit comments