Decouple Platform Token Usage handling from Agent by introducing new interface

This commit is contained in:
Christopher Hertel
2025-12-12 18:10:54 +01:00
parent ba7a32c23b
commit fe02dae3f6
2 changed files with 12 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ use Symfony\AI\Platform\Result\TextResult;
use Symfony\AI\Platform\Result\ToolCall;
use Symfony\AI\Platform\Result\ToolCallResult;
use Symfony\AI\Platform\ResultConverterInterface;
use Symfony\AI\Platform\TokenUsage\TokenUsageExtractorInterface;
/**
* This default implementation is based on the OpenAI GPT completion API.
@@ -82,6 +83,11 @@ class ResultConverter implements ResultConverterInterface
return 1 === \count($choices) ? $choices[0] : new ChoiceResult(...$choices);
}
public function getTokenUsageExtractor(): ?TokenUsageExtractorInterface
{
return null;
}
private function convertStream(RawResultInterface|RawHttpResult $result): \Generator
{
$toolCalls = [];

View File

@@ -20,6 +20,7 @@ use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\Result\RawResultInterface;
use Symfony\AI\Platform\Result\VectorResult;
use Symfony\AI\Platform\ResultConverterInterface;
use Symfony\AI\Platform\TokenUsage\TokenUsageExtractorInterface;
use Symfony\AI\Platform\Vector\Vector;
/**
@@ -66,4 +67,9 @@ class ResultConverter implements ResultConverterInterface
),
);
}
public function getTokenUsageExtractor(): ?TokenUsageExtractorInterface
{
return null;
}
}