Skip to content

Commit 6421e4e

Browse files
committed
[Examples] Simplify platform-as-tool to use OpenAI gpt-4o
Changed from ElevenLabs speech-to-text example to a simpler OpenAI-only example that mirrors the agent-as-tool pattern: - Main agent uses gpt-4o-mini - Platform tool uses gpt-4o for advanced analysis - Demonstrates using a more powerful model as a tool for complex tasks - Removes external dependency on ElevenLabs API key
1 parent 1fc6641 commit 6421e4e

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

examples/openai/platform-as-tool.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,27 @@
1212
use Symfony\AI\Agent\Agent;
1313
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1414
use Symfony\AI\Agent\Toolbox\Tool\Platform as PlatformTool;
15-
use Symfony\AI\Agent\Toolbox\Toolbox;
1615
use Symfony\AI\Agent\Toolbox\ToolFactory\ChainFactory;
1716
use Symfony\AI\Agent\Toolbox\ToolFactory\MemoryToolFactory;
1817
use Symfony\AI\Agent\Toolbox\ToolFactory\ReflectionToolFactory;
19-
use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory as ElevenLabsPlatformFactory;
18+
use Symfony\AI\Agent\Toolbox\Toolbox;
2019
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
21-
use Symfony\AI\Platform\Message\Content\Audio;
2220
use Symfony\AI\Platform\Message\Message;
2321
use Symfony\AI\Platform\Message\MessageBag;
2422

2523
require_once dirname(__DIR__).'/bootstrap.php';
2624

27-
// Create the main OpenAI platform
28-
$openAiPlatform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
29-
30-
// Create ElevenLabs platform as a tool for speech-to-text
31-
$elevenLabsPlatform = ElevenLabsPlatformFactory::create(
32-
apiKey: env('ELEVEN_LABS_API_KEY'),
33-
httpClient: http_client()
34-
);
25+
$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
3526

36-
// Wrap ElevenLabs platform as a tool
37-
$speechToText = new PlatformTool($elevenLabsPlatform, 'scribe_v1');
27+
// Create a specialized OpenAI platform tool using gpt-4o for complex analysis
28+
$analysisTool = new PlatformTool($platform, 'gpt-4o');
3829

3930
// Use MemoryToolFactory to register the tool with metadata
4031
$memoryFactory = new MemoryToolFactory();
4132
$memoryFactory->addTool(
42-
$speechToText,
43-
'transcribe_audio',
44-
'Transcribes audio files to text using ElevenLabs speech-to-text. Accepts audio file content.',
33+
$analysisTool,
34+
'advanced_analysis',
35+
'Performs deep analysis and complex reasoning tasks using GPT-4o. Use this for tasks requiring sophisticated understanding.',
4536
);
4637

4738
// Combine with ReflectionToolFactory using ChainFactory
@@ -50,20 +41,13 @@
5041
new ReflectionToolFactory(),
5142
]);
5243

53-
// Create toolbox with the platform tool
54-
$toolbox = new Toolbox([$speechToText], toolFactory: $chainFactory, logger: logger());
44+
// Create the main agent with gpt-4o-mini but with gpt-4o available as a tool
45+
$toolbox = new Toolbox([$analysisTool], toolFactory: $chainFactory, logger: logger());
5546
$processor = new AgentProcessor($toolbox);
47+
$agent = new Agent($platform, 'gpt-4o-mini', [$processor], [$processor], logger: logger());
5648

57-
// Create agent with OpenAI platform but with ElevenLabs tool available
58-
$agent = new Agent($openAiPlatform, 'gpt-4o-mini', [$processor], [$processor], logger: logger());
59-
60-
// The agent can now use ElevenLabs for speech-to-text while using OpenAI for reasoning
61-
$audioPath = dirname(__DIR__, 2).'/fixtures/audio.mp3';
62-
$messages = new MessageBag(
63-
Message::ofUser('I have an audio file. Please transcribe it and tell me what it says.'),
64-
Message::ofUser(Audio::fromFile($audioPath)),
65-
);
66-
49+
// Ask a question that could benefit from advanced analysis
50+
$messages = new MessageBag(Message::ofUser('Analyze the philosophical implications of artificial consciousness and whether current AI systems exhibit any form of genuine understanding. Provide a detailed analysis.'));
6751
$result = $agent->call($messages);
6852

6953
echo $result->getContent().\PHP_EOL;

0 commit comments

Comments
 (0)