Skip to content

Commit 7ceb9bc

Browse files
committed
🐛 fix: Fix missing log entries in OpenAIAssistant.php
- Add a new variable `$log_entry` to store log entries. - Append each method call and its arguments to `$log_entry`. - Call the `write_log()` method with `$log_entry` as an argument to write the log entries to a file. - Add a new private method `write_log()` to handle writing log entries to a file. - Update the `submit_tool_outputs()` method to write the `$outputs` array to the log file. - These changes ensure that all tool calls and their outputs are properly logged.
1 parent 5671476 commit 7ceb9bc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/OpenAIAssistant.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public function execute_tools(
201201
$run = $this->get_run($thread_id, $execution_id);
202202
$calls = $run['required_action']['submit_tool_outputs']['tool_calls'];
203203
$outputs = array();
204+
$log_entry = '';
204205

205206
foreach ($calls as $call) {
206207
$method_name = $call['function']['name'];
@@ -217,10 +218,12 @@ public function execute_tools(
217218
'tool_call_id' => $call['id'],
218219
'output' => json_encode($data)
219220
));
221+
$log_entry .= "$method_name -> " . print_r($method_args, true);
220222
} else {
221223
throw new \Exception("Failed to execute tool: The $method_name you provided is not callable");
222224
}
223225
}
226+
$this->write_log($log_entry);
224227
$this->has_tool_calls = false;
225228
return $outputs;
226229
}
@@ -231,6 +234,7 @@ public function submit_tool_outputs($thread_id, $execution_id, $outputs)
231234
"/threads/{$thread_id}/runs/{$execution_id}/submit_tool_outputs",
232235
array('tool_outputs' => $outputs)
233236
);
237+
$this->write_log("outputs -> " . print_r($outputs, true));
234238

235239
if (empty($response['id'])) {
236240
throw new \Exception('Unable to submit tool outputs');
@@ -340,4 +344,17 @@ private function list_runs($thread_id)
340344
}
341345
return $response['data'];
342346
}
347+
348+
private function write_log($message)
349+
{
350+
$logFile = __DIR__ . '/tool_calls_log';
351+
$logEntry = date('Y-m-d H:i:s') . ' - ' . $message . PHP_EOL;
352+
353+
if ($fileHandle = fopen($logFile, 'a')) {
354+
fwrite($fileHandle, $logEntry);
355+
fclose($fileHandle);
356+
return true;
357+
}
358+
return false;
359+
}
343360
}

0 commit comments

Comments
 (0)