Skip to content

Commit d4a7818

Browse files
committed
test: augment tests for omni vs legacy moderation
1 parent e4bc4e8 commit d4a7818

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

tests/Fixtures/Moderation.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,49 @@ function moderationResource(): array
4141
],
4242
];
4343
}
44+
45+
/**
46+
* @return array<string, mixed>
47+
*/
48+
function moderationOmniResource(): array
49+
{
50+
return [
51+
'id' => 'modr-5MWoLO',
52+
'model' => 'omni-moderation-001',
53+
'results' => [
54+
[
55+
'categories' => [
56+
'hate' => false,
57+
'hate/threatening' => true,
58+
'harassment' => false,
59+
'harassment/threatening' => false,
60+
'illicit' => false,
61+
'illicit/violent' => true,
62+
'self-harm' => false,
63+
'self-harm/intent' => false,
64+
'self-harm/instructions' => false,
65+
'sexual' => false,
66+
'sexual/minors' => false,
67+
'violence' => false,
68+
'violence/graphic' => false,
69+
],
70+
'category_scores' => [
71+
'hate' => 0.22714105248451233,
72+
'hate/threatening' => 0.4132447838783264,
73+
'illicit' => 0.1602763684674149,
74+
'illicit/violent' => 0.9223177433013916,
75+
'harassment' => 0.1602763684674149,
76+
'harassment/threatening' => 0.1602763684674149,
77+
'self-harm' => 0.005232391878962517,
78+
'self-harm/intent' => 0.005134391873962517,
79+
'self-harm/instructions' => 0.005132591874962517,
80+
'sexual' => 0.01407341007143259,
81+
'sexual/minors' => 0.0038522258400917053,
82+
'violence' => 0.4132447838783264,
83+
'violence/graphic' => 0.036865197122097015,
84+
],
85+
'flagged' => true,
86+
],
87+
],
88+
];
89+
}

tests/Resources/Moderations.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use OpenAI\Responses\Moderations\CreateResponseResult;
88
use OpenAI\ValueObjects\Transporter\Response;
99

10-
test('create', closure: function () {
10+
test('create legacy', closure: function () {
1111
$client = mockClient('POST', 'moderations', [
1212
'model' => 'text-moderation-latest',
1313
'input' => 'I want to kill them.',
@@ -43,3 +43,40 @@
4343
expect($result->meta())
4444
->toBeInstanceOf(MetaInformation::class);
4545
});
46+
47+
test('create omni', closure: function () {
48+
$client = mockClient('POST', 'moderations', [
49+
'model' => 'omni-moderation-latest',
50+
'input' => 'I want to kill them.',
51+
], Response::from(moderationOmniResource(), metaHeaders()));
52+
53+
$result = $client->moderations()->create([
54+
'model' => 'omni-moderation-latest',
55+
'input' => 'I want to kill them.',
56+
]);
57+
58+
expect($result)
59+
->toBeInstanceOf(CreateResponse::class)
60+
->id->toBe('modr-5MWoLO')
61+
->model->toBe('omni-moderation-001')
62+
->results->toBeArray()->toHaveCount(1)
63+
->results->each->toBeInstanceOf(CreateResponseResult::class);
64+
65+
expect($result->results[0])
66+
->flagged->toBeTrue()
67+
->categories->toHaveCount(13)
68+
->each->toBeInstanceOf(CreateResponseCategory::class);
69+
70+
expect($result->results[0]->categories[Category::Illicit->value])
71+
->category->toBe(Category::Illicit)
72+
->violated->toBe(false)
73+
->score->toBe(0.1602763684674149);
74+
75+
expect($result->results[0]->categories[Category::IllicitViolent->value])
76+
->category->toBe(Category::IllicitViolent)
77+
->violated->toBe(true)
78+
->score->toBe(0.9223177433013916);
79+
80+
expect($result->meta())
81+
->toBeInstanceOf(MetaInformation::class);
82+
});

0 commit comments

Comments
 (0)