更新
This commit is contained in:
@@ -10,7 +10,7 @@ final class DifyStreamTiming
|
||||
'message', 'agent_message', 'agent_thought', 'message_end', 'error', 'ping', 'choices'];
|
||||
private const TYPES = ['start', 'llm', 'knowledge-retrieval', 'tool', 'code', 'template-transform',
|
||||
'if-else', 'answer', 'end', 'agent', 'http-request', 'iteration', 'question-classifier',
|
||||
'variable-aggregator', 'parameter-extractor'];
|
||||
'variable-aggregator', 'parameter-extractor', 'list-operator', 'document-extractor'];
|
||||
private \Closure $clock;
|
||||
private float $started;
|
||||
private array $metrics = [];
|
||||
@@ -77,6 +77,9 @@ final class DifyStreamTiming
|
||||
if (is_numeric($elapsed) && is_finite((float) $elapsed) && (float) $elapsed >= 0) {
|
||||
$this->nodes[$position]['provider_elapsed_ms'] = (int) min(3600000, (float) $elapsed * 1000);
|
||||
}
|
||||
if ($this->nodes[$position]['type'] === 'llm' && $name === 'node_finished') {
|
||||
$this->imageCounts($position, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
$usage = $name === 'message_end' ? ($decoded['metadata']['usage'] ?? []) : ($decoded['usage'] ?? []);
|
||||
@@ -90,6 +93,30 @@ final class DifyStreamTiming
|
||||
|
||||
public function delivered(): void { $this->metrics['first_delivered_ms'] ??= $this->elapsed(); }
|
||||
|
||||
/** Count the actual LLM image parts when the provider exposes them, never their contents. */
|
||||
private function imageCounts(int $position, array $data): void
|
||||
{
|
||||
$files = $data['inputs']['#files#'] ?? null;
|
||||
if (is_array($files) && count($files) <= 1000) {
|
||||
$this->nodes[$position]['input_image_count'] = count(array_filter($files,
|
||||
static fn ($file): bool => is_array($file) && ($file['type'] ?? '') === 'image'));
|
||||
}
|
||||
$prompts = $data['process_data']['prompts'] ?? null;
|
||||
if (!is_array($prompts) || count($prompts) > 512) return;
|
||||
$parts = 0;
|
||||
$high = 0;
|
||||
foreach ($prompts as $prompt) {
|
||||
if (!is_array($prompt) || !is_array($prompt['files'] ?? null) || count($prompt['files']) > 1000) return;
|
||||
foreach ($prompt['files'] as $file) {
|
||||
if (!is_array($file) || ($file['type'] ?? '') !== 'image') continue;
|
||||
++$parts;
|
||||
if (($file['detail'] ?? '') === 'high') ++$high;
|
||||
}
|
||||
}
|
||||
$this->nodes[$position]['model_image_part_count'] = $parts;
|
||||
$this->nodes[$position]['model_high_detail_image_part_count'] = $high;
|
||||
}
|
||||
|
||||
public function transport(array $values): void
|
||||
{
|
||||
foreach (['connect_ms', 'tls_ms', 'header_ttfb_ms', 'transfer_ms', 'http_status', 'curl_errno'] as $key) {
|
||||
|
||||
Reference in New Issue
Block a user