-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Showing
6 changed files
with
176 additions
and
4 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
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
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EchoLabs\Prism\ValueObjects\Messages\Support; | ||
|
||
use Illuminate\Support\Facades\File; | ||
use InvalidArgumentException; | ||
|
||
/** | ||
* Note: Prism currently only supports Documents with Anthropic. | ||
*/ | ||
class Document | ||
{ | ||
public function __construct( | ||
public readonly string $document, | ||
public readonly string $mimeType | ||
) {} | ||
|
||
public static function fromPath(string $path): self | ||
{ | ||
if (! is_file($path)) { | ||
throw new InvalidArgumentException("{$path} is not a file"); | ||
} | ||
|
||
$content = file_get_contents($path); | ||
|
||
if ($content === '' || $content === '0' || $content === false) { | ||
throw new InvalidArgumentException("{$path} is empty"); | ||
} | ||
|
||
$mimeType = File::mimeType($path); | ||
|
||
if ($mimeType === false) { | ||
throw new InvalidArgumentException("Could not determine mime type for {$path}"); | ||
} | ||
|
||
return new self( | ||
base64_encode($content), | ||
$mimeType, | ||
); | ||
} | ||
|
||
public static function fromBase64(string $document, string $mimeType): self | ||
{ | ||
return new self( | ||
$document, | ||
$mimeType | ||
); | ||
} | ||
} |
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
Binary file not shown.
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