Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ direction LR
+withMessageParts(...MessagePart $part) self
+withHistory(...Message $messages) self
+usingModel(ModelInterface $model) self
+usingSystemInstruction(string|MessagePart[]|Message $systemInstruction) self
+usingSystemInstruction(string $systemInstruction) self
+usingMaxTokens(int $maxTokens) self
+usingTemperature(float $temperature) self
+usingTopP(float $topP) self
Expand Down Expand Up @@ -475,7 +475,7 @@ direction LR
+withMessageParts(...MessagePart $part) self
+withHistory(...Message $messages) self
+usingModel(ModelInterface $model) self
+usingSystemInstruction(string|MessagePart[]|Message $systemInstruction) self
+usingSystemInstruction(string $systemInstruction) self
+usingMaxTokens(int $maxTokens) self
+usingTemperature(float $temperature) self
+usingTopP(float $topP) self
Expand Down Expand Up @@ -566,8 +566,6 @@ direction LR
}
class ModelMessage {
}
class SystemMessage {
}
class UserMessage {
}
}
Expand All @@ -582,7 +580,6 @@ direction LR
class MessageRoleEnum {
USER
MODEL
SYSTEM
}
class ModalityEnum {
TEXT
Expand Down Expand Up @@ -778,7 +775,6 @@ direction LR
Candidate ..> FinishReasonEnum
Message <|-- UserMessage
Message <|-- ModelMessage
Message <|-- SystemMessage
OperationInterface <|-- GenerativeAiOperation
OperationInterface <|-- EmbeddingOperation
ResultInterface <|-- GenerativeAiResult
Expand Down Expand Up @@ -944,8 +940,8 @@ direction LR
class ModelConfig {
+setOutputModalities(ModalityEnum[] $modalities) void
+getOutputModalities() ModalityEnum[]
+setSystemInstruction(string|MessagePart|MessagePart[]|Message $systemInstruction) void
+getSystemInstruction() Message?
+setSystemInstruction(string $systemInstruction) void
+getSystemInstruction() string?
Comment on lines -947 to +944
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this change, I was wondering whether your PR was missing that adjustment in ModelConfig itself, but then I checked and realized we never implemented it like this in the first place, it's always been a string - so that's perfect 😆

+setCandidateCount(int $candidateCount) void
+getCandidateCount() int
+setMaxTokens(int $maxTokens) void
Expand Down
4 changes: 2 additions & 2 deletions src/Messages/DTO/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ final public static function fromArray(array $array): self
} elseif ($role->isModel()) {
return new ModelMessage($parts);
} else {
// System is the only remaining option
return new SystemMessage($parts);
// Only USER and MODEL roles are supported
throw new \InvalidArgumentException('Invalid message role: ' . $role->value);
}
}
}
30 changes: 0 additions & 30 deletions src/Messages/DTO/SystemMessage.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Messages/Enums/MessageRoleEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
*
* @method static self user() Creates an instance for USER role.
* @method static self model() Creates an instance for MODEL role.
* @method static self system() Creates an instance for SYSTEM role.
* @method bool isUser() Checks if the role is USER.
* @method bool isModel() Checks if the role is MODEL.
* @method bool isSystem() Checks if the role is SYSTEM.
*/
class MessageRoleEnum extends AbstractEnum
{
Expand All @@ -29,9 +27,4 @@ class MessageRoleEnum extends AbstractEnum
* Model role - messages from the AI model.
*/
public const MODEL = 'model';

/**
* System role - system instructions.
*/
public const SYSTEM = 'system';
}
12 changes: 5 additions & 7 deletions tests/unit/Messages/DTO/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testCreateWithMultipleParts(): void
*/
public function testCreateWithEmptyParts(): void
{
$role = MessageRoleEnum::system();
$role = MessageRoleEnum::user();
$message = new Message($role, []);

$this->assertEquals($role, $message->getRole());
Expand Down Expand Up @@ -93,7 +93,6 @@ public function testWithDifferentRoles(MessageRoleEnum $role): void
public function roleProvider(): array
{
return [
'system' => [MessageRoleEnum::system()],
'user' => [MessageRoleEnum::user()],
'model' => [MessageRoleEnum::model()],
];
Expand Down Expand Up @@ -151,7 +150,6 @@ public function testJsonSchema(): void
$roleSchema = $schema['properties'][Message::KEY_ROLE];
$this->assertEquals('string', $roleSchema['type']);
$this->assertArrayHasKey('enum', $roleSchema);
$this->assertContains('system', $roleSchema['enum']);
$this->assertContains('user', $roleSchema['enum']);
$this->assertContains('model', $roleSchema['enum']);

Expand Down Expand Up @@ -263,21 +261,21 @@ public function testToArray(): void
public function testFromArray(): void
{
$json = [
Message::KEY_ROLE => MessageRoleEnum::system()->value,
Message::KEY_ROLE => MessageRoleEnum::user()->value,
Message::KEY_PARTS => [
[
MessagePart::KEY_TYPE => MessagePartTypeEnum::text()->value,
MessagePart::KEY_TEXT => 'You are a helpful assistant.'
MessagePart::KEY_TEXT => 'Hello, how can you help me?'
]
]
];

$message = Message::fromArray($json);

$this->assertInstanceOf(Message::class, $message);
$this->assertEquals(MessageRoleEnum::system(), $message->getRole());
$this->assertEquals(MessageRoleEnum::user(), $message->getRole());
$this->assertCount(1, $message->getParts());
$this->assertEquals('You are a helpful assistant.', $message->getParts()[0]->getText());
$this->assertEquals('Hello, how can you help me?', $message->getParts()[0]->getText());
}

/**
Expand Down
Loading