Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/platform/src/Bridge/Gemini/Gemini/ResultConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,20 @@ private function convertChoice(array $choice): ToolCallResult|TextResult|BinaryR
}
}

// Fallback for multi-part text responses (e.g., thinking + response)
if ('' === $content) {
foreach ($contentParts as $contentPart) {
if (isset($contentPart['text'])) {
$content .= $contentPart['text'];
}
}
}

if ('' !== $content) {
return new TextResult($content);
}

throw new RuntimeException('Code execution failed.');
throw new RuntimeException('Response does not contain any text content.');
}

/**
Expand Down
33 changes: 33 additions & 0 deletions src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Result\BinaryResult;
use Symfony\AI\Platform\Result\RawHttpResult;
use Symfony\AI\Platform\Result\TextResult;
use Symfony\AI\Platform\Result\ToolCall;
use Symfony\AI\Platform\Result\ToolCallResult;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand Down Expand Up @@ -132,4 +133,36 @@ public function testConvertsInlineDataWithoutMimeTypeToBinaryResult()
$this->assertSame('base64EncodedData', $result->getContent());
$this->assertNull($result->getMimeType());
}

public function testConvertsMultiPartThinkingResponseToTextResult()
{
$converter = new ResultConverter();
$httpResponse = self::createMock(ResponseInterface::class);
$httpResponse->method('getStatusCode')->willReturn(200);
$httpResponse->method('toArray')->willReturn([
'candidates' => [
[
'content' => [
'parts' => [
[
'text' => '<analysis>This is the thinking process...</analysis>',
'thoughtSignature' => 'base64-encoded-signature...',
],
[
'text' => '```json\n{"result": "actual response"}\n```',
],
],
],
'finishReason' => 'STOP',
],
],
]);

$result = $converter->convert(new RawHttpResult($httpResponse));
$this->assertInstanceOf(TextResult::class, $result);
$this->assertSame(
'<analysis>This is the thinking process...</analysis>```json\n{"result": "actual response"}\n```',
$result->getContent()
);
}
}
Loading