Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ai-bundle/src/Profiler/DataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ private function awaitCallResults(TraceablePlatform $platform): array
if (isset($platform->resultCache[$result])) {
$call['result'] = $platform->resultCache[$result];
} else {
$call['result'] = $result->getContent();
$content = $result->getContent();
$call['result'] = $content instanceof \Generator ? null : $content;
}

$call['metadata'] = $result->getMetadata();
Expand Down
24 changes: 24 additions & 0 deletions src/ai-bundle/tests/Profiler/DataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ public function testCollectsDataForStreamingResponse()
$this->assertSame('Assistant response', $dataCollector->getPlatformCalls()[0]['result']);
}

public function testCollectsDataForUnconsumedStreamingResponse()
{
$platform = $this->createMock(PlatformInterface::class);
$traceablePlatform = new TraceablePlatform($platform);
$messageBag = new MessageBag(Message::ofUser(new Text('Hello')));
$result = new StreamResult(
(function () {
yield 'Assistant ';
yield 'response';
})(),
);

$platform->method('invoke')->willReturn(new DeferredResult(new PlainConverter($result), $this->createStub(RawResultInterface::class)));

// Invoke but do NOT consume the stream
$traceablePlatform->invoke('gpt-4o', $messageBag, ['stream' => true]);

$dataCollector = new DataCollector([$traceablePlatform], [], [], []);
$dataCollector->lateCollect();

$this->assertCount(1, $dataCollector->getPlatformCalls());
$this->assertNull($dataCollector->getPlatformCalls()[0]['result']);
}

public function testCollectsDataForMessageStore()
{
$traceableMessageStore = new TraceableMessageStore(new InMemoryStore(), new MonotonicClock());
Expand Down
Loading