Skip to content

Commit 65f041e

Browse files
committed
feat: adds implementor DTOs
1 parent 530a9f7 commit 65f041e

24 files changed

+2378
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Common\Contracts;
6+
7+
/**
8+
* Interface for objects that can provide their JSON schema representation
9+
*
10+
* This interface is implemented by DTOs to provide a consistent way to retrieve
11+
* their JSON schema for validation and serialization purposes.
12+
*
13+
* @since n.e.x.t
14+
*/
15+
interface WithJsonSchema
16+
{
17+
/**
18+
* Get the JSON schema representation of the object
19+
*
20+
* @since n.e.x.t
21+
* @return array<string, mixed> The JSON schema as an associative array
22+
*/
23+
public static function getJsonSchema(): array;
24+
}

src/Embeddings/DTO/Embedding.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Embeddings\DTO;
6+
7+
/**
8+
* Represents an embedding vector
9+
*
10+
* Embeddings are numerical representations of text that capture semantic meaning,
11+
* used for tasks like similarity search and clustering.
12+
*
13+
* @since n.e.x.t
14+
*/
15+
class Embedding
16+
{
17+
/**
18+
* @var float[] The embedding vector
19+
*/
20+
private array $vector;
21+
22+
/**
23+
* Constructor
24+
*
25+
* @since n.e.x.t
26+
* @param float[] $vector The embedding vector
27+
*/
28+
public function __construct(array $vector)
29+
{
30+
$this->vector = $vector;
31+
}
32+
33+
/**
34+
* Get the embedding vector
35+
*
36+
* @since n.e.x.t
37+
* @return float[] The vector
38+
*/
39+
public function getVector(): array
40+
{
41+
return $this->vector;
42+
}
43+
44+
/**
45+
* Get the dimension of the embedding
46+
*
47+
* @since n.e.x.t
48+
* @return int The number of dimensions
49+
*/
50+
public function getDimension(): int
51+
{
52+
return count($this->vector);
53+
}
54+
}

src/Files/Contracts/FileInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Files\Contracts;
6+
7+
/**
8+
* Interface for file representations in the AI client
9+
*
10+
* This interface defines the common contract for various file types that can be
11+
* used as input or output in AI operations.
12+
*
13+
* @since n.e.x.t
14+
*/
15+
interface FileInterface
16+
{
17+
/**
18+
* Get the MIME type of the file
19+
*
20+
* @since n.e.x.t
21+
* @return string The MIME type (e.g., 'image/png', 'audio/mp3')
22+
*/
23+
public function getMimeType(): string;
24+
}

src/Files/DTO/InlineFile.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Files\DTO;
6+
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
8+
use WordPress\AiClient\Files\Contracts\FileInterface;
9+
10+
/**
11+
* Represents a file with inline base64-encoded data
12+
*
13+
* This DTO is used for files that are embedded directly in the request as base64 data,
14+
* commonly used for small files or when direct data transfer is preferred.
15+
*
16+
* @since n.e.x.t
17+
*/
18+
class InlineFile implements FileInterface, WithJsonSchema
19+
{
20+
/**
21+
* @var string The MIME type of the file
22+
*/
23+
private string $mimeType;
24+
25+
/**
26+
* @var string The base64-encoded file data
27+
*/
28+
private string $base64Data;
29+
30+
/**
31+
* Constructor
32+
*
33+
* @since n.e.x.t
34+
* @param string $mimeType The MIME type of the file
35+
* @param string $base64Data The base64-encoded file data
36+
*/
37+
public function __construct(string $mimeType, string $base64Data)
38+
{
39+
$this->mimeType = $mimeType;
40+
$this->base64Data = $base64Data;
41+
}
42+
43+
/**
44+
* Get the MIME type of the file
45+
*
46+
* @since n.e.x.t
47+
* @return string The MIME type
48+
*/
49+
public function getMimeType(): string
50+
{
51+
return $this->mimeType;
52+
}
53+
54+
/**
55+
* Get the base64-encoded data
56+
*
57+
* @since n.e.x.t
58+
* @return string The base64-encoded data
59+
*/
60+
public function getBase64Data(): string
61+
{
62+
return $this->base64Data;
63+
}
64+
65+
/**
66+
* Get the JSON schema for this DTO
67+
*
68+
* @since n.e.x.t
69+
* @return array<string, mixed> The JSON schema
70+
*/
71+
public static function getJsonSchema(): array
72+
{
73+
return [
74+
'type' => 'object',
75+
'properties' => [
76+
'mimeType' => [
77+
'type' => 'string',
78+
'description' => 'The MIME type of the file',
79+
],
80+
'base64Data' => [
81+
'type' => 'string',
82+
'description' => 'The base64-encoded file data',
83+
],
84+
],
85+
'required' => ['mimeType', 'base64Data'],
86+
];
87+
}
88+
}

src/Files/DTO/LocalFile.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Files\DTO;
6+
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
8+
use WordPress\AiClient\Files\Contracts\FileInterface;
9+
10+
/**
11+
* Represents a file stored locally on the filesystem
12+
*
13+
* This DTO is used for files that are referenced by their local path,
14+
* typically used when working with files already present on the server.
15+
*
16+
* @since n.e.x.t
17+
*/
18+
class LocalFile implements FileInterface, WithJsonSchema
19+
{
20+
/**
21+
* @var string The MIME type of the file
22+
*/
23+
private string $mimeType;
24+
25+
/**
26+
* @var string The local filesystem path to the file
27+
*/
28+
private string $path;
29+
30+
/**
31+
* Constructor
32+
*
33+
* @since n.e.x.t
34+
* @param string $mimeType The MIME type of the file
35+
* @param string $path The local filesystem path to the file
36+
*/
37+
public function __construct(string $mimeType, string $path)
38+
{
39+
$this->mimeType = $mimeType;
40+
$this->path = $path;
41+
}
42+
43+
/**
44+
* Get the MIME type of the file
45+
*
46+
* @since n.e.x.t
47+
* @return string The MIME type
48+
*/
49+
public function getMimeType(): string
50+
{
51+
return $this->mimeType;
52+
}
53+
54+
/**
55+
* Get the local filesystem path
56+
*
57+
* @since n.e.x.t
58+
* @return string The local path
59+
*/
60+
public function getPath(): string
61+
{
62+
return $this->path;
63+
}
64+
65+
/**
66+
* Get the JSON schema for this DTO
67+
*
68+
* @since n.e.x.t
69+
* @return array<string, mixed> The JSON schema
70+
*/
71+
public static function getJsonSchema(): array
72+
{
73+
return [
74+
'type' => 'object',
75+
'properties' => [
76+
'mimeType' => [
77+
'type' => 'string',
78+
'description' => 'The MIME type of the file',
79+
],
80+
'path' => [
81+
'type' => 'string',
82+
'description' => 'The local filesystem path to the file',
83+
],
84+
],
85+
'required' => ['mimeType', 'path'],
86+
];
87+
}
88+
}

src/Files/DTO/RemoteFile.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Files\DTO;
6+
7+
use WordPress\AiClient\Common\Contracts\WithJsonSchema;
8+
use WordPress\AiClient\Files\Contracts\FileInterface;
9+
10+
/**
11+
* Represents a file accessible via a remote URL
12+
*
13+
* This DTO is used for files that are hosted remotely and accessed via HTTP/HTTPS,
14+
* commonly used for media files stored on CDNs or external services.
15+
*
16+
* @since n.e.x.t
17+
*/
18+
class RemoteFile implements FileInterface, WithJsonSchema
19+
{
20+
/**
21+
* @var string The MIME type of the file
22+
*/
23+
private string $mimeType;
24+
25+
/**
26+
* @var string The URL to the remote file
27+
*/
28+
private string $url;
29+
30+
/**
31+
* Constructor
32+
*
33+
* @since n.e.x.t
34+
* @param string $mimeType The MIME type of the file
35+
* @param string $url The URL to the remote file
36+
*/
37+
public function __construct(string $mimeType, string $url)
38+
{
39+
$this->mimeType = $mimeType;
40+
$this->url = $url;
41+
}
42+
43+
/**
44+
* Get the MIME type of the file
45+
*
46+
* @since n.e.x.t
47+
* @return string The MIME type
48+
*/
49+
public function getMimeType(): string
50+
{
51+
return $this->mimeType;
52+
}
53+
54+
/**
55+
* Get the URL to the remote file
56+
*
57+
* @since n.e.x.t
58+
* @return string The URL
59+
*/
60+
public function getUrl(): string
61+
{
62+
return $this->url;
63+
}
64+
65+
/**
66+
* Get the JSON schema for this DTO
67+
*
68+
* @since n.e.x.t
69+
* @return array<string, mixed> The JSON schema
70+
*/
71+
public static function getJsonSchema(): array
72+
{
73+
return [
74+
'type' => 'object',
75+
'properties' => [
76+
'mimeType' => [
77+
'type' => 'string',
78+
'description' => 'The MIME type of the file',
79+
],
80+
'url' => [
81+
'type' => 'string',
82+
'format' => 'uri',
83+
'description' => 'The URL to the remote file',
84+
],
85+
],
86+
'required' => ['mimeType', 'url'],
87+
];
88+
}
89+
}

0 commit comments

Comments
 (0)