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
1 parent
84a9499
commit 7caf441
Showing
4 changed files
with
45 additions
and
3 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
35 changes: 35 additions & 0 deletions
35
src/Service/AiHorde/MessageFormatter/VicunaMessageFormatter.php
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,35 @@ | ||
<?php | ||
|
||
namespace App\Service\AiHorde\MessageFormatter; | ||
|
||
use App\Enum\AiActor; | ||
use App\Enum\AiModel; | ||
use App\Service\AiHorde\Message\Message; | ||
use App\Service\AiHorde\Message\MessageHistory; | ||
|
||
final readonly class VicunaMessageFormatter implements MessageFormatter | ||
{ | ||
public function getPrompt(MessageHistory $messages): string | ||
{ | ||
$result = ''; | ||
foreach ($messages as $message) { | ||
$result .= "\n" . strtoupper($message->role->value) . ': ' . $message->content; | ||
} | ||
$result .= "\nASSISTANT:"; | ||
|
||
return $result; | ||
} | ||
|
||
public function formatOutput(string $message): Message | ||
{ | ||
return new Message( | ||
role: AiActor::Assistant, | ||
content: trim($message), | ||
); | ||
} | ||
|
||
public function supports(AiModel $model): bool | ||
{ | ||
return in_array($model, [AiModel::Fimbulvetr11Bv2], true); | ||
} | ||
} |
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