| 
									
										
										
										
											2022-04-12 16:41:05 +02:00
										 |  |  | from __future__ import annotations | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from typing import Dict, List, Optional, Union | 
					
						
							| 
									
										
										
										
											2021-10-18 14:38:14 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | try: | 
					
						
							|  |  |  |     from typing import Literal | 
					
						
							|  |  |  | except ImportError: | 
					
						
							| 
									
										
										
										
											2022-02-03 13:43:18 +01:00
										 |  |  |     from typing_extensions import Literal  # type: ignore | 
					
						
							| 
									
										
										
										
											2021-10-13 14:23:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:41:05 +02:00
										 |  |  | from pydantic import BaseModel, Field, Extra | 
					
						
							|  |  |  | from pydantic import BaseConfig | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from haystack.schema import Answer, Document, Label | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 18:12:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-13 14:23:23 +02:00
										 |  |  | BaseConfig.arbitrary_types_allowed = True | 
					
						
							| 
									
										
										
										
											2021-10-04 11:21:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 16:41:05 +02:00
										 |  |  | PrimitiveType = Union[str, int, float, bool] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-26 18:12:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 11:21:00 +02:00
										 |  |  | class QueryRequest(BaseModel): | 
					
						
							|  |  |  |     query: str | 
					
						
							|  |  |  |     params: Optional[dict] = None | 
					
						
							| 
									
										
										
										
											2021-11-18 18:13:03 +01:00
										 |  |  |     debug: Optional[bool] = False | 
					
						
							| 
									
										
										
										
											2022-02-03 13:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 18:13:03 +01:00
										 |  |  |     class Config: | 
					
						
							|  |  |  |         # Forbid any extra fields in the request to avoid silent failures | 
					
						
							|  |  |  |         extra = Extra.forbid | 
					
						
							| 
									
										
										
										
											2021-10-04 11:21:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-03 13:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 11:21:00 +02:00
										 |  |  | class FilterRequest(BaseModel): | 
					
						
							| 
									
										
										
										
											2022-04-12 16:41:05 +02:00
										 |  |  |     filters: Optional[Dict[str, Union[PrimitiveType, List[PrimitiveType], Dict[str, PrimitiveType]]]] = None | 
					
						
							| 
									
										
										
										
											2021-10-04 11:21:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 14:38:14 +02:00
										 |  |  | class AnswerSerialized(Answer): | 
					
						
							|  |  |  |     context: Optional[str] = None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-03 13:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 14:38:14 +02:00
										 |  |  | class DocumentSerialized(Document): | 
					
						
							|  |  |  |     content: str | 
					
						
							| 
									
										
										
										
											2022-02-09 18:27:12 +01:00
										 |  |  |     embedding: Optional[List[float]]  # type: ignore | 
					
						
							| 
									
										
										
										
											2021-10-18 14:38:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-03 13:43:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 11:43:26 +01:00
										 |  |  | class LabelSerialized(Label, BaseModel): | 
					
						
							| 
									
										
										
										
											2021-10-18 14:38:14 +02:00
										 |  |  |     document: DocumentSerialized | 
					
						
							|  |  |  |     answer: Optional[AnswerSerialized] = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 11:43:26 +01:00
										 |  |  | class CreateLabelSerialized(BaseModel): | 
					
						
							|  |  |  |     id: Optional[str] = None | 
					
						
							|  |  |  |     query: str | 
					
						
							|  |  |  |     document: DocumentSerialized | 
					
						
							|  |  |  |     is_correct_answer: bool | 
					
						
							|  |  |  |     is_correct_document: bool | 
					
						
							|  |  |  |     origin: Literal["user-feedback", "gold-label"] | 
					
						
							|  |  |  |     answer: Optional[AnswerSerialized] = None | 
					
						
							|  |  |  |     no_answer: Optional[bool] = None | 
					
						
							|  |  |  |     pipeline_id: Optional[str] = None | 
					
						
							|  |  |  |     created_at: Optional[str] = None | 
					
						
							|  |  |  |     updated_at: Optional[str] = None | 
					
						
							|  |  |  |     meta: Optional[dict] = None | 
					
						
							|  |  |  |     filters: Optional[dict] = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class Config: | 
					
						
							|  |  |  |         # Forbid any extra fields in the request to avoid silent failures | 
					
						
							|  |  |  |         extra = Extra.forbid | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 11:21:00 +02:00
										 |  |  | class QueryResponse(BaseModel): | 
					
						
							|  |  |  |     query: str | 
					
						
							| 
									
										
										
										
											2022-02-16 11:10:59 +01:00
										 |  |  |     answers: List[AnswerSerialized] = [] | 
					
						
							|  |  |  |     documents: List[DocumentSerialized] = [] | 
					
						
							| 
									
										
										
										
											2021-11-18 18:13:03 +01:00
										 |  |  |     debug: Optional[Dict] = Field(None, alias="_debug") |