add proper citation handling

This commit is contained in:
pablodanswer 2025-02-03 13:57:05 -08:00 committed by Evan Lohn
parent eb227c0acc
commit cb85be41b1
3 changed files with 10 additions and 7 deletions

View File

@ -10,7 +10,6 @@ from onyx.auth.users import current_user
from onyx.auth.users import is_user_admin
from onyx.configs.constants import KV_REINDEX_KEY
from onyx.configs.constants import NotificationType
from onyx.db.engine import get_current_tenant_id
from onyx.db.engine import get_session
from onyx.db.models import User
from onyx.db.notification import create_notification
@ -43,7 +42,6 @@ def put_settings(
def fetch_settings(
user: User | None = Depends(current_user),
db_session: Session = Depends(get_session),
tenant_id: str | None = Depends(get_current_tenant_id),
) -> UserSettings:
"""Settings and notifications are stuffed into this single endpoint to reduce number of
Postgres calls"""

View File

@ -142,6 +142,11 @@ export const AgenticMessage = ({
}
}
processed = processed.replace(/\[([QD])(\d+)\]/g, (match, type, number) => {
const citationNumber = parseInt(number, 10);
return `[[${type}${citationNumber}]]()`;
});
processed = processed.replace(/\{\{(\d+)\}\}/g, (match, p1) => {
const citationNumber = parseInt(p1, 10);
return `[[${citationNumber}]]()`;
@ -158,7 +163,6 @@ export const AgenticMessage = ({
const [isViewingInitialAnswer, setIsViewingInitialAnswer] = useState(true);
const [canShowResponse, setCanShowResponse] = useState(isComplete);
const [isPulsing, setIsPulsing] = useState(false);
const [isRegenerateHovered, setIsRegenerateHovered] = useState(false);
const [isRegenerateDropdownVisible, setIsRegenerateDropdownVisible] =
useState(false);

View File

@ -139,15 +139,16 @@ const SubQuestionDisplay: React.FC<{
return preprocessLaTeX(content);
}
}
// Add newlines after ]] or ) if there's text immediately following
content = content.replace(/(\]\]|\))((?!\s|\n|\[|\(|$).)/g, "$1\n$2");
// Turn {{number}} into citation in content
content = content.replace(/\[([QD])(\d+)\]/g, (match, type, number) => {
const citationNumber = parseInt(number, 10);
return `[[${type}${citationNumber}]]()`;
});
content = content.replace(/\{\{(\d+)\}\}/g, (match, p1) => {
const citationNumber = parseInt(p1, 10);
return `[[${citationNumber}]]()`;
});
// Add () after ]] if not present
content = content.replace(/\]\](?!\()/g, "]]()");
return (