AIConfig.php
- Pfad:
src/Infrastructure/AI/AIConfig.php - Namespace: Infrastructure\AI
- Zeilen: 154 | Größe: 4,944 Bytes
- Geändert: 2025-12-25 16:57:33 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 2
- use Infrastructure\Config\CredentialService
- use RuntimeException
Klassen 1
-
AIConfigclass Zeile 12
Funktionen 7
-
__construct()public Zeile 24 -
fromCredentialsFile()public Zeile 52 -
createChatService()public Zeile 79 -
createOllamaService()public Zeile 99 -
createQdrantService()public Zeile 114 -
createClaudeService()public Zeile 129 -
loadAnthropicApiKey()private Zeile 143
Verwendet von 1
Versionen 13
-
v13
2025-12-25 16:57 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v12
2025-12-25 16:56 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-25 16:56 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-25 16:56 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-25 16:56 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-25 16:55 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-25 16:55 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-24 16:22 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-23 08:00 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-23 08:00 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 08:24 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-22 08:24 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-20 17:24 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Infrastructure\AI;
// @responsibility: Zentralisierte Konfiguration und Factory für AI-Services
use Infrastructure\Config\CredentialService;
use RuntimeException;
final readonly class AIConfig
{
/**
* Konstruiert eine neue AIConfig-Instanz.
*
* @param string $ollamaHost Ollama API Host-URL
* @param string $qdrantHost Qdrant API Host-URL
* @param string $anthropicApiKey Anthropic API Key
* @param string $embeddingModel Embedding-Modell für Ollama
* @param string $claudeModel Claude-Modell für Anthropic
* @param string $defaultCollection Standard-Collection für Qdrant
*/
public function __construct(
public string $ollamaHost,
public string $qdrantHost,
public string $anthropicApiKey,
public string $embeddingModel,
public string $claudeModel,
public string $defaultCollection
) {
}
/**
* Erstellt AIConfig aus Credentials-Datei mit Default-Werten.
*
* Lädt den Anthropic API Key aus der credentials.md Datei und
* verwendet Default-Werte für alle anderen Konfigurationsparameter.
*
* @param string|null $credentialsPath Pfad zur credentials.md Datei (optional, verwendet Environment-Variable oder Default)
*
* @return self Konfigurierte AIConfig-Instanz
*
* @throws RuntimeException Wenn Credentials-Datei nicht existiert
* @throws RuntimeException Wenn Credentials-Datei nicht gelesen werden kann
* @throws RuntimeException Wenn Anthropic API Key nicht gefunden wird
*
* @example
* $config = AIConfig::fromCredentialsFile();
* $chatService = $config->createChatService();
*/
public static function fromCredentialsFile(?string $credentialsPath = null): self
{
$anthropicApiKey = self::loadAnthropicApiKey($credentialsPath);
return new self(
ollamaHost: CredentialService::getOllamaHost(),
qdrantHost: CredentialService::getQdrantHost(),
anthropicApiKey: $anthropicApiKey,
embeddingModel: 'mxbai-embed-large',
claudeModel: 'claude-opus-4-5-20251101',
defaultCollection: 'documents'
);
}
/**
* Erstellt einen konfigurierten ChatService.
*
* Erzeugt alle benötigten Dependencies (OllamaService, QdrantService, ClaudeService)
* und liefert einen vollständig konfigurierten ChatService zurück.
*
* @return ChatService Konfigurierter ChatService
*
* @example
* $config = AIConfig::fromCredentialsFile();
* $chatService = $config->createChatService();
* $result = $chatService->chat('Was ist systemisches Coaching?');
*/
public function createChatService(): ChatService
{
return new ChatService(
$this->createOllamaService(),
$this->createQdrantService(),
$this->createClaudeService(),
new ScoringService()
);
}
/**
* Erstellt einen konfigurierten OllamaService.
*
* @return OllamaService Konfigurierter OllamaService
*
* @example
* $config = AIConfig::fromCredentialsFile();
* $ollama = $config->createOllamaService();
* $embedding = $ollama->getEmbedding('Hello World');
*/
public function createOllamaService(): OllamaService
{
return new OllamaService($this->ollamaHost);
}
/**
* Erstellt einen konfigurierten QdrantService.
*
* @return QdrantService Konfigurierter QdrantService
*
* @example
* $config = AIConfig::fromCredentialsFile();
* $qdrant = $config->createQdrantService();
* $results = $qdrant->search($vector, 'documents');
*/
public function createQdrantService(): QdrantService
{
return new QdrantService($this->qdrantHost);
}
/**
* Erstellt einen konfigurierten ClaudeService.
*
* @return ClaudeService Konfigurierter ClaudeService
*
* @example
* $config = AIConfig::fromCredentialsFile();
* $claude = $config->createClaudeService();
* $result = $claude->ask('Explain quantum computing');
*/
public function createClaudeService(): ClaudeService
{
return new ClaudeService();
}
/**
* Lädt den Anthropic API Key aus der Credentials-Datei.
*
* @param string|null $credentialsPath Pfad zur credentials.md Datei (unused, kept for BC)
*
* @return string Der gefundene API Key
*
* @throws RuntimeException Wenn API Key nicht gefunden wird
*/
private static function loadAnthropicApiKey(?string $credentialsPath): string
{
$apiKey = CredentialService::getAnthropicApiKey();
if ($apiKey === '') {
throw new RuntimeException('Anthropic API key not found in credentials file');
}
return $apiKey;
}
}