@@ -27,6 +27,8 @@ You do not need to explain the steps taken, only provide the result to the given
2727You are referred to as a tool.
2828`
2929
30+ var completionID int64
31+
3032func init () {
3133 if p := os .Getenv ("GPTSCRIPT_INTERNAL_SYSTEM_PROMPT" ); p != "" {
3234 InternalSystemPrompt = p
@@ -142,8 +144,27 @@ func (c *Context) getTool(name string) (types.Tool, error) {
142144 return tool , nil
143145}
144146
145- func (e * Engine ) runCommand (ctx context.Context , tool types.Tool , input string ) (string , error ) {
147+ func (e * Engine ) runCommand (ctx context.Context , tool types.Tool , input string ) (cmdOut string , cmdErr error ) {
148+ id := fmt .Sprint (atomic .AddInt64 (& completionID , 1 ))
149+
150+ defer func () {
151+ e .Progress <- openai.Status {
152+ CompletionID : id ,
153+ Response : map [string ]any {
154+ "output" : cmdOut ,
155+ "err" : cmdErr ,
156+ },
157+ }
158+ }()
159+
146160 if tool .BuiltinFunc != nil {
161+ e .Progress <- openai.Status {
162+ CompletionID : id ,
163+ Request : map [string ]any {
164+ "command" : []string {tool .ID },
165+ "input" : input ,
166+ },
167+ }
147168 return tool .BuiltinFunc (ctx , e .Env , input )
148169 }
149170
@@ -200,6 +221,14 @@ func (e *Engine) runCommand(ctx context.Context, tool types.Tool, input string)
200221 return "" , err
201222 }
202223
224+ e .Progress <- openai.Status {
225+ CompletionID : id ,
226+ Request : map [string ]any {
227+ "command" : args ,
228+ "input" : input ,
229+ },
230+ }
231+
203232 output := & bytes.Buffer {}
204233
205234 cmd := exec .Command (args [0 ], append (args [1 :], f .Name ())... )
0 commit comments