-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3513643
commit 33e61af
Showing
8 changed files
with
99 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use PhpLlm\LlmChain\Chain; | ||
use PhpLlm\LlmChain\Message\Message; | ||
use PhpLlm\LlmChain\Message\MessageBag; | ||
use PhpLlm\LlmChain\OpenAI\Model\Gpt; | ||
use PhpLlm\LlmChain\OpenAI\Model\Gpt\Version; | ||
use PhpLlm\LlmChain\OpenAI\Runtime\OpenAI; | ||
use PhpLlm\LlmChain\ToolBox\ParameterAnalyzer; | ||
use PhpLlm\LlmChain\ToolBox\Registry; | ||
use PhpLlm\LlmChain\ToolBox\Tool\OpenMeteo; | ||
use PhpLlm\LlmChain\ToolBox\ToolAnalyzer; | ||
use Symfony\Component\HttpClient\HttpClient; | ||
|
||
require_once dirname(__DIR__).'/vendor/autoload.php'; | ||
|
||
$httpClient = HttpClient::create(); | ||
$runtime = new OpenAI($httpClient, getenv('OPENAI_API_KEY')); | ||
$llm = new Gpt($runtime, Version::GPT_4o_MINI); | ||
|
||
$wikipedia = new OpenMeteo($httpClient); | ||
$registry = new Registry(new ToolAnalyzer(new ParameterAnalyzer()), [$wikipedia]); | ||
$chain = new Chain($llm, $registry); | ||
|
||
$messages = new MessageBag(Message::ofUser('How is the weather currently in Berlin?')); | ||
$response = $chain->call($messages); | ||
|
||
echo $response.PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpLlm\LlmChain\ToolBox\Tool; | ||
|
||
use PhpLlm\LlmChain\ToolBox\AsTool; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
#[AsTool(name: 'weather', description: 'get the current weather for a location')] | ||
final readonly class OpenMeteo | ||
{ | ||
public function __construct( | ||
private HttpClientInterface $httpClient, | ||
) { | ||
} | ||
|
||
/** | ||
* @param float $latitude the latitude of the location | ||
* @param float $longitude the longitude of the location | ||
*/ | ||
public function __invoke(float $latitude, float $longitude): string | ||
{ | ||
$response = $this->httpClient->request('GET', 'https://api.open-meteo.com/v1/forecast', [ | ||
'query' => [ | ||
'latitude' => $latitude, | ||
'longitude' => $longitude, | ||
'current' => 'temperature_2m,wind_speed_10m', | ||
], | ||
]); | ||
|
||
return $response->getContent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters