<?php

use boru\ai\AI;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/example_helpers.php';
require __DIR__ . '/StreamHandlerIncludes.php';
require __DIR__ . '/WeatherTemperatureTool.php';

$parsedArgs = exampleParseArgs($argv);
if (exampleHasFlag($parsedArgs, 'help')) {
    examplePrintUsageAndExit(
        'examples/weatherbot_class_tool.php',
        'Run a weatherbot example using a class-based tool implementation.',
        '[--provider=openai|gemini] [--model=MODEL]',
        0
    );
}

exampleBootstrap();

$ai = exampleCreateAi($parsedArgs, 'openai', 'weatherbot_class_tool_example')
    ->setToolContextValue('temp', 69)
    ->addTool(new WeatherTemperatureTool())
    ->addMessage('What\'s the weather in Atlanta right now in Fahrenheit? Also, please generate a random sentence about the weather that is returned. Thanks!');

list($outputBuffer, $completionStatus, $functionCalls) = attachStreamHandlersToAi($ai);
$response = $ai->run();

echo PHP_EOL;
echo '---' . PHP_EOL;
echo 'Buffered text length: ' . strlen($outputBuffer->buffer()) . PHP_EOL;
echo 'Turn completion status: ' . ($completionStatus->status() ? $completionStatus->status() : 'unknown') . PHP_EOL;
echo 'Observed tool calls: ' . count($functionCalls->calls()) . PHP_EOL;
echo rtrim($response->text()) . PHP_EOL;
