mirror of
https://github.com/symfony/ai.git
synced 2026-03-23 23:42:18 +01:00
c56401728830e56179fb794827b5db9bb0499d63
This PR was merged into the main branch.
Discussion
----------
[Platform][Mistral] Add token usage extraction for embeddings
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| Docs? | no
| Issues | -
| License | MIT
## Description
This PR adds token usage extraction support for Mistral embeddings — the first embedding bridge to support this.
### Changes
1. **`Mistral\Embeddings\TokenUsageExtractor`** — New class implementing `TokenUsageExtractorInterface`. Extracts `prompt_tokens`, `total_tokens`, and rate limit headers (`x-ratelimit-limit-tokens-minute`, `x-ratelimit-limit-tokens-month`) from Mistral embedding responses. No `completionTokens` since embeddings don't produce completions.
2. **`Mistral\Embeddings\ResultConverter`** — `getTokenUsageExtractor()` now returns the new extractor instead of `null`.
3. **Updated Mistral embeddings example** to display token usage.
### Usage
```php
$result = $platform->invoke('mistral-embed', 'Some text to embed');
$tokenUsage = $result->getMetadata()->get('token_usage');
$tokenUsage->getPromptTokens(); // e.g. 15
$tokenUsage->getTotalTokens(); // e.g. 15
```
Commits
-------
81caade2 [Platform][Mistral] Add token usage extraction for embeddings
Symfony AI is a set of components that integrate AI capabilities into PHP applications.
Components & Bundles
Symfony AI consists of several lower and higher level components and the respective integration bundles:
- Components
- Agent: Framework for building AI agents that can interact with users and perform tasks.
- Chat: A unified interface to send messages to agents and store long-term context.
- Mate: MCP development server enabling AI assistants to interact with PHP applications through standardized tools.
- Platform: A unified interface to various AI platforms like OpenAI, Anthropic, Azure, Gemini, VertexAI, and more.
- Store: Data storage abstraction with indexing and retrieval for AI applications.
- Bundles
- AI Bundle: Symfony integration for AI Platform, Store and Agent components.
- MCP Bundle: Symfony integration for official MCP SDK, allowing them to act as MCP servers or clients.
Examples & Demo
To get started with Symfony AI, you can either check out the examples to see how to use the components in smaller snippets, or you can run the demo application to see the components work together in a full Symfony web application.
Resources
Sponsor
Help Symfony by sponsoring its development!
Contributing
Thank you for considering contributing to Symfony AI! You can find the contribution guide here.
Languages
PHP
97.4%
Twig
1.9%
CSS
0.4%
JavaScript
0.3%