feat(nordagpt): inject user identity into AI system prompt — personalized greetings and context
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cd1de6fe4b
commit
4ee4165f85
@ -264,6 +264,20 @@ def chat_send_message(conversation_id):
|
||||
if exceeded:
|
||||
return jsonify({'success': False, **limit_msg}), 429
|
||||
|
||||
# Build user context for AI personalization
|
||||
user_context = {
|
||||
'user_id': current_user.id,
|
||||
'user_name': current_user.name,
|
||||
'user_email': current_user.email,
|
||||
'company_name': current_user.company.name if current_user.company else None,
|
||||
'company_id': current_user.company.id if current_user.company else None,
|
||||
'company_category': current_user.company.category.name if current_user.company and current_user.company.category else None,
|
||||
'company_role': current_user.company_role or 'MEMBER',
|
||||
'is_norda_member': current_user.is_norda_member,
|
||||
'chamber_role': current_user.chamber_role,
|
||||
'member_since': current_user.created_at.strftime('%Y-%m-%d') if current_user.created_at else None,
|
||||
}
|
||||
|
||||
# Map model choice to actual model name and thinking level
|
||||
model_map = {
|
||||
'flash': '3-flash', # Gemini 3 Flash - 10K RPD, thinking mode
|
||||
@ -280,7 +294,8 @@ def chat_send_message(conversation_id):
|
||||
conversation_id=conversation_id,
|
||||
user_message=message,
|
||||
user_id=current_user.id,
|
||||
thinking_level=thinking_map.get(model_choice, 'high')
|
||||
thinking_level=thinking_map.get(model_choice, 'high'),
|
||||
user_context=user_context
|
||||
)
|
||||
|
||||
# Get actual cost from response
|
||||
|
||||
@ -165,7 +165,8 @@ class NordaBizChatEngine:
|
||||
conversation_id: int,
|
||||
user_message: str,
|
||||
user_id: int,
|
||||
thinking_level: str = 'high'
|
||||
thinking_level: str = 'high',
|
||||
user_context: Optional[Dict[str, Any]] = None
|
||||
) -> AIChatMessage:
|
||||
"""
|
||||
Send message and get AI response
|
||||
@ -240,7 +241,8 @@ class NordaBizChatEngine:
|
||||
context,
|
||||
user_message,
|
||||
user_id=user_id,
|
||||
thinking_level=thinking_level
|
||||
thinking_level=thinking_level,
|
||||
user_context=user_context
|
||||
)
|
||||
|
||||
# Calculate metrics for per-message tracking in AIChatMessage table
|
||||
@ -892,7 +894,8 @@ class NordaBizChatEngine:
|
||||
context: Dict[str, Any],
|
||||
user_message: str,
|
||||
user_id: Optional[int] = None,
|
||||
thinking_level: str = 'high'
|
||||
thinking_level: str = 'high',
|
||||
user_context: Optional[Dict[str, Any]] = None
|
||||
) -> str:
|
||||
"""
|
||||
Query Gemini AI with full company database context
|
||||
@ -919,7 +922,27 @@ class NordaBizChatEngine:
|
||||
gbp_audits_count = len(context.get('gbp_audits', []))
|
||||
seo_audits_count = len(context.get('seo_audits', []))
|
||||
|
||||
system_prompt = f"""Jesteś pomocnym asystentem portalu Norda Biznes - katalogu firm zrzeszonych w stowarzyszeniu Norda Biznes z Wejherowa.
|
||||
user_identity = ""
|
||||
if user_context:
|
||||
first_name = user_context.get('user_name', 'Nieznany').split()[0] if user_context.get('user_name') else 'Nieznany'
|
||||
user_identity = f"""
|
||||
# AKTUALNY UŻYTKOWNIK
|
||||
Rozmawiasz z: {user_context.get('user_name', 'Nieznany')}
|
||||
Firma: {user_context.get('company_name', 'brak')} — kategoria: {user_context.get('company_category', 'brak')}
|
||||
Rola w firmie: {user_context.get('company_role', 'MEMBER')}
|
||||
Członek Izby Norda Biznes: {'tak' if user_context.get('is_norda_member') else 'nie'}
|
||||
Rola w Izbie: {user_context.get('chamber_role') or '—'}
|
||||
Na portalu od: {user_context.get('member_since', 'nieznana data')}
|
||||
|
||||
ZASADY PERSONALIZACJI:
|
||||
- Zwracaj się do użytkownika po imieniu ({first_name})
|
||||
- W pierwszej wiadomości konwersacji przywitaj się krótko po imieniu
|
||||
- Na pytania "co wiesz o mnie?" / "kim jestem?" — wypisz powyższe dane + powiązania firmowe z bazy
|
||||
- Uwzględniaj kontekst firmy użytkownika w odpowiedziach
|
||||
- NIE ujawniaj danych technicznych (user_id, company_id, rola systemowa)
|
||||
"""
|
||||
|
||||
system_prompt = user_identity + f"""Jesteś pomocnym asystentem portalu Norda Biznes - katalogu firm zrzeszonych w stowarzyszeniu Norda Biznes z Wejherowa.
|
||||
|
||||
📊 MASZ DOSTĘP DO BAZY WIEDZY:
|
||||
- Liczba firm: {context['total_companies']}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user