Skip to content

Commit

Permalink
Merge pull request #53 from outl1ne/Virtual-branch
Browse files Browse the repository at this point in the history
refactor: Update Message class to accept content as string or array
  • Loading branch information
allantatter authored Aug 12, 2024
2 parents c5617f9 + 0d03e97 commit df29752
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/Capabilities/Threads/Parameters/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ class Message
{
public function __construct(
public readonly string $role,
public readonly string $content,
public readonly string|array $content,
public readonly ?array $attachments = [],
public readonly ?array $metadata = null,
) {
}
) {}

static public function user(string $content, ?array $attachments = null, ?array $metadata = null): self
static public function user(string|array $content, ?array $attachments = null, ?array $metadata = null): self
{
return new self(
'user',
Expand Down
17 changes: 16 additions & 1 deletion tests/Unit/ThreadsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_threads(): void
'gpt-4o-mini',
'Allan',
'nova-openai testimiseks',
'You are a kindergarten teacher. When asked a questions, anwser shortly and as a young child could understand.'
'You are a kindergarten teacher. When asked a questions, anwser shortly and as a young child could understand. Answer all questions from all messaged from the user in a single message.'
);
$this->assertTrue($assistant instanceof AssistantResponse);

Expand All @@ -43,6 +43,21 @@ public function test_threads(): void
->create($thread->id, Message::user('How does AI work? Explain it in simple terms in one sentence.'));
$this->assertTrue($message instanceof MessageResponse);

$message2 = OpenAI::threads()->messages()
->create($thread->id, Message::user([
[
'type' => 'text',
'text' => 'Describe what\'s on the attached photo',
],
[
'type' => 'image_url',
'image_url' => [
'url' => 'https://img-cdn.pixlr.com/image-generator/history/65bb506dcb310754719cf81f/ede935de-1138-4f66-8ed7-44bd16efc709/medium.webp',
],
],
]));
$this->assertTrue($message2 instanceof MessageResponse);

$run = OpenAI::threads()->run()->execute($thread->id, $assistant->id);
$this->assertTrue($run instanceof RunResponse);

Expand Down

0 comments on commit df29752

Please sign in to comment.