forked from ezimuel/php-llm-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllphant_tool.php
More file actions
41 lines (32 loc) · 966 Bytes
/
Copy pathllphant_tool.php
File metadata and controls
41 lines (32 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Function calling example with LLPhant
*/
use LLPhant\Chat\FunctionInfo\FunctionInfo;
use LLPhant\Chat\FunctionInfo\Parameter;
use LLPhant\Chat\OpenAIChat;
use LLPhant\OpenAIConfig;
require dirname(__DIR__) . '/vendor/autoload.php';
$config = new OpenAIConfig();
$config->model = 'gpt-3.5-turbo';
$chat = new OpenAIChat($config);
class WeatherStation
{
public function get_temperature(string $city): float
{
return 20.5;
}
}
$city = new Parameter('city', 'string', 'the name of the city');
$tool = new FunctionInfo(
'get_temperature',
new WeatherStation(),
'Get the current temperature for a city',
[$city],
$requiredParameters = [$city]
);
$chat->addTool($tool);
$chat->setSystemMessage('You are a weather bot. Use the provided functions to answer questions.');
$answer = $chat->generateText('What is the temperature now in Turin?');
printf("Answer: %s\n", $answer);
var_dump($chat->getLastResponse());