Chat Interface#
The ChatInterface
is the main interface for the chat service. It defines the core functionality required for a chat service
that can return various types of responses such as:
- Text: Regular text responses streamed chunk by chunk
- References: Source documents used to generate the answer
ragbits.chat.interface.ChatInterface
#
Bases: ABC
Base interface for chat implementations.
This interface defines the core functionality required for a chat service that can return various types of responses such as:
- Text: Regular text responses streamed chunk by chunk
- References: Source documents used to generate the answer
feedback_config
class-attribute
instance-attribute
#
create_text_response
staticmethod
#
Helper method to create a text response.
create_reference
staticmethod
#
Helper method to create a reference response.
Source code in packages/ragbits-chat/src/ragbits/chat/interface/_interface.py
chat
abstractmethod
async
#
chat(message: str, history: ChatFormat | None = None, context: dict | None = None) -> AsyncGenerator[ChatResponse, None]
Process a chat message and yield responses asynchronously.
PARAMETER | DESCRIPTION |
---|---|
message |
The current user message
TYPE:
|
history |
Optional list of previous messages in the conversation
TYPE:
|
context |
Optional context
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
AsyncGenerator[ChatResponse, None]
|
ChatResponse objects containing different types of content: |
AsyncGenerator[ChatResponse, None]
|
|
AsyncGenerator[ChatResponse, None]
|
|
Example
Source code in packages/ragbits-chat/src/ragbits/chat/interface/_interface.py
save_feedback
async
#
Save feedback about a chat message.
PARAMETER | DESCRIPTION |
---|---|
message_id |
The ID of the message
TYPE:
|
feedback |
The type of feedback
TYPE:
|
payload |
The payload of the feedback
TYPE:
|