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

Ability to pass error messages from API to UI #409

Open
nenb opened this issue May 10, 2024 · 2 comments
Open

Ability to pass error messages from API to UI #409

nenb opened this issue May 10, 2024 · 2 comments

Comments

@nenb
Copy link
Contributor

nenb commented May 10, 2024

Feature description

The ability to pass any error message that is raised in the API to the UI. Currently this is not possible as StreamingResponse is used which results in peer closed connection without sending complete message body being raised in the UI for all API errors.

Value and/or benefit

Better user experience eg ability to determine more easily whether an issue is UI or API-related.

Anything else?

No response

@pmeier
Copy link
Member

pmeier commented May 13, 2024

All for it. The message (or chunks in case of streaming) that we are returning always have a role attached to them:

class Message(BaseModel):
id: uuid.UUID = Field(default_factory=uuid.uuid4)
content: str
role: ragna.core.MessageRole

Currently MessageRole.ASSISTANT is hardcoded for this

ragna/ragna/core/_rag.py

Lines 223 to 227 in 3cef0f7

answer = Message(
content=self._run_gen(self.assistant.answer, prompt, sources),
role=MessageRole.ASSISTANT,
sources=sources,
)

We could switch the role to MessageRole.SYSTEM in case we hit an error. With that we could send the error message either instead of the answer or as last chunk when streaming. If we do that, we could make it protocol, i.e. document, that if one receives a system message when one from the assistant is expected, this indicates an error and it should be displayed as such.

Thoughts?

@nenb
Copy link
Contributor Author

nenb commented May 24, 2024

If we do that, we could make it protocol, i.e. document, that if one receives a system message when one from the assistant is expected, this indicates an error and it should be displayed as such.

It seems a little bit complicated/non-standard, but I would be okay with it.

In practice, whenever I hit an error, it always comes from trying to generate the first chunk. If the first chunk is successful, then I don't remember hitting an error (although it's of course possible).

This was the motivation for #410 - test the first chunk, and if there is an error then return a standard 500 response with details. I suspect that this will catch the vast majority of errors, and is what seemed to be recommended by others when I did a quick web-search.

It might be useful for others who only consume the web API (ie don't use our UI) to have the ability to error before starting streaming.

Happy for you to make a decision on how to proceed.

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

No branches or pull requests

2 participants