-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bernhard Schmitt
committed
Jul 15, 2024
1 parent
8aa83e4
commit df5f824
Showing
7 changed files
with
128 additions
and
40 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
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\Chatterbox\Domain\Knowledge; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Sitegeist\Chatterbox\Domain\OrganizationDiscriminator; | ||
|
||
#[Flow\Proxy(false)] | ||
final readonly class VectorStoreName | ||
{ | ||
public function __construct( | ||
public KnowledgeSourceDiscriminator $knowledgeSourceDiscriminator, | ||
public int $timestamp, | ||
) { | ||
} | ||
|
||
public static function forKnowledgeSource(KnowledgeSourceDiscriminator $knowledgeSourceDiscriminator): self | ||
{ | ||
return new self( | ||
$knowledgeSourceDiscriminator, | ||
time() | ||
); | ||
} | ||
|
||
public static function tryFromNullableString(?string $value): ?self | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
if (substr_count($value, '-') !== 2) { | ||
return null; | ||
} | ||
list($discriminator, $sourceName, $timestamp) = explode('-', $value); | ||
|
||
if (!is_numeric($timestamp)) { | ||
return null; | ||
} | ||
|
||
return new self( | ||
new KnowledgeSourceDiscriminator( | ||
new OrganizationDiscriminator($discriminator), | ||
new KnowledgeSourceName($sourceName) | ||
), | ||
(int)$timestamp | ||
); | ||
} | ||
|
||
public function takesPrecedenceOver(self $other): bool | ||
{ | ||
if ($this->knowledgeSourceDiscriminator->equals($other->knowledgeSourceDiscriminator) === false) { | ||
return false; | ||
} | ||
|
||
return $this->timestamp > $other->timestamp; | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->knowledgeSourceDiscriminator->toString() . '-' . $this->timestamp; | ||
} | ||
} |
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