Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit ffd13f3

Browse files
authored
Merge pull request #77 from mindvalley/fix/ignore-if-missing-field-employee-context
Return None if field is missing in Airtable record
2 parents 408954b + 2adb9cf commit ffd13f3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

backend/danswer/chat/process_message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def stream_chat_message_objects(
282282
user_id = user.id if user is not None else None
283283

284284
user_email = user.email if user is not None else None
285-
285+
286286
chat_session = get_chat_session_by_id(
287287
chat_session_id=new_msg_req.chat_session_id,
288288
user_id=user_id,

backend/danswer/prompts/prompt_utils.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44

55
import redis
66
from danswer.chat.models import LlmDoc
7-
from danswer.configs.app_configs import AIRTABLE_API_TOKEN
8-
from danswer.configs.app_configs import AIRTABLE_EMPLOYEE_BASE_ID
9-
from danswer.configs.app_configs import AIRTABLE_EMPLOYEE_TABLE_NAME_OR_ID
10-
from danswer.configs.app_configs import REDIS_DB_NUMBER
11-
from danswer.configs.app_configs import REDIS_HOST
12-
from danswer.configs.app_configs import REDIS_PORT
7+
from danswer.configs.app_configs import (
8+
AIRTABLE_API_TOKEN,
9+
AIRTABLE_EMPLOYEE_BASE_ID,
10+
AIRTABLE_EMPLOYEE_TABLE_NAME_OR_ID,
11+
REDIS_DB_NUMBER,
12+
REDIS_HOST,
13+
REDIS_PORT,
14+
)
1315
from danswer.configs.chat_configs import LANGUAGE_HINT
1416
from danswer.configs.constants import DocumentSource
1517
from danswer.db.models import Prompt
1618
from danswer.llm.answering.models import PromptConfig
17-
from danswer.prompts.chat_prompts import ADDITIONAL_INFO
18-
from danswer.prompts.chat_prompts import CITATION_REMINDER
19+
from danswer.prompts.chat_prompts import ADDITIONAL_INFO, CITATION_REMINDER
1920
from danswer.prompts.constants import CODE_BLOCK_PAT
2021
from danswer.search.models import InferenceChunk
2122
from danswer.utils.logger import setup_logger
@@ -85,7 +86,15 @@ def add_employee_context_to_prompt(prompt_str: str, user_email: str) -> str:
8586
if "fields" in employee and "MV Email" in employee["fields"]:
8687
if employee["fields"]["MV Email"] == user_email:
8788
logger.info(f"Employee found: {employee['fields']['Preferred Name']}")
88-
employee_context = f"My Name: {employee['fields']['Preferred Name']}\nMy Title: {employee['fields']['Job Role']}\nMy City Office: {employee['fields']['City Office']}\nMy Division: {employee['fields']['Import: Division']}\nMy Manager: {employee['fields']['Reports To']}\nMy Department: {employee['fields']['Import: Department']}\nMy Employment Status: {employee['fields']['Employment Status']}"
89+
employee_context = (
90+
f"My Name: {employee['fields'].get('Preferred Name', None)}\n"
91+
f"My Title: {employee['fields'].get('Job Role', None)}\n"
92+
f"My City Office: {employee['fields'].get('City Office', None)}\n"
93+
f"My Division: {employee['fields'].get('Import: Division', None)}\n"
94+
f"My Manager: {employee['fields'].get('Reports To', None)}\n"
95+
f"My Department: {employee['fields'].get('Import: Department', None)}\n"
96+
f"My Employment Status: {employee['fields'].get('Employment Status', None)}"
97+
)
8998

9099
# Store the employee context in Redis with a TTL of 30 days
91100
redis_client.setex(user_email, 7 * 24 * 60 * 60, employee_context)

0 commit comments

Comments
 (0)