Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ContentInterface to Content #104

Merged
merged 1 commit into from
Oct 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace PhpLlm\LlmChain\Message\Content;

interface ContentInterface extends \JsonSerializable
interface Content extends \JsonSerializable
{
}
2 changes: 1 addition & 1 deletion src/Message/Content/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpLlm\LlmChain\Message\Content;

final readonly class Image implements ContentInterface
final readonly class Image implements Content
{
/**
* @param string $url An URL like "http://localhost:3000/my-image.png" or a data url like "data:image/png;base64,iVBOR[...]"
Expand Down
2 changes: 1 addition & 1 deletion src/Message/Content/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpLlm\LlmChain\Message\Content;

final readonly class Text implements ContentInterface
final readonly class Text implements Content
{
public function __construct(
public string $text,
Expand Down
6 changes: 3 additions & 3 deletions src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpLlm\LlmChain\Message;

use PhpLlm\LlmChain\Message\Content\ContentInterface;
use PhpLlm\LlmChain\Message\Content\Content;
use PhpLlm\LlmChain\Message\Content\Text;
use PhpLlm\LlmChain\Response\ToolCall;

Expand All @@ -28,10 +28,10 @@ public static function ofAssistant(?string $content = null, ?array $toolCalls =
return new AssistantMessage($content, $toolCalls);
}

public static function ofUser(string|ContentInterface ...$content): UserMessage
public static function ofUser(string|Content ...$content): UserMessage
{
$content = \array_map(
static fn (string|ContentInterface $entry) => \is_string($entry) ? new Text($entry) : $entry,
static fn (string|Content $entry) => \is_string($entry) ? new Text($entry) : $entry,
$content,
);

Expand Down
8 changes: 4 additions & 4 deletions src/Message/UserMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace PhpLlm\LlmChain\Message;

use PhpLlm\LlmChain\Message\Content\ContentInterface;
use PhpLlm\LlmChain\Message\Content\Content;
use PhpLlm\LlmChain\Message\Content\Image;
use PhpLlm\LlmChain\Message\Content\Text;

final readonly class UserMessage implements MessageInterface
{
/**
* @var list<ContentInterface>
* @var list<Content>
*/
public array $content;

public function __construct(
ContentInterface ...$content,
Content ...$content,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add the string and \Stringable type in a follow-up PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

) {
$this->content = $content;
}
Expand All @@ -40,7 +40,7 @@ public function hasImageContent(): bool
/**
* @return array{
* role: Role::User,
* content: string|list<ContentInterface>
* content: string|list<Content>
* }
*/
public function jsonSerialize(): array
Expand Down