File size: 5,961 Bytes
cf14c12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | <?php
declare(strict_types=1);
namespace Billing\Domain\ValueObjects;
use Ai\Domain\ValueObjects\Model;
use Billing\Domain\ValueObjects\PlanConfig\ChatConfig;
use Billing\Domain\ValueObjects\PlanConfig\ClassifierConfig;
use Billing\Domain\ValueObjects\PlanConfig\CoderConfig;
use Billing\Domain\ValueObjects\PlanConfig\ImagineConfig;
use Billing\Domain\ValueObjects\PlanConfig\TitlerConfig;
use Billing\Domain\ValueObjects\PlanConfig\TranscriberConfig;
use Billing\Domain\ValueObjects\PlanConfig\VoiceIsolatorConfig;
use Billing\Domain\ValueObjects\PlanConfig\VoiceOverConfig;
use Billing\Domain\ValueObjects\PlanConfig\WriterConfig;
use JsonSerializable;
use Override;
class PlanConfig implements JsonSerializable
{
public readonly WriterConfig $writer;
public readonly CoderConfig $coder;
public readonly ImagineConfig $imagine;
public readonly TranscriberConfig $transcriber;
public readonly VoiceOverConfig $voiceover;
public readonly TitlerConfig $titler;
public readonly ChatConfig $chat;
public readonly VoiceIsolatorConfig $voiceIsolator;
public readonly ClassifierConfig $classifier;
/** @var array<string,bool> */
public readonly array $models;
/** @var array<string,bool> */
public readonly array $tools;
public readonly Model $embeddingModel;
/** @var null|array<string> */
public readonly ?array $assistants;
/** @var null|array<string> */
public readonly ?array $presets;
public function __construct(?array $data = null)
{
$data = $data ?? [];
$this->writer = new WriterConfig(
$data['writer']['is_enabled'] ?? false,
new Model($data['writer']['model'] ?? 'gpt-4')
);
$this->coder = new CoderConfig(
$data['coder']['is_enabled'] ?? false,
new Model($data['coder']['model'] ?? 'gpt-4')
);
$this->imagine = new ImagineConfig(
$data['imagine']['is_enabled'] ?? false
);
$this->transcriber = new TranscriberConfig(
$data['transcriber']['is_enabled'] ?? false
);
$this->voiceover = new VoiceOverConfig(
$data['voiceover']['is_enabled'] ?? false
);
$this->titler = new TitlerConfig(
new Model($data['titler']['model'] ?? 'gpt-4')
);
$this->chat = new ChatConfig(
$data['chat']['is_enabled'] ?? false
);
$this->voiceIsolator = new VoiceIsolatorConfig(
$data['voice_isolator']['is_enabled'] ?? false
);
$this->classifier = new ClassifierConfig(
$data['classifier']['is_enabled'] ?? false
);
$models = [
'gpt-4o' => false,
'gpt-4o-mini' => false,
'gpt-4-turbo' => false,
'gpt-4' => false,
'gpt-3.5-turbo' => false,
'claude-3-5-sonnet-20240620' => false,
'claude-3-haiku-20240307' => false,
'claude-3-sonnet-20240229' => false,
'claude-3-opus-20240229' => false,
'command-r-plus' => false,
'command-r' => false,
'command' => false,
'command-light' => false,
'dall-e-3' => false,
'dall-e-2' => false,
'flux-pro' => false,
'flux-realism' => false,
'sd-ultra' => false,
'sd-core' => false,
'sd3-large' => false,
'sd3-large-turbo' => false,
'sd3-medium' => false,
'stable-diffusion-xl-1024-v1-0' => false,
'stable-diffusion-v1-6' => false,
'clipdrop' => false,
'tts-1' => false,
'eleven_multilingual_v2' => false,
'eleven_turbo_v2_5' => false,
'eleven_multilingual_v1' => false,
'eleven_monolingual_v1' => false,
'google-tts-standard' => false,
'google-tts-premium' => false,
'google-tts-studio' => false,
'azure-tts' => false,
];
foreach ($models as $model => $enabled) {
$models[$model] = (bool) ($data['models'][$model] ?? false);
}
$this->models = $models;
$tools = [
'embedding_search' => false,
'google_search' => false,
'cohere_web_search' => false,
'web_scrap' => false,
'generate_image' => false,
];
foreach ($tools as $tool => $enabled) {
$tools[$tool] = (bool) ($data['tools'][$tool] ?? false);
}
$this->tools = $tools;
$this->embeddingModel = new Model($data['embedding_model'] ?? 'text-embedding-ada-002');
$this->assistants = isset($data['assistants']) && is_array($data['assistants'])
? array_filter(
$data['assistants'],
fn($assistant) => is_string($assistant)
) : null;
$this->presets = isset($data['presets']) && is_array($data['presets'])
? array_filter(
$data['presets'],
fn($assistant) => is_string($assistant)
) : null;
}
#[Override]
public function jsonSerialize(): array
{
return [
'writer' => $this->writer,
'coder' => $this->coder,
'imagine' => $this->imagine,
'transcriber' => $this->transcriber,
'voiceover' => $this->voiceover,
'chat' => $this->chat,
'voice_isolator' => $this->voiceIsolator,
'classifier' => $this->classifier,
'titler' => $this->titler,
'models' => $this->models,
'tools' => $this->tools,
'embedding_model' => $this->embeddingModel,
'assistants' => $this->assistants,
'presets' => $this->presets,
];
}
public function toArray(): array
{
return json_decode(json_encode($this), true);
}
}
|