-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Bug]: API method /chat/{chat_id}/question is broken in 0.0.300 #3096
Comments
Hello, @wonderu! I'm here to help you with any bugs, questions, or contributions. Let's tackle this together! A similar issue was reported and resolved in a closed issue: Issue #952. The problem was fixed by a pull request: fix(chatMessages): Fix error on answering question [1]. The Here is an example of how you might define a from pydantic import BaseModel
from typing import Any, Dict
class Document(BaseModel):
id: str
content: str
# Add other fields as necessary
def to_dict(self) -> Dict[str, Any]:
return {
"id": self.id,
"content": self.content,
# Convert other fields to a serializable format
}
# Example usage in the endpoint
@chat_router.post("/chat/{chat_id}/question", dependencies=[Depends(AuthBearer())], tags=["Chat"])
async def create_question_handler(
request: Request,
chat_question: ChatQuestion,
chat_id: UUID,
current_user: UserIdentityDep,
chat_service: ChatServiceDep,
model_service: ModelServiceDep,
brain_id: Annotated[UUID | None, Query()] = None,
):
# Your existing logic here...
try:
# Your existing logic here...
chat_answer = await service.generate_answer(chat_question.question)
# Ensure the chat_answer is serializable
if isinstance(chat_answer, Document):
chat_answer = chat_answer.to_dict()
return chat_answer
except AssertionError:
raise HTTPException(
status_code=422,
detail="unprocessable entity",
)
except HTTPException as e:
raise e Additionally, ensure that the # Example usage in the ChatLLMService class
def save_answer(self, question: str, answer: ParsedRAGResponse):
logger.info(
f"Saving answer for chat {self.chat_id} with model {self.model_to_use}"
)
logger.info(answer)
return self.chat_service.update_chat_history(
CreateChatHistory(
**{
"chat_id": self.chat_id,
"user_message": question,
"assistant": answer.answer,
"brain_id": None,
"prompt_id": None,
"metadata": answer.metadata.model_dump() if answer.metadata else {},
}
)
) By ensuring that all objects returned in the response are serializable, you can resolve the |
duplicated #3082 |
I still got error from rag_service.py |
What happened?
Send request
curl -X 'POST' \ 'https://api.quivr.app/chat/<chat_id>/question?brain_id=<brain_id>' \ -H 'accept: application/json' \ -H 'Authorization: Bearer <token>' \ -H 'Content-Type: application/json' \ -d '{ "question": "what do you know?", "brain_id": "<brain_id>" }'
Got
500 Internal Server Error
The problem is in https://github.com/QuivrHQ/quivr/blob/main/backend/api/quivr_api/modules/chat/repository/chats.py#L84: system can't serialize Document object
Relevant log output
No response
Twitter / LinkedIn details
No response
The text was updated successfully, but these errors were encountered: