Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/agent/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
},
"require-dev": {
"mrmysql/youtube-transcript": "^0.0.5",
"nyholm/psr7": "^1.8",
"php-http/discovery": "^1.19",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^11.5.13",
Expand Down
35 changes: 35 additions & 0 deletions src/agent/tests/Fixtures/Tool/youtube-captions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"playabilityStatus": {
"status": "OK"
},
"captions": {
"playerCaptionsTracklistRenderer": {
"captionTracks": [
{
"baseUrl": "https://www.youtube.com/api/timedtext?v=dQw4w9WgXcQ",
"name": {
"runs": [
{
"text": "English"
}
]
},
"languageCode": "en",
"isTranslatable": true
}
],
"translationLanguages": [
{
"languageName": {
"runs": [
{
"text": "Spanish"
}
]
},
"languageCode": "es"
}
]
}
}
}
6 changes: 6 additions & 0 deletions src/agent/tests/Fixtures/Tool/youtube-transcript.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<transcript>
<text start="0.0" dur="2.5">Hello and welcome to this video</text>
<text start="2.5" dur="3.0">Today we will learn about PHP</text>
<text start="5.5" dur="2.0">Thank you for watching</text>
</transcript>
10 changes: 10 additions & 0 deletions src/agent/tests/Fixtures/Tool/youtube-video-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<script>
var ytcfg = {"INNERTUBE_API_KEY": "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"};
</script>
</head>
<body>
</body>
</html>
37 changes: 37 additions & 0 deletions src/agent/tests/Toolbox/Tool/YouTubeTranscriberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\Agent\Tests\Toolbox\Tool;

use PHPUnit\Framework\TestCase;
use Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;

final class YouTubeTranscriberTest extends TestCase
{
public function testInvoke()
{
$httpClient = new MockHttpClient([
MockResponse::fromFile(__DIR__.'/../../Fixtures/Tool/youtube-video-page.html'),
MockResponse::fromFile(__DIR__.'/../../Fixtures/Tool/youtube-captions.json'),
MockResponse::fromFile(__DIR__.'/../../Fixtures/Tool/youtube-transcript.xml'),
]);

$transcriber = new YouTubeTranscriber($httpClient);

$result = $transcriber('dQw4w9WgXcQ');

$this->assertStringContainsString('Hello and welcome to this video', $result);
$this->assertStringContainsString('Today we will learn about PHP', $result);
$this->assertStringContainsString('Thank you for watching', $result);
}
}
Loading