optimize ui
add new ki endpoint params
This commit is contained in:
72
src/Service/ModelGenerationConfigManager.php
Normal file
72
src/Service/ModelGenerationConfigManager.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\ModelGenerationConfig;
|
||||
use App\Repository\ModelGenerationConfigRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
final class ModelGenerationConfigManager
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private ModelGenerationConfigRepository $repository
|
||||
) {}
|
||||
|
||||
public function activate(ModelGenerationConfig $config): void
|
||||
{
|
||||
$this->validate($config);
|
||||
|
||||
$this->em->wrapInTransaction(function () use ($config) {
|
||||
|
||||
// Alle aktiven für dieses Modell deaktivieren
|
||||
$activeConfigs = $this->repository->findBy([
|
||||
'modelName' => $config->getModelName(),
|
||||
'active' => true
|
||||
]);
|
||||
|
||||
foreach ($activeConfigs as $active) {
|
||||
$active->setActive(false);
|
||||
$this->em->persist($active);
|
||||
}
|
||||
|
||||
// Diese aktivieren
|
||||
$config->setActive(true);
|
||||
$this->em->persist($config);
|
||||
|
||||
$this->em->flush();
|
||||
});
|
||||
}
|
||||
|
||||
private function validate(ModelGenerationConfig $config): void
|
||||
{
|
||||
// Guardrails
|
||||
|
||||
if ($config->getTemperature() < 0.0 || $config->getTemperature() > 2.0) {
|
||||
throw new \InvalidArgumentException('Temperature must be between 0.0 and 2.0');
|
||||
}
|
||||
|
||||
if ($config->getTopP() <= 0.0 || $config->getTopP() > 1.0) {
|
||||
throw new \InvalidArgumentException('Top P must be between 0.0 and 1.0');
|
||||
}
|
||||
|
||||
if ($config->getTopK() <= 0) {
|
||||
throw new \InvalidArgumentException('Top K must be > 0');
|
||||
}
|
||||
|
||||
if ($config->getRepeatPenalty() < 0.0 || $config->getRepeatPenalty() > 5.0) {
|
||||
throw new \InvalidArgumentException('Repeat Penalty out of allowed range');
|
||||
}
|
||||
|
||||
if ($config->getNumCtx() < 512 || $config->getNumCtx() > 32768) {
|
||||
throw new \InvalidArgumentException('Num Ctx outside safe range');
|
||||
}
|
||||
|
||||
// Enterprise RAG Warnbereich (optional, nur Logging)
|
||||
if ($config->getTemperature() > 0.7) {
|
||||
// hier könntest du optional Logging einbauen
|
||||
}
|
||||
}
|
||||
}
|
||||
42
src/Service/ModelGenerationConfigProvider.php
Normal file
42
src/Service/ModelGenerationConfigProvider.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\ModelGenerationConfig;
|
||||
use App\Repository\ModelGenerationConfigRepository;
|
||||
|
||||
final class ModelGenerationConfigProvider
|
||||
{
|
||||
public function __construct(
|
||||
private ModelGenerationConfigRepository $repository
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function getActiveForModel(string $modelName): ModelGenerationConfig
|
||||
{
|
||||
$config = $this->repository->findActiveForModel($modelName);
|
||||
|
||||
if ($config !== null) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
// Safe Enterprise Default Fallback
|
||||
// ------------------------------
|
||||
return new ModelGenerationConfig(
|
||||
modelName: $modelName,
|
||||
version: 0,
|
||||
stream: false,
|
||||
temperature: 0.1,
|
||||
topK: 20,
|
||||
topP: 0.8,
|
||||
repeatPenalty: 1.05,
|
||||
numCtx: 4096,
|
||||
active: false
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user