Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedboxState now includes citations #1118

Draft
wants to merge 5 commits into
base: feature/redbox-697-wikipedia-tool
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 67 additions & 65 deletions django_app/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions django_app/redbox_app/redbox_core/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections.abc import Mapping, Sequence
from typing import Any, ClassVar
from uuid import UUID
from itertools import groupby

from channels.db import database_sync_to_async
from channels.generic.websocket import AsyncWebsocketConsumer
Expand Down Expand Up @@ -210,14 +209,14 @@ def save_ai_message(
file=file,
text=citation.page_content,
page_numbers=parse_page_number(citation.metadata.get("page_number")),
source=Citation.Origin.USER_UPLOADED_DOCUMENT
source=Citation.Origin.USER_UPLOADED_DOCUMENT,
)
else:
Citation.objects.create(
chat_message=chat_message,
url=citation.metadata.get("original_resource_ref"),
text=citation.page_content,
source=Citation.Origin(citation.metadata.get("creator_type"))
source=Citation.Origin(citation.metadata.get("creator_type")),
)

if self.metadata:
Expand All @@ -228,7 +227,6 @@ def save_ai_message(
model_name=model,
token_count=token_count,
)

for model, token_count in self.metadata.output_tokens.items():
ChatMessageTokenUse.objects.create(
chat_message=chat_message,
Expand Down Expand Up @@ -275,9 +273,7 @@ async def handle_documents(self, response: list[Document]):
files = File.objects.filter(original_file__in=sources_by_resource_ref.keys())
async for file in files:
await self.send_to_client("source", {"url": str(file.url), "original_file_name": file.original_file_name})
self.citations.append(
(file, sources_by_resource_ref[file.unique_name])
)
self.citations.append((file, sources_by_resource_ref[file.unique_name]))
handled_sources.add(file.unique_name)

additional_sources = [doc for doc in response if doc.metadata["original_resource_ref"] not in handled_sources]
Expand Down
1 change: 1 addition & 0 deletions redbox-core/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
".",
"-v",
"-m not ( ai )"
],
"python.testing.pytestPath": "venv/bin/python -m pytest"
Expand Down
Loading
Loading