mirror of
https://github.com/symfony/ai.git
synced 2026-03-23 23:42:18 +01:00
[Agent][Brave] Add symfony/ai-brave-tool
This commit is contained in:
2
.github/build-packages.php
vendored
2
.github/build-packages.php
vendored
@@ -9,7 +9,7 @@ require __DIR__.'/../vendor/autoload.php';
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
$finder = (new Finder())
|
||||
->in([__DIR__.'/../src/*/', __DIR__.'/../examples/', __DIR__.'/../demo/'])
|
||||
->in([__DIR__.'/../src/*/', __DIR__.'/../src/*/src/Bridge/*/', __DIR__.'/../examples/', __DIR__.'/../demo/'])
|
||||
->depth(0)
|
||||
->name('composer.json')
|
||||
;
|
||||
|
||||
2
.github/workflows/code-quality.yaml
vendored
2
.github/workflows/code-quality.yaml
vendored
@@ -32,7 +32,7 @@ jobs:
|
||||
echo COMPOSER_UP='composer update --no-progress --no-interaction --no-scripts --ansi --ignore-platform-req=ext-mongodb' >> $GITHUB_ENV
|
||||
echo PHPSTAN='vendor/bin/phpstan' >> $GITHUB_ENV
|
||||
|
||||
PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | sed 's/^src\///' | grep -Ev "examples" | sort | tr '\n' ' ')
|
||||
PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -not -path "*/Bridge/*" -printf '%h\n' | sed 's/^src\///' | grep -Ev "examples" | sort | tr '\n' ' ')
|
||||
echo "Packages: $PACKAGES"
|
||||
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
|
||||
|
||||
|
||||
14
.github/workflows/integration-tests.yaml
vendored
14
.github/workflows/integration-tests.yaml
vendored
@@ -65,19 +65,19 @@ jobs:
|
||||
- name: Install root dependencies
|
||||
uses: ramsey/composer-install@v3
|
||||
|
||||
- name: Install examples dependencies
|
||||
- name: Build root packages
|
||||
run: php .github/build-packages.php
|
||||
|
||||
- name: Install root dependencies
|
||||
uses: ramsey/composer-install@v3
|
||||
with:
|
||||
working-directory: examples
|
||||
|
||||
- name: Link examples
|
||||
working-directory: examples
|
||||
run: ../link
|
||||
|
||||
- name: Run commands examples
|
||||
working-directory: examples
|
||||
run: |
|
||||
php examples/commands/stores.php
|
||||
php examples/commands/message-stores.php
|
||||
php commands/stores.php
|
||||
php commands/message-stores.php
|
||||
|
||||
demo:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
"symfony/ai-chat": "@dev",
|
||||
"symfony/ai-platform": "@dev",
|
||||
"symfony/ai-store": "@dev",
|
||||
"symfony/ai-brave-tool": "@dev",
|
||||
"symfony/cache": "^7.3|^8.0",
|
||||
"symfony/clock": "^7.3|^8.0",
|
||||
"symfony/console": "^7.3|^8.0",
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
*/
|
||||
|
||||
use Symfony\AI\Agent\Agent;
|
||||
use Symfony\AI\Agent\Bridge\Brave\Brave;
|
||||
use Symfony\AI\Agent\Toolbox\AgentProcessor;
|
||||
use Symfony\AI\Agent\Toolbox\Tool\Brave;
|
||||
use Symfony\AI\Agent\Toolbox\Tool\Clock;
|
||||
use Symfony\AI\Agent\Toolbox\Tool\Scraper;
|
||||
use Symfony\AI\Agent\Toolbox\Toolbox;
|
||||
|
||||
5
link
5
link
@@ -38,7 +38,10 @@ if (!is_dir("$pathToProject/vendor/symfony")) {
|
||||
$sfPackages = array();
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
$directories = glob(__DIR__.'/src/*', GLOB_ONLYDIR | GLOB_NOSORT);
|
||||
$braces = array('*', '*/src/Bridge/*');
|
||||
$directories = array_merge(...array_values(array_map(function ($part) {
|
||||
return glob(__DIR__.'/src/'.$part, GLOB_ONLYDIR | GLOB_NOSORT);
|
||||
}, $braces)));
|
||||
|
||||
foreach ($directories as $dir) {
|
||||
if ($filesystem->exists($composer = "$dir/composer.json")) {
|
||||
|
||||
@@ -6,6 +6,8 @@ parameters:
|
||||
paths:
|
||||
- src/
|
||||
- tests/
|
||||
excludePaths:
|
||||
- src/Bridge/*/vendor/
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Method .*::test.*\\(\\) has no return type specified\\.$#"
|
||||
|
||||
3
src/agent/src/Bridge/Brave/.gitattributes
vendored
Normal file
3
src/agent/src/Bridge/Brave/.gitattributes
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/Tests export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/.git* export-ignore
|
||||
8
src/agent/src/Bridge/Brave/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
8
src/agent/src/Bridge/Brave/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
Please do not submit any Pull Requests here. They will be closed.
|
||||
---
|
||||
|
||||
Please submit your PR here instead:
|
||||
https://github.com/symfony/ai
|
||||
|
||||
This repository is what we call a "subtree split": a read-only subset of that main repository.
|
||||
We're looking forward to your PR there!
|
||||
20
src/agent/src/Bridge/Brave/.github/close-pull-request.yml
vendored
Normal file
20
src/agent/src/Bridge/Brave/.github/close-pull-request.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Close Pull Request
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: superbrothers/close-pull-request@v3
|
||||
with:
|
||||
comment: |
|
||||
Thanks for your Pull Request! We love contributions.
|
||||
|
||||
However, you should instead open your PR on the main repository:
|
||||
https://github.com/symfony/ai
|
||||
|
||||
This repository is what we call a "subtree split": a read-only subset of that main repository.
|
||||
We're looking forward to your PR there!
|
||||
4
src/agent/src/Bridge/Brave/.gitignore
vendored
Normal file
4
src/agent/src/Bridge/Brave/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
.phpunit.result.cache
|
||||
@@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\AI\Agent\Toolbox\Tool;
|
||||
namespace Symfony\AI\Agent\Bridge\Brave;
|
||||
|
||||
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;
|
||||
use Symfony\AI\Agent\Toolbox\Source\HasSourcesInterface;
|
||||
7
src/agent/src/Bridge/Brave/CHANGELOG.md
Normal file
7
src/agent/src/Bridge/Brave/CHANGELOG.md
Normal file
@@ -0,0 +1,7 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
0.1
|
||||
---
|
||||
|
||||
* Add the bridge
|
||||
19
src/agent/src/Bridge/Brave/LICENSE
Normal file
19
src/agent/src/Bridge/Brave/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2025-present Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -9,19 +9,18 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\AI\Agent\Tests\Toolbox\Tool;
|
||||
namespace Symfony\AI\Agent\Bridge\Brave\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\AI\Agent\Toolbox\Tool\Brave;
|
||||
use Symfony\AI\Agent\Bridge\Brave\Brave;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Component\HttpClient\Response\JsonMockResponse;
|
||||
use Symfony\Component\HttpClient\Response\MockResponse;
|
||||
|
||||
final class BraveTest extends TestCase
|
||||
{
|
||||
public function testReturnsSearchResults()
|
||||
{
|
||||
$result = JsonMockResponse::fromFile(__DIR__.'/../../fixtures/Tool/brave.json');
|
||||
$result = JsonMockResponse::fromFile(__DIR__.'/fixtures/search-results.json');
|
||||
$httpClient = new MockHttpClient($result);
|
||||
$brave = new Brave($httpClient, 'test-api-key');
|
||||
|
||||
@@ -38,7 +37,7 @@ final class BraveTest extends TestCase
|
||||
|
||||
public function testPassesCorrectParametersToApi()
|
||||
{
|
||||
$result = JsonMockResponse::fromFile(__DIR__.'/../../fixtures/Tool/brave.json');
|
||||
$result = JsonMockResponse::fromFile(__DIR__.'/fixtures/search-results.json');
|
||||
$httpClient = new MockHttpClient($result);
|
||||
$brave = new Brave($httpClient, 'test-api-key', ['extra' => 'option']);
|
||||
|
||||
@@ -52,13 +51,13 @@ final class BraveTest extends TestCase
|
||||
|
||||
$requestOptions = $result->getRequestOptions();
|
||||
$this->assertArrayHasKey('headers', $requestOptions);
|
||||
$this->assertIsArray($requestOptions['headers']);
|
||||
$this->assertContains('X-Subscription-Token: test-api-key', $requestOptions['headers']);
|
||||
}
|
||||
|
||||
public function testHandlesEmptyResults()
|
||||
{
|
||||
$result = new MockResponse(json_encode(['web' => ['results' => []]]));
|
||||
$httpClient = new MockHttpClient($result);
|
||||
$httpClient = new MockHttpClient(new JsonMockResponse(['web' => ['results' => []]]));
|
||||
$brave = new Brave($httpClient, 'test-api-key');
|
||||
|
||||
$results = $brave('this should return nothing');
|
||||
45
src/agent/src/Bridge/Brave/composer.json
Normal file
45
src/agent/src/Bridge/Brave/composer.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "symfony/ai-brave-tool",
|
||||
"description": "Brave Search AI tool bridge for Symfony applications.",
|
||||
"license": "MIT",
|
||||
"type": "library",
|
||||
"keywords": ["ai", "bridge", "brave", "agent", "tool"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Christopher Hertel",
|
||||
"email": "mail@christopher-hertel.de"
|
||||
},
|
||||
{
|
||||
"name": "Oskar Stark",
|
||||
"email": "oskarstark@googlemail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"symfony/ai-agent": "@dev",
|
||||
"symfony/http-client": "^7.3|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^11.5.13"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\AI\\Agent\\Bridge\\Brave\\": ""
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Symfony\\AI\\Agent\\Bridge\\Brave\\Tests\\": "Tests/"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/ai",
|
||||
"url": "https://github.com/symfony/ai"
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
32
src/agent/src/Bridge/Brave/phpunit.xml.dist
Normal file
32
src/agent/src/Bridge/Brave/phpunit.xml.dist
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnDeprecation="true"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Symfony Brave AI Tool Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<source ignoreSuppressionOfDeprecations="true">
|
||||
<include>
|
||||
<directory>./</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</source>
|
||||
</phpunit>
|
||||
Reference in New Issue
Block a user