Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 78320df

Browse filesBrowse files
authored
fix(OpenAI): support nested file search properties (#670)
* fix(OpenAI): support nested file search properties * test(OpenAI): augment file search for nested properties
1 parent aab80a9 commit 78320df
Copy full SHA for 78320df

File tree

Expand file treeCollapse file tree

3 files changed

+65
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+65
-4
lines changed
Open diff view settings
Collapse file

‎src/Responses/Responses/Tool/FileSearchCompoundFilter.php‎

Copy file name to clipboardExpand all lines: src/Responses/Responses/Tool/FileSearchCompoundFilter.php
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
/**
1212
* @phpstan-import-type ComparisonFilterType from FileSearchComparisonFilter
1313
*
14-
* @phpstan-type CompoundFilterType array{filters: array<int, ComparisonFilterType>, type: 'and'|'or'}
14+
* @phpstan-type CompoundFilterNodeType array{filters: array<int, ComparisonFilterType>, type: 'and'|'or'}
15+
* @phpstan-type CompoundFilterType array{filters: array<int, ComparisonFilterType|CompoundFilterNodeType>, type: 'and'|'or'}
1516
*
1617
* @implements ResponseContract<CompoundFilterType>
1718
*/
@@ -25,7 +26,7 @@ final class FileSearchCompoundFilter implements ResponseContract
2526
use Fakeable;
2627

2728
/**
28-
* @param array<int, FileSearchComparisonFilter> $filters
29+
* @param array<int, FileSearchComparisonFilter|FileSearchCompoundFilter> $filters
2930
* @param 'and'|'or' $type
3031
*/
3132
private function __construct(
@@ -39,7 +40,10 @@ private function __construct(
3940
public static function from(array $attributes): self
4041
{
4142
$filters = array_map(
42-
static fn (array $filter): FileSearchComparisonFilter => FileSearchComparisonFilter::from($filter),
43+
static fn (array $filter): FileSearchComparisonFilter|FileSearchCompoundFilter => match ($filter['type']) {
44+
'eq', 'ne', 'gt', 'gte', 'lt', 'lte' => FileSearchComparisonFilter::from($filter),
45+
'and', 'or' => FileSearchCompoundFilter::from($filter),
46+
},
4347
$attributes['filters'],
4448
);
4549

@@ -54,9 +58,10 @@ public static function from(array $attributes): self
5458
*/
5559
public function toArray(): array
5660
{
61+
// @phpstan-ignore-next-line
5762
return [
5863
'filters' => array_map(
59-
static fn (FileSearchComparisonFilter $filter): array => $filter->toArray(),
64+
static fn (FileSearchComparisonFilter|FileSearchCompoundFilter $filter): array => $filter->toArray(),
6065
$this->filters,
6166
),
6267
'type' => $this->type,
Collapse file

‎tests/Fixtures/Responses.php‎

Copy file name to clipboardExpand all lines: tests/Fixtures/Responses.php
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,45 @@ function toolFileSearch(): array
690690
];
691691
}
692692

693+
/**
694+
* @return array<string, mixed>
695+
*/
696+
function toolFileSearchNestedFilters(): array
697+
{
698+
return [
699+
'type' => 'file_search',
700+
'filters' => [
701+
'type' => 'and',
702+
'filters' => [
703+
[
704+
'type' => 'and',
705+
'filters' => [
706+
[
707+
'type' => 'ne',
708+
'key' => 'state',
709+
'value' => 'ks',
710+
],
711+
[
712+
'type' => 'ne',
713+
'key' => 'state',
714+
'value' => 'mo',
715+
],
716+
],
717+
],
718+
],
719+
],
720+
'max_num_results' => 5,
721+
'ranking_options' => [
722+
'ranker' => 'auto',
723+
'score_threshold' => 0.1,
724+
],
725+
'vector_store_ids' => [
726+
'vector_store_id_1',
727+
'vector_store_id_2',
728+
],
729+
];
730+
}
731+
693732
/**
694733
* @return resource
695734
*/
Collapse file

‎tests/Responses/Responses/Tool/FileSearchTool.php‎

Copy file name to clipboardExpand all lines: tests/Responses/Responses/Tool/FileSearchTool.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use OpenAI\Responses\Responses\Tool\FileSearchComparisonFilter;
4+
use OpenAI\Responses\Responses\Tool\FileSearchCompoundFilter;
45
use OpenAI\Responses\Responses\Tool\FileSearchRankingOption;
56
use OpenAI\Responses\Responses\Tool\FileSearchTool;
67

@@ -31,6 +32,22 @@
3132
->filters->toBeNull();
3233
});
3334

35+
test('from complex nested filters', function () {
36+
$response = FileSearchTool::from(toolFileSearchNestedFilters());
37+
38+
expect($response)
39+
->toBeInstanceOf(FileSearchTool::class)
40+
->filters->toBeInstanceOf(FileSearchCompoundFilter::class)
41+
->filters->filters->toBeArray()
42+
->and($response->filters->filters[0])
43+
->toBeInstanceOf(FileSearchCompoundFilter::class)
44+
->filters->toBeArray()
45+
->and($response->filters->filters[0]->filters[0])
46+
->toBeInstanceOf(FileSearchComparisonFilter::class)
47+
->and($response->filters->filters[0]->filters[1])
48+
->toBeInstanceOf(FileSearchComparisonFilter::class);
49+
});
50+
3451
test('from results', function () {
3552
$response = FileSearchTool::from(toolFileSearch());
3653

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.