Skip to content

Commit c85a4bc

Browse files
committed
feature #537 [AiBundle] Add Perplexity platform configuration support (matyo91)
This PR was squashed before being merged into the main branch. Discussion ---------- [AiBundle] Add Perplexity platform configuration support | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | yes <!-- required for new features --> | Issues | Fix #534 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Commits ------- 1b18452 [AiBundle] Add Perplexity platform configuration support
2 parents afd238c + 1b18452 commit c85a4bc

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

src/ai-bundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add Symfony bundle for integrating Platform, Agent, and Store components
8+
* Add Perplexity platform support with API key configuration
89
* Add service configuration:
910
- Agent services with configurable platforms and system prompts
1011
- Tool registration via `#[AsTool]` attribute and `ai.tool` tag

src/ai-bundle/config/options.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@
101101
->scalarNode('api_key')->isRequired()->end()
102102
->end()
103103
->end()
104+
->arrayNode('perplexity')
105+
->children()
106+
->scalarNode('api_key')->isRequired()->end()
107+
->end()
108+
->end()
104109
->end()
105110
->end()
106111
->arrayNode('agent')

src/ai-bundle/doc/index.rst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Configuration
3434
class: 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'
3535
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Gpt::GPT_4O_MINI
3636
37-
**Advanced Example with Anthropic, Azure, ElevenLabs, Gemini, Vertex AI, Ollama multiple agents**
37+
**Advanced Example with Anthropic, Azure, ElevenLabs, Gemini, Perplexity, Vertex AI, Ollama multiple agents**
3838

3939
.. code-block:: yaml
4040
@@ -56,6 +56,8 @@ Configuration
5656
output_path: '%env(ELEVEN_LABS_OUTPUT_PATH)%'
5757
gemini:
5858
api_key: '%env(GEMINI_API_KEY)%'
59+
perplexity:
60+
api_key: '%env(PERPLEXITY_API_KEY)%'
5961
vertexai:
6062
location: '%env(GOOGLE_CLOUD_LOCATION)%'
6163
project_id: '%env(GOOGLE_CLOUD_PROJECT)%'
@@ -93,6 +95,12 @@ Configuration
9395
tools: # If undefined, all tools are injected into the agent, use "tools: false" to disable tools.
9496
- 'Symfony\AI\Agent\Toolbox\Tool\Wikipedia'
9597
fault_tolerant_toolbox: false # Disables fault tolerant toolbox, default is true
98+
search_agent:
99+
platform: 'ai.platform.perplexity'
100+
model:
101+
class: 'Symfony\AI\Platform\Bridge\Perplexity\Perplexity'
102+
name: !php/const Symfony\AI\Platform\Bridge\Perplexity\Perplexity::SONAR
103+
tools: false
96104
audio:
97105
platform: 'ai.platform.eleven_labs'
98106
model:
@@ -131,7 +139,7 @@ Configuration
131139
default:
132140
vectorizer: 'ai.vectorizer.openai_embeddings'
133141
store: 'ai.store.chroma_db.default'
134-
142+
135143
research:
136144
vectorizer: 'ai.vectorizer.mistral_embeddings'
137145
store: 'ai.store.memory.research'
@@ -355,13 +363,13 @@ Vectorizers are defined in the ``vectorizer`` section of your configuration:
355363
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Embeddings::TEXT_EMBEDDING_3_SMALL
356364
options:
357365
dimensions: 512
358-
366+
359367
openai_large:
360368
platform: 'ai.platform.openai'
361369
model:
362370
class: 'Symfony\AI\Platform\Bridge\OpenAi\Embeddings'
363371
name: !php/const Symfony\AI\Platform\Bridge\OpenAi\Embeddings::TEXT_EMBEDDING_3_LARGE
364-
372+
365373
mistral_embed:
366374
platform: 'ai.platform.mistral'
367375
model:
@@ -379,19 +387,19 @@ Once configured, vectorizers can be referenced by name in indexer configurations
379387
documents:
380388
vectorizer: 'ai.vectorizer.openai_small'
381389
store: 'ai.store.chroma_db.documents'
382-
390+
383391
research:
384392
vectorizer: 'ai.vectorizer.openai_large'
385393
store: 'ai.store.chroma_db.research'
386-
394+
387395
knowledge_base:
388396
vectorizer: 'ai.vectorizer.mistral_embed'
389397
store: 'ai.store.memory.kb'
390398
391399
**Benefits of Configured Vectorizers**
392400

393401
* **Reusability**: Define once, use in multiple indexers
394-
* **Consistency**: Ensure all indexers using the same vectorizer have identical embedding configuration
402+
* **Consistency**: Ensure all indexers using the same vectorizer have identical embedding configuration
395403
* **Maintainability**: Change vectorizer settings in one place
396404

397405
Profiler

src/ai-bundle/src/AiBundle.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory as OllamaPlatformFactory;
4141
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory as OpenAiPlatformFactory;
4242
use Symfony\AI\Platform\Bridge\OpenRouter\PlatformFactory as OpenRouterPlatformFactory;
43+
use Symfony\AI\Platform\Bridge\Perplexity\PlatformFactory as PerplexityPlatformFactory;
4344
use Symfony\AI\Platform\Bridge\VertexAi\PlatformFactory as VertexAiPlatformFactory;
4445
use Symfony\AI\Platform\Bridge\Voyage\PlatformFactory as VoyagePlatformFactory;
4546
use Symfony\AI\Platform\Exception\RuntimeException;
@@ -419,7 +420,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
419420
return;
420421
}
421422

422-
if ('cerebras' === $type && isset($platform['api_key'])) {
423+
if ('cerebras' === $type) {
423424
$platformId = 'ai.platform.cerebras';
424425
$definition = (new Definition(Platform::class))
425426
->setFactory(CerebrasPlatformFactory::class.'::create')
@@ -436,7 +437,7 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
436437
return;
437438
}
438439

439-
if ('voyage' === $type && isset($platform['api_key'])) {
440+
if ('voyage' === $type) {
440441
$platformId = 'ai.platform.voyage';
441442
$definition = (new Definition(Platform::class))
442443
->setFactory(VoyagePlatformFactory::class.'::create')
@@ -453,6 +454,24 @@ private function processPlatformConfig(string $type, array $platform, ContainerB
453454
return;
454455
}
455456

457+
if ('perplexity' === $type) {
458+
$platformId = 'ai.platform.perplexity';
459+
$definition = (new Definition(Platform::class))
460+
->setFactory(PerplexityPlatformFactory::class.'::create')
461+
->setLazy(true)
462+
->addTag('proxy', ['interface' => PlatformInterface::class])
463+
->setArguments([
464+
$platform['api_key'],
465+
new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE),
466+
new Reference('ai.platform.contract.perplexity'),
467+
])
468+
->addTag('ai.platform');
469+
470+
$container->setDefinition($platformId, $definition);
471+
472+
return;
473+
}
474+
456475
throw new InvalidArgumentException(\sprintf('Platform "%s" is not supported for configuration via bundle at this point.', $type));
457476
}
458477

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,31 @@ public function testOpenAiPlatformWithInvalidRegion()
623623
]);
624624
}
625625

626+
public function testPerplexityPlatformConfiguration()
627+
{
628+
$container = $this->buildContainer([
629+
'ai' => [
630+
'platform' => [
631+
'perplexity' => [
632+
'api_key' => 'pplx-test-key',
633+
],
634+
],
635+
],
636+
]);
637+
638+
$this->assertTrue($container->hasDefinition('ai.platform.perplexity'));
639+
640+
$definition = $container->getDefinition('ai.platform.perplexity');
641+
$arguments = $definition->getArguments();
642+
643+
$this->assertCount(3, $arguments);
644+
$this->assertSame('pplx-test-key', $arguments[0]);
645+
$this->assertInstanceOf(Reference::class, $arguments[1]);
646+
$this->assertSame('http_client', (string) $arguments[1]);
647+
$this->assertInstanceOf(Reference::class, $arguments[2]);
648+
$this->assertSame('ai.platform.contract.perplexity', (string) $arguments[2]);
649+
}
650+
626651
public function testVectorizerConfiguration()
627652
{
628653
$container = $this->buildContainer([

0 commit comments

Comments
 (0)