Skip to content

Commit 18423c9

Browse files
authored
fix(OpenAI): add support for missing url on web search output for Responses (#733)
1 parent e388422 commit 18423c9

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/Responses/Responses/Output/WebSearch/OutputWebSearchActionSources.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use OpenAI\Testing\Responses\Concerns\Fakeable;
1010

1111
/**
12-
* @phpstan-type WebSearchActionSourcesType array{type: 'url', url: string}
12+
* @phpstan-type WebSearchActionSourcesType array{type: 'url', url: string|null}
1313
*
1414
* @implements ResponseContract<WebSearchActionSourcesType>
1515
*/
@@ -27,7 +27,7 @@ final class OutputWebSearchActionSources implements ResponseContract
2727
*/
2828
private function __construct(
2929
public readonly string $type,
30-
public readonly string $url
30+
public readonly ?string $url
3131
) {}
3232

3333
/**
@@ -37,7 +37,7 @@ public static function from(array $attributes): self
3737
{
3838
return new self(
3939
type: $attributes['type'],
40-
url: $attributes['url'],
40+
url: $attributes['url'] ?? null,
4141
);
4242
}
4343

tests/Responses/Responses/Output/OutputWebSearchToolCall.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,20 @@
100100
->not->toHaveKey('query')
101101
->not->toHaveKey('sources');
102102
});
103+
104+
test('from with source without url', function () {
105+
$payload = outputWebSearchToolCall();
106+
$payload['action']['sources'] = [
107+
['type' => 'url'],
108+
];
109+
110+
$response = OutputWebSearchToolCall::from($payload);
111+
112+
expect($response)
113+
->toBeInstanceOf(OutputWebSearchToolCall::class)
114+
->action->sources->toHaveCount(1);
115+
116+
expect($response->action->sources[0])
117+
->type->toBe('url')
118+
->url->toBeNull();
119+
});

0 commit comments

Comments
 (0)