v0.11 U6: Bring your own key für die KI-Auswertung (Anthropic, OpenRouter)
Deploy FeWo mit PipelineManager / deploy (push) Successful in 5m11s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 5m11s
- Jeder Mandant verbindet unter „System › KI-Anbindung“ seinen eigenen Zugang: Anbieter (Anthropic oder OpenRouter), API-Schlüssel, Modell für die erste Auswertung und für die Prüfung – keine Modellkennung im Code, kein zentraler Betreiberschlüssel (FEWO_AI_API_KEY entfällt). - Gespeichert im bestehenden TenantService (ai_guest_mail): Schlüssel verschlüsselt, nie wieder angezeigt, nie in Meldungen; Anbieter/Modelle in settings, Prüfergebnis in check_status/check_message/checked_at. - Feste Endpunkte je Anbieter (AiProvider), nicht konfigurierbar. OpenRouter mit response_format json_schema (strict) und provider.require_parameters. - „Verbindung prüfen“ testet beide Modelle. Ein abgelehnter Zugang (401/402/403) schaltet die Auswertung für den Mandanten ab, meldet es im Postfach der Verwaltung; Nachrichten bleiben zur Prüfung im Posteingang. - Zweistufige Extraktion und ihre Sicherheitsregeln unverändert. - Zielarchitektur §3.8, Umsetzungsplan U6, Bericht, Drehbuch, Status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f9aa46943
commit
6862dec201
20 files changed
+752
-95
No files matched your search
@@ -9,7 +9,8 @@
|
||||
/**
|
||||
* The model side of the extraction (v0.11, CH-14): versioned prompts with defined placeholders, a JSON schema for the
|
||||
* answer and its validation here (the answer is checked, not trusted). The small model extracts; the review model
|
||||
* sees the original and the first extraction. Both only return candidates – nothing is stored or changed here.
|
||||
* sees the original and the first extraction – both as configured in the landlord's own access. Both only return
|
||||
* candidates – nothing is stored or changed here.
|
||||
*/
|
||||
class MessageExtractor
|
||||
{
|
||||
@@ -20,9 +21,9 @@ public function __construct(private LlmClient $client) {}
|
||||
*
|
||||
* @throws ExtractionFailed
|
||||
*/
|
||||
public function extract(string $apiKey, InboundMessage $message, Booking $booking): array
|
||||
public function extract(AiAccess $access, InboundMessage $message, Booking $booking): array
|
||||
{
|
||||
return $this->call($apiKey, (string) config('fewo.ai.small_model'), $this->prompt('', $booking), $this->messageText($message), 'medium');
|
||||
return $this->call($access, $access->smallModel, $this->prompt('', $booking), $this->messageText($message), 'medium');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,9 +32,9 @@ public function extract(string $apiKey, InboundMessage $message, Booking $bookin
|
||||
*
|
||||
* @throws ExtractionFailed
|
||||
*/
|
||||
public function review(string $apiKey, InboundMessage $message, Booking $booking, array $first): array
|
||||
public function review(AiAccess $access, InboundMessage $message, Booking $booking, array $first): array
|
||||
{
|
||||
return $this->call($apiKey, (string) config('fewo.ai.review_model'), $this->prompt('-review', $booking, ['first_extraction' => json_encode($first, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]), $this->messageText($message), 'high');
|
||||
return $this->call($access, $access->reviewModel, $this->prompt('-review', $booking, ['first_extraction' => json_encode($first, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]), $this->messageText($message), 'high');
|
||||
}
|
||||
|
||||
public static function promptVersion(): string
|
||||
@@ -87,13 +88,13 @@ public static function schema(): array
|
||||
/**
|
||||
* @return array{data: array{facts: list<array{field: string, value: string, evidence: string, confidence: float|int}>, change_requests: list<array{field: string, value: string, evidence: string}>, intent: string, uncertainties: list<string>}, model: string}
|
||||
*/
|
||||
private function call(string $apiKey, string $model, string $system, string $text, string $effort): array
|
||||
private function call(AiAccess $access, string $model, string $system, string $text, string $effort): array
|
||||
{
|
||||
$schema = self::schema();
|
||||
$lastError = null;
|
||||
// One repetition when the answer does not fit the schema, then the message goes to the landlord.
|
||||
for ($attempt = 1; $attempt <= 2; $attempt++) {
|
||||
$result = $this->client->structured($apiKey, $model, $system, $text, $schema, $effort);
|
||||
$result = $this->client->structured($access, $model, $system, $text, $schema, $effort);
|
||||
$lastError = $this->violation($result['data'], $schema);
|
||||
if ($lastError === null) {
|
||||
return ['data' => $result['data'], 'model' => $result['model']];
|
||||
|
||||
Reference in new issue
Block a user