<?php
use Cognesy\Messages\Messages;
use Cognesy\Polyglot\Inference\Data\ToolChoice;
use Cognesy\Polyglot\Inference\Data\ToolDefinitions;
use Cognesy\Polyglot\Inference\Inference;
$tools = [
[
'type' => 'function',
'function' => [
'name' => 'get_weather',
'description' => 'Get the current weather for a location',
'parameters' => [
'type' => 'object',
'properties' => [
'location' => ['type' => 'string'],
],
'required' => ['location'],
],
],
],
[
'type' => 'function',
'function' => [
'name' => 'get_flight_info',
'description' => 'Get information about a flight',
'parameters' => [
'type' => 'object',
'properties' => [
'flight_number' => ['type' => 'string'],
'date' => ['type' => 'string'],
],
'required' => ['flight_number'],
],
],
],
];
$response = Inference::using('openai')
->with(
messages: Messages::fromString('What is the status of flight AA123?'),
tools: ToolDefinitions::fromArray($tools),
toolChoice: ToolChoice::auto(),
)
->response();
// @doctest id="c547"