Chat Routes
This module defines the API routes for the chat functionality of the chatbot.
- class app.api.chat_routes.ChatRequest(*, message: Annotated[str, MinLen(min_length=1), MaxLen(max_length=1000)])[source]
Bases:
BaseModel
Model for chat request.
- Parameters:
message – The user’s input message, with length constraints.
- message: str
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'message': FieldInfo(annotation=str, required=True, metadata=[MinLen(min_length=1), MaxLen(max_length=1000)])}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class app.api.chat_routes.ConversationHistory(*, history: List[Tuple[str, str]], context_info: Dict[str, int] | None = None)[source]
Bases:
BaseModel
Model for conversation history with context information.
- Parameters:
history – A list of tuples containing the conversation history.
context_info – A dictionary with information about the conversation context.
- context_info: Dict[str, int] | None
- history: List[Tuple[str, str]]
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'context_info': FieldInfo(annotation=Union[Dict[str, int], NoneType], required=False, default=None), 'history': FieldInfo(annotation=List[Tuple[str, str]], required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- class app.api.chat_routes.ErrorResponse(*, detail: str)[source]
Bases:
BaseModel
Model for error responses.
- Parameters:
detail – A string describing the error.
- detail: str
- model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[dict[str, FieldInfo]] = {'detail': FieldInfo(annotation=str, required=True)}
Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].
This replaces Model.__fields__ from Pydantic V1.
- async app.api.chat_routes.chat(request: ChatRequest, chat_service: ChatService = Depends(get_chat_service))[source]
Endpoint for processing a chat message.
- Parameters:
request – The ChatRequest containing the user’s message.
chat_service – An instance of ChatService, injected as a dependency.
- Returns:
A ChatResponse containing the AI’s response.
- Raises:
HTTPException – If the message is empty or an error occurs during processing.
- app.api.chat_routes.clear_conversation(chat_service: ChatService = Depends(get_chat_service))[source]
Endpoint for clearing the conversation history.
- Parameters:
chat_service – An instance of ChatService, injected as a dependency.
- Returns:
A Response with a 204 No Content status code on success.
- Raises:
HTTPException – If an error occurs while clearing the conversation.
- app.api.chat_routes.get_chat_service()[source]
Dependency injection function to get the ChatService instance.
- Returns:
An instance of ChatService.
- async app.api.chat_routes.get_conversation(include_context: bool | None = Query(None), chat_service: ChatService = Depends(get_chat_service))[source]
Endpoint for retrieving the conversation history and optionally context information.
- Parameters:
include_context – If True, includes context information in the response.
chat_service – An instance of ChatService, injected as a dependency.
- Returns:
A dictionary containing the conversation history and optionally context info.
- Raises:
HTTPException – If an error occurs while retrieving the conversation history.