Skip to content
Snippets Groups Projects

Applied provided patch for testing purposes. #3517618

Open Paul Smith requested to merge issue/ai-3517618:3517618-abstract-token-usage into 1.1.x
3 unresolved threads
@@ -30,6 +30,31 @@ class ChatOutput implements OutputInterface {
*/
private mixed $metadata;
/**
* The amount of input tokens from the AI provider.
*/
private ?int $inputTokensUsage = NULL;
/**
* The amount of output tokens from the AI provider.
*/
private ?int $outputTokensUsage = NULL;
/**
* The amount of total tokens from the AI provider.
*/
private ?int $totalTokensUsage = NULL;
/**
* The amount of reasoning tokens from the AI provider.
*/
private ?int $reasoningTokensUsage = NULL;
/**
* The amount of cached tokens from the AI provider.
*/
private ?int $cachedTokensUsage = NULL;
/**
* The constructor.
*
@@ -76,6 +101,106 @@ class ChatOutput implements OutputInterface {
return $this->metadata;
}
/**
* Set the total tokens used by the AI provider.
*
* @param int $tokens
* The amount of tokens.
*/
public function setTotalTokenUsage(int $tokens): void {
$this->totalTokensUsage = $tokens;
}
/**
* Set the input tokens used by the AI provider.
*
* @param int $tokens
* The amount of tokens.
*/
public function setInputTokenUsage(int $tokens): void {
$this->inputTokensUsage = $tokens;
}
/**
* Set the output tokens used by the AI provider.
*
* @param int $tokens
* The amount of tokens.
*/
public function setOutputTokenUsage(int $tokens): void {
$this->outputTokensUsage = $tokens;
}
/**
* Set the reasoning tokens used by the AI provider.
*
* @param int $tokens
* The amount of tokens.
*/
public function setReasoningTokenUsage(int $tokens): void {
$this->reasoningTokensUsage = $tokens;
}
/**
* Set the cached tokens used by the AI provider.
*
* @param int $tokens
* The amount of tokens.
*/
public function setCachedTokenUsage(int $tokens): void {
$this->cachedTokensUsage = $tokens;
}
/**
* Gets the total tokens used by the AI provider.
*
* @return int|null
* The total token usage.
*/
public function getTotalTokenUsage(): ?int {
return $this->totalTokensUsage;
}
/**
* Gets the input tokens used by the AI provider.
*
* @return int|null
* The input token usage.
*/
public function getInputTokenUsage(): ?int {
return $this->inputTokensUsage;
}
/**
* Gets the output tokens used by the AI provider.
*
* @return int|null
* The output token usage.
*/
public function getOutputTokenUsage(): ?int {
return $this->outputTokensUsage;
}
/**
* Gets the reasoning tokens used by the AI provider.
*
* @return int|null
* The reasoning token usage.
*/
public function getReasoningTokenUsage(): ?int {
return $this->reasoningTokensUsage;
}
/**
* Gets the cached tokens used by the AI provider.
*
* @return int|null
* The cached token usage.
*/
public function getCachedTokenUsage(): ?int {
return $this->cachedTokensUsage;
}
/**
* {@inheritdoc}
*/
@@ -84,6 +209,13 @@ class ChatOutput implements OutputInterface {
'normalized' => $this->normalized,
'rawOutput' => $this->rawOutput,
'metadata' => $this->metadata,
'tokenUsage' => [
'input' => $this->inputTokensUsage,
'output' => $this->outputTokensUsage,
'total' => $this->totalTokensUsage,
'reasoning' => $this->reasoningTokensUsage,
'cached' => $this->cachedTokensUsage,
],
];
}
Loading