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: 11 additions & 0 deletions src/Requests/MessageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MessageRequest
private ?array $metadata = null;
private ?int $topK = null;
private ?float $topP = null;
private ?array $raw = [];

public function __construct(Config $config = null)
{
Expand Down Expand Up @@ -141,6 +142,12 @@ public function setTopP(?float $topP): self
return $this;
}

public function setRaw(?array $raw): self
{
$this->raw = $raw;
return $this;
}

public function toArray(): array
{
if (empty($this->messages)) {
Expand All @@ -153,6 +160,10 @@ public function toArray(): array
'messages' => $this->messages,
];

if (!empty($this->raw)) {
$data = array_merge($data, $this->raw);
}

if (!empty($this->system)) {
$data['system'] = $this->system;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,24 @@ public function testEnable128kOutputWithTokens()
// Verify max tokens is set correctly
$this->assertEquals($customTokens, $this->config->getMaxTokens());
}

public function testMessageRequestWithRaw()
{
$messageRequest = new MessageRequest();
$messageRequest->addMessage(new Message('user', [new TextContent('Hello world!')]));

$messageRequest->setRaw([
'thinking' => [
'type' => 'enabled',
'budget_tokens' => 24000
]
]);

$requestArray = $messageRequest->toArray();

$this->assertArrayHasKey('thinking', $requestArray);
$this->assertCount(2, $requestArray['thinking']);
$this->assertEquals('enabled', $requestArray['thinking']['type']);
}

}