fix unused config for model
This commit is contained in:
1
.env
1
.env
@@ -21,7 +21,6 @@ APP_SECRET=09333662211af45850ff13d68a40f8e3
|
|||||||
|
|
||||||
###> AI Agent Core ###
|
###> AI Agent Core ###
|
||||||
AI_LLM_API_URL=http://192.168.178.143:11434/api/generate
|
AI_LLM_API_URL=http://192.168.178.143:11434/api/generate
|
||||||
AI_LLM_MODEL=mto-model
|
|
||||||
AI_LLM_TIMEOUT=600
|
AI_LLM_TIMEOUT=600
|
||||||
|
|
||||||
AI_HISTORY_DIR=var/agent-history
|
AI_HISTORY_DIR=var/agent-history
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ services:
|
|||||||
App\Infrastructure\OllamaClient:
|
App\Infrastructure\OllamaClient:
|
||||||
arguments:
|
arguments:
|
||||||
$apiUrl: '%env(AI_LLM_API_URL)%'
|
$apiUrl: '%env(AI_LLM_API_URL)%'
|
||||||
$model: '%env(AI_LLM_MODEL)%'
|
|
||||||
$timeoutSeconds: 600
|
$timeoutSeconds: 600
|
||||||
$configProvider: '@App\Service\ModelGenerationConfigProvider'
|
$configProvider: '@App\Service\ModelGenerationConfigProvider'
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class ModelGenerationConfigController extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('ROLE_KNOWLEDGE_ADMIN');
|
$this->denyAccessUnlessGranted('ROLE_KNOWLEDGE_ADMIN');
|
||||||
|
|
||||||
$configs = $repository->findBy([], ['modelName' => 'ASC', 'version' => 'DESC']);
|
$configs = $repository->findBy([], ['active' => 'DESC', 'modelName' => 'ASC', 'version' => 'DESC']);
|
||||||
|
|
||||||
return $this->render('admin/model_config/list.html.twig', [
|
return $this->render('admin/model_config/list.html.twig', [
|
||||||
'configs' => $configs,
|
'configs' => $configs,
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ use Throwable;
|
|||||||
final class OllamaClient
|
final class OllamaClient
|
||||||
{
|
{
|
||||||
private ?ModelGenerationConfig $cachedConfig = null;
|
private ?ModelGenerationConfig $cachedConfig = null;
|
||||||
|
private $config = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private string $apiUrl,
|
private string $apiUrl,
|
||||||
private string $model,
|
private string $timeoutSeconds,
|
||||||
private int $timeoutSeconds,
|
|
||||||
private ModelGenerationConfigProvider $configProvider
|
private ModelGenerationConfigProvider $configProvider
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ final class OllamaClient
|
|||||||
*/
|
*/
|
||||||
public function stream(string $prompt): Generator
|
public function stream(string $prompt): Generator
|
||||||
{
|
{
|
||||||
$config = $this->getConfig();
|
$this->config = $this->getConfig();
|
||||||
|
|
||||||
if ($config->isStream()) {
|
if ($this->config->isStream()) {
|
||||||
yield from $this->streamInternal($prompt);
|
yield from $this->streamInternal($prompt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ final class OllamaClient
|
|||||||
private function buildPayload(string $prompt, bool $stream): string
|
private function buildPayload(string $prompt, bool $stream): string
|
||||||
{
|
{
|
||||||
return json_encode([
|
return json_encode([
|
||||||
'model' => $this->model,
|
'model' => $this->config->getModelName(),
|
||||||
'prompt' => $prompt,
|
'prompt' => $prompt,
|
||||||
'stream' => $stream,
|
'stream' => $stream,
|
||||||
'options' => $this->buildOptions()
|
'options' => $this->buildOptions()
|
||||||
@@ -178,14 +178,13 @@ final class OllamaClient
|
|||||||
*/
|
*/
|
||||||
private function buildOptions(): array
|
private function buildOptions(): array
|
||||||
{
|
{
|
||||||
$config = $this->getConfig();
|
$this->config = $this->getConfig();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'temperature' => $config->getTemperature(),
|
'temperature' => $this->config->getTemperature(),
|
||||||
'top_k' => $config->getTopK(),
|
'top_k' => $this->config->getTopK(),
|
||||||
'top_p' => $config->getTopP(),
|
'top_p' => $this->config->getTopP(),
|
||||||
'repeat_penalty' => $config->getRepeatPenalty(),
|
'repeat_penalty' => $this->config->getRepeatPenalty(),
|
||||||
'num_ctx' => $config->getNumCtx(),
|
'num_ctx' => $this->config->getNumCtx(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +194,7 @@ final class OllamaClient
|
|||||||
private function getConfig(): ModelGenerationConfig
|
private function getConfig(): ModelGenerationConfig
|
||||||
{
|
{
|
||||||
if ($this->cachedConfig === null) {
|
if ($this->cachedConfig === null) {
|
||||||
$this->cachedConfig = $this->configProvider->getActiveForModel($this->model);
|
$this->cachedConfig = $this->configProvider->getActiveForModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->cachedConfig;
|
return $this->cachedConfig;
|
||||||
|
|||||||
@@ -15,12 +15,10 @@ final class ModelGenerationConfigRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, ModelGenerationConfig::class);
|
parent::__construct($registry, ModelGenerationConfig::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findActiveForModel(string $modelName): ?ModelGenerationConfig
|
public function findActiveForModel(): ?ModelGenerationConfig
|
||||||
{
|
{
|
||||||
return $this->createQueryBuilder('c')
|
return $this->createQueryBuilder('c')
|
||||||
->andWhere('c.modelName = :model')
|
|
||||||
->andWhere('c.active = true')
|
->andWhere('c.active = true')
|
||||||
->setParameter('model', $modelName)
|
|
||||||
->orderBy('c.version', 'DESC')
|
->orderBy('c.version', 'DESC')
|
||||||
->setMaxResults(1)
|
->setMaxResults(1)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ final class ModelGenerationConfigManager
|
|||||||
|
|
||||||
$this->em->wrapInTransaction(function () use ($config) {
|
$this->em->wrapInTransaction(function () use ($config) {
|
||||||
|
|
||||||
// Alle aktiven für dieses Modell deaktivieren
|
|
||||||
$activeConfigs = $this->repository->findBy([
|
$activeConfigs = $this->repository->findBy([
|
||||||
'modelName' => $config->getModelName(),
|
|
||||||
'active' => true
|
'active' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ final class ModelGenerationConfigProvider
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActiveForModel(string $modelName): ModelGenerationConfig
|
public function getActiveForModel(): ModelGenerationConfig
|
||||||
{
|
{
|
||||||
$config = $this->repository->findActiveForModel($modelName);
|
$config = $this->repository->findActiveForModel();
|
||||||
|
|
||||||
if ($config !== null) {
|
if ($config !== null) {
|
||||||
return $config;
|
return $config;
|
||||||
@@ -28,7 +28,7 @@ final class ModelGenerationConfigProvider
|
|||||||
// Safe Enterprise Default Fallback
|
// Safe Enterprise Default Fallback
|
||||||
// ------------------------------
|
// ------------------------------
|
||||||
return new ModelGenerationConfig(
|
return new ModelGenerationConfig(
|
||||||
modelName: $modelName,
|
modelName: 'mto-model',
|
||||||
version: 0,
|
version: 0,
|
||||||
stream: false,
|
stream: false,
|
||||||
temperature: 0.1,
|
temperature: 0.1,
|
||||||
|
|||||||
Reference in New Issue
Block a user