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

Feature/redbox 200 move sources to a separate field for chat endpoint responses #298

Conversation

gecBurton
Copy link
Collaborator

@gecBurton gecBurton commented May 1, 2024

Context

As a frontend I want the backed to return as much information as possible., i.e. the uuid of the original file.

Changes proposed in this pull request

  • I have extended the ChatResponse to return the full langchain response
  • I have extended the test to check that the original document is returned
  • I have switched to the incremental test approach (thx @wpfl-dbt)

Guidance to review

Relevant links

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

Things to check

models.ManyToManyField(
blank=True, related_name="chat_histories", to="redbox_core.file"
),
models.ManyToManyField(blank=True, related_name="chat_histories", to="redbox_core.file"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is ruff modifying some unrelated files

processing_status = models.CharField(
choices=ProcessingStatusEnum.choices, null=False, blank=False
)
processing_status = models.CharField(choices=ProcessingStatusEnum.choices, null=False, blank=False)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ruff again

@@ -112,7 +112,7 @@ def simple_chat(chat_request: ChatRequest) -> ChatResponse:
return ChatResponse(response_message=ChatMessage(text=response.text, role="ai"))


@chat_app.post("/rag", tags=["chat"], response_model=ChatResponse)
@chat_app.post("/rag", tags=["chat"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the response model need to be returned?

Copy link
Collaborator Author

@gecBurton gecBurton May 1, 2024

Choose a reason for hiding this comment

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

not if it is in the annotation (below). ofc its not doing any harm either, happy to put it back?

Comment on lines 57 to 60
question: str = Field(
description="original question",
examples=["Who is the prime minister?"],
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this? I think it makes things more complicated -- the frontend already has this information because it submitted it.

Copy link
Collaborator Author

@gecBurton gecBurton May 1, 2024

Choose a reason for hiding this comment

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

the frontend knows all of the documents that could have been used in RAG, but not the documents actually used in RAG. The point of this change is that the document references come back in a helpful format rather-than/as-well-as the Sources: <Doc37518e8f-f6af-4f5f-bdcd-49e2f1b65fc1> <Docf36e683f-0f9e-4573-b122-1f90b65d5ad1> text format

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I highlighted too much -- this is a point about the question param. The front end submitted that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ahh, good point. yes lets drop it, its unhelpful

description="original question",
examples=["Who is the prime minister?"],
)
input_documents: Optional[list[InputDocuments]] = Field(
Copy link
Collaborator

@wpfl-dbt wpfl-dbt May 1, 2024

Choose a reason for hiding this comment

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

I've been using LangChain's own Documents class. Is there a reason to roll our own? Pydantic v1 stuff?

ALSO: "input" might be misleading -- down the line we might have lots of file inputs, but the LLM only chooses certain chunks as sources for this response.

Copy link
Collaborator Author

@gecBurton gecBurton May 1, 2024

Choose a reason for hiding this comment

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

we absolutely could use the LangChain Document class but it is very underspecified, i.e. the Matadata is just a dictionary. but... im in two minds here. The point of this PR is to return structured data, however we cant be sure that LangChain is going to do this 🤔 . What do you think @lmwilkigov ?

ALSO: "input" might be misleading -- down the line we might have lots of file inputs, but the LLM only chooses certain chunks as sources for this response.

This is what i was trying to say here but put much better! we could rename the field to input_documents_used ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair play on the Document point! I think Metadata is underspecified because it can contain things like what tools were called by an agent -- it's deliberately a bit open-ended and extendable. If we want to be stricter, cool, it's helpful for the frontend.

On name I'd been going with sources to conceptually align with what it is to the user. I'm not married to it but input* as a word is very unaligned with the frontend cause it'll have passed a bunch of inputs, and this attribute is quite loosely coupled to what they'd have been.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sources sounds good, it is what appears in the text afterall

@gecBurton gecBurton force-pushed the feature/REDBOX-200-move-sources-to-a-separate-field-for-chat-endpoint-responses branch from f1dc9c7 to 55f5685 Compare May 2, 2024 07:29
@gecBurton gecBurton merged commit 41b0a4b into main May 2, 2024
9 checks passed
@gecBurton gecBurton deleted the feature/REDBOX-200-move-sources-to-a-separate-field-for-chat-endpoint-responses branch May 2, 2024 09:47
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