-
-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db7d1ce
commit 9a20f1e
Showing
2 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
function threadMessageResource(): array | ||
{ | ||
return [ | ||
'id' => 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', | ||
'object' => 'thread.message', | ||
'created_at' => 1699623839, | ||
'thread_id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y', | ||
'role' => 'user', | ||
'content' => [ | ||
[ | ||
'type' => 'text', | ||
'text' => [ | ||
'value' => 'How does AI work? Explain it in simple terms.', | ||
'annotations' => [ | ||
], | ||
], | ||
], | ||
], | ||
'file_ids' => [ | ||
'file-DhxjnFCaSHc4ZELRGKwTMFtI', | ||
], | ||
'assistant_id' => null, | ||
'run_id' => null, | ||
'metadata' => [], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
function threadMessageListResource(): array | ||
{ | ||
return [ | ||
'object' => 'list', | ||
'data' => [ | ||
threadMessageResource(), | ||
threadMessageResource(), | ||
], | ||
'first_id' => 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', | ||
'last_id' => 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', | ||
'has_more' => false, | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
function threadMessageDeleteResource(): array | ||
{ | ||
return [ | ||
'id' => 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', | ||
'object' => 'thread.message.deleted', | ||
'deleted' => true, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
use OpenAI\Responses\Meta\MetaInformation; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageDeleteResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageListResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageResponseContentTextObject; | ||
use OpenAI\ValueObjects\Transporter\Response; | ||
|
||
test('list', function () { | ||
$client = mockClient('GET', 'threads/thread_agvtHUGezjTCt4SKgQg0NJ2Y/messages', [], Response::from(threadMessageListResource(), metaHeaders())); | ||
|
||
$result = $client->threads()->messages()->list('thread_agvtHUGezjTCt4SKgQg0NJ2Y'); | ||
|
||
expect($result) | ||
->toBeInstanceOf(ThreadMessageListResponse::class) | ||
->object->toBe('list') | ||
->data->toBeArray()->toHaveCount(2) | ||
->data->each->toBeInstanceOf(ThreadMessageResponse::class) | ||
->firstId->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->lastId->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->hasMore->toBeFalse(); | ||
|
||
expect($result->meta()) | ||
->toBeInstanceOf(MetaInformation::class); | ||
}); | ||
|
||
test('create', function () { | ||
$client = mockClient('POST', 'threads/thread_agvtHUGezjTCt4SKgQg0NJ2Y/messages', [ | ||
'role' => 'user', | ||
'content' => 'How does AI work? Explain it in simple terms.', | ||
'file_ids' => [ | ||
'file-DhxjnFCaSHc4ZELRGKwTMFtI', | ||
], | ||
], Response::from(threadMessageResource(), metaHeaders())); | ||
|
||
$result = $client->threads()->messages()->create('thread_agvtHUGezjTCt4SKgQg0NJ2Y', [ | ||
'role' => 'user', | ||
'content' => 'How does AI work? Explain it in simple terms.', | ||
'file_ids' => [ | ||
'file-DhxjnFCaSHc4ZELRGKwTMFtI', | ||
], | ||
]); | ||
|
||
expect($result) | ||
->toBeInstanceOf(ThreadMessageResponse::class) | ||
->id->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->object->toBe('thread.message') | ||
->createdAt->toBe(1699623839) | ||
->threadId->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y') | ||
->role->toBe('user') | ||
->content->toBeArray() | ||
->content->toHaveCount(1) | ||
->content->each->toBeInstanceOf(ThreadMessageResponseContentTextObject::class) | ||
->fileIds->toBeArray() | ||
->fileIds->toBe(['file-DhxjnFCaSHc4ZELRGKwTMFtI']) | ||
->assistantId->toBeNull() | ||
->runId->toBeNull() | ||
->metadata->toBeArray() | ||
->metadata->toBeEmpty(); | ||
|
||
expect($result->meta()) | ||
->toBeInstanceOf(MetaInformation::class); | ||
}); | ||
|
||
test('modify', function () { | ||
$client = mockClient('POST', 'threads/thread_agvtHUGezjTCt4SKgQg0NJ2Y/messages/msg_KNsDDwE41BUAHhcPNpDkdHWZ', [ | ||
'metadata' => [ | ||
'name' => 'My new message name', | ||
], | ||
], Response::from(threadMessageResource(), metaHeaders())); | ||
|
||
$result = $client->threads()->messages()->modify('thread_agvtHUGezjTCt4SKgQg0NJ2Y', 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', [ | ||
'metadata' => [ | ||
'name' => 'My new message name', | ||
], | ||
]); | ||
|
||
expect($result) | ||
->toBeInstanceOf(ThreadMessageResponse::class) | ||
->id->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->object->toBe('thread.message') | ||
->createdAt->toBe(1699623839) | ||
->threadId->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y') | ||
->role->toBe('user') | ||
->content->toBeArray() | ||
->content->toHaveCount(1) | ||
->content->each->toBeInstanceOf(ThreadMessageResponseContentTextObject::class) | ||
->fileIds->toBeArray() | ||
->fileIds->toBe(['file-DhxjnFCaSHc4ZELRGKwTMFtI']) | ||
->assistantId->toBeNull() | ||
->runId->toBeNull() | ||
->metadata->toBeArray() | ||
->metadata->toBeEmpty(); | ||
|
||
expect($result->meta()) | ||
->toBeInstanceOf(MetaInformation::class); | ||
}); | ||
|
||
test('retrieve', function () { | ||
$client = mockClient('GET', 'threads/thread_agvtHUGezjTCt4SKgQg0NJ2Y/messages/msg_KNsDDwE41BUAHhcPNpDkdHWZ', [], Response::from(threadMessageResource(), metaHeaders())); | ||
|
||
$result = $client->threads()->messages()->retrieve('thread_agvtHUGezjTCt4SKgQg0NJ2Y', 'msg_KNsDDwE41BUAHhcPNpDkdHWZ'); | ||
|
||
expect($result) | ||
->toBeInstanceOf(ThreadMessageResponse::class) | ||
->id->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->object->toBe('thread.message') | ||
->createdAt->toBe(1699623839) | ||
->threadId->toBe('thread_agvtHUGezjTCt4SKgQg0NJ2Y') | ||
->role->toBe('user') | ||
->content->toBeArray() | ||
->content->toHaveCount(1) | ||
->content->each->toBeInstanceOf(ThreadMessageResponseContentTextObject::class) | ||
->fileIds->toBeArray() | ||
->fileIds->toBe(['file-DhxjnFCaSHc4ZELRGKwTMFtI']) | ||
->assistantId->toBeNull() | ||
->runId->toBeNull() | ||
->metadata->toBeArray() | ||
->metadata->toBeEmpty(); | ||
|
||
expect($result->meta()) | ||
->toBeInstanceOf(MetaInformation::class); | ||
}); | ||
|
||
test('delete', function () { | ||
$client = mockClient('DELETE', 'threads/thread_agvtHUGezjTCt4SKgQg0NJ2Y/messages/msg_KNsDDwE41BUAHhcPNpDkdHWZ', [], Response::from(threadMessageDeleteResource(), metaHeaders())); | ||
|
||
$result = $client->threads()->messages()->delete('thread_agvtHUGezjTCt4SKgQg0NJ2Y', 'msg_KNsDDwE41BUAHhcPNpDkdHWZ'); | ||
|
||
expect($result) | ||
->toBeInstanceOf(ThreadMessageDeleteResponse::class) | ||
->id->toBe('msg_KNsDDwE41BUAHhcPNpDkdHWZ') | ||
->object->toBe('thread.message.deleted') | ||
->deleted->toBe(true); | ||
|
||
expect($result->meta()) | ||
->toBeInstanceOf(MetaInformation::class); | ||
}); |