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

Add Citations to Django app #641

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

gecBurton
Copy link
Collaborator

@gecBurton gecBurton commented Jun 24, 2024

Context

Although the core-api returns citations, we don't currently record or store these in Django. It might be useful to do this for 2 reasons:

  • to show users more precise sources (which may help them improve prompting)
  • to help us diagnose response issues.

Changes proposed in this pull request

  • Adds a Citation model to the django app
  • Populates this from the streaming chat request and response
  • Makes the Citation visible in Django Admin

To follow in a later PR

  • Implementing this for non-streaming chat
  • Making Citations visible to users

Guidance to review

Try some RAG chats locally; take a look in Django Admin for the Citation records.

Relevant links

https://technologyprogramme.atlassian.net/browse/REDBOX-367

Things to check

  • I have added any new ENV vars in all deployed environments
  • I have tested any code added or changed
  • I have run integration tests

@brunns brunns force-pushed the revert-640-revert-564-feature/capture-chunks branch from 7aaf874 to 154ea96 Compare June 24, 2024 15:53
@rachaelcodes rachaelcodes force-pushed the revert-640-revert-564-feature/capture-chunks branch 6 times, most recently from 1229760 to 3628025 Compare June 26, 2024 07:43
gecBurton and others added 5 commits June 27, 2024 08:41
Move all database activity into @database_sync_to_async  methods.
linting

update migration numbers

update poetry.lock
@rachaelcodes rachaelcodes force-pushed the revert-640-revert-564-feature/capture-chunks branch from 3628025 to a78d268 Compare June 27, 2024 08:36
@rachaelcodes rachaelcodes changed the title Feature/capture chunks Feature/capture Citations Jun 27, 2024
@rachaelcodes rachaelcodes changed the title Feature/capture Citations Add Citations to Django app Jun 27, 2024
Copy link
Contributor

@brunns brunns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending the integration tests you have running.



@pytest.mark.django_db()
def test_0019_remove_chatmessage_source_files_textchunk_and_more(migrator):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

World's tiniest nitpick.

Suggested change
def test_0019_remove_chatmessage_source_files_textchunk_and_more(migrator):
def test_0020_remove_chatmessage_source_files_textchunk_and_more(migrator):

@rachaelcodes rachaelcodes merged commit 668e43e into main Jun 27, 2024
3 checks passed
@rachaelcodes rachaelcodes deleted the revert-640-revert-564-feature/capture-chunks branch June 27, 2024 09:33
Citation.objects.create(chat_message=chat_message, file=file, text=doc.page_content)
if sources:
for file, citations in sources:
for citation in citations:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic, good spot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants