feat: Add Aktenzeichen utility functions and LangChain xAI service integration
- Implemented utility functions for extracting, validating, and normalizing Aktenzeichen in 'aktenzeichen_utils.py'. - Created LangChainXAIService for integrating LangChain ChatXAI with file search capabilities in 'langchain_xai_service.py'. - Developed VMH xAI Chat Completions API to handle OpenAI-compatible requests with support for Aktenzeichen detection and file search in 'xai_chat_completion_api_step.py'.
This commit is contained in:
110
services/aktenzeichen_utils.py
Normal file
110
services/aktenzeichen_utils.py
Normal file
@@ -0,0 +1,110 @@
|
||||
"""Aktenzeichen-Erkennung und Validation
|
||||
|
||||
Utility functions für das Erkennen, Validieren und Normalisieren von
|
||||
Aktenzeichen im Format '1234/56' oder 'ABC/23'.
|
||||
"""
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
|
||||
# Regex für Aktenzeichen: 1-4 Zeichen (alphanumerisch) + "/" + 2 Ziffern
|
||||
AKTENZEICHEN_REGEX = re.compile(r'^([A-Za-z0-9]{1,4}/\d{2})\s*', re.IGNORECASE)
|
||||
|
||||
|
||||
def extract_aktenzeichen(text: str) -> Optional[str]:
|
||||
"""
|
||||
Extrahiert Aktenzeichen vom Anfang des Textes.
|
||||
|
||||
Pattern: ^[A-Za-z0-9]{1,4}/\d{2}
|
||||
|
||||
Examples:
|
||||
>>> extract_aktenzeichen("1234/56 Was ist der Stand?")
|
||||
"1234/56"
|
||||
>>> extract_aktenzeichen("ABC/23 Frage zum Vertrag")
|
||||
"ABC/23"
|
||||
>>> extract_aktenzeichen("Kein Aktenzeichen hier")
|
||||
None
|
||||
|
||||
Args:
|
||||
text: Eingabetext (z.B. erste Message)
|
||||
|
||||
Returns:
|
||||
Aktenzeichen als String, oder None wenn nicht gefunden
|
||||
"""
|
||||
if not text or not isinstance(text, str):
|
||||
return None
|
||||
|
||||
match = AKTENZEICHEN_REGEX.match(text.strip())
|
||||
return match.group(1) if match else None
|
||||
|
||||
|
||||
def remove_aktenzeichen(text: str) -> str:
|
||||
"""
|
||||
Entfernt Aktenzeichen vom Anfang des Textes.
|
||||
|
||||
Examples:
|
||||
>>> remove_aktenzeichen("1234/56 Was ist der Stand?")
|
||||
"Was ist der Stand?"
|
||||
>>> remove_aktenzeichen("Kein Aktenzeichen")
|
||||
"Kein Aktenzeichen"
|
||||
|
||||
Args:
|
||||
text: Eingabetext mit Aktenzeichen
|
||||
|
||||
Returns:
|
||||
Text ohne Aktenzeichen (whitespace getrimmt)
|
||||
"""
|
||||
if not text or not isinstance(text, str):
|
||||
return text
|
||||
|
||||
return AKTENZEICHEN_REGEX.sub('', text, count=1).strip()
|
||||
|
||||
|
||||
def validate_aktenzeichen(az: str) -> bool:
|
||||
"""
|
||||
Validiert Aktenzeichen-Format.
|
||||
|
||||
Pattern: ^[A-Za-z0-9]{1,4}/\d{2}$
|
||||
|
||||
Examples:
|
||||
>>> validate_aktenzeichen("1234/56")
|
||||
True
|
||||
>>> validate_aktenzeichen("ABC/23")
|
||||
True
|
||||
>>> validate_aktenzeichen("12345/567") # Zu lang
|
||||
False
|
||||
>>> validate_aktenzeichen("1234-56") # Falsches Trennzeichen
|
||||
False
|
||||
|
||||
Args:
|
||||
az: Aktenzeichen zum Validieren
|
||||
|
||||
Returns:
|
||||
True wenn valide, False sonst
|
||||
"""
|
||||
if not az or not isinstance(az, str):
|
||||
return False
|
||||
|
||||
return bool(re.match(r'^[A-Za-z0-9]{1,4}/\d{2}$', az, re.IGNORECASE))
|
||||
|
||||
|
||||
def normalize_aktenzeichen(az: str) -> str:
|
||||
"""
|
||||
Normalisiert Aktenzeichen (uppercase, trim whitespace).
|
||||
|
||||
Examples:
|
||||
>>> normalize_aktenzeichen("abc/23")
|
||||
"ABC/23"
|
||||
>>> normalize_aktenzeichen(" 1234/56 ")
|
||||
"1234/56"
|
||||
|
||||
Args:
|
||||
az: Aktenzeichen zum Normalisieren
|
||||
|
||||
Returns:
|
||||
Normalisiertes Aktenzeichen (uppercase, getrimmt)
|
||||
"""
|
||||
if not az or not isinstance(az, str):
|
||||
return az
|
||||
|
||||
return az.strip().upper()
|
||||
Reference in New Issue
Block a user