mirror of
				https://github.com/deepset-ai/haystack.git
				synced 2025-10-31 09:49:48 +00:00 
			
		
		
		
	 3d58e81b5e
			
		
	
	
		3d58e81b5e
		
			
		
	
	
	
	
		
			
			* test pydantic dataclasses * Add latest docstring and tutorial changes * enable pydantic mypy plugin * switch to pydentic dataclasses and implement custom to_json from_json * clean up Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from typing import Dict, List, Optional, Union, Any
 | |
| from pydantic import BaseModel, Field
 | |
| from haystack import Answer, Document, Label, Span
 | |
| from pydantic import BaseConfig
 | |
| from pydantic.dataclasses import dataclass as pydantic_dataclass
 | |
| 
 | |
| try:
 | |
|     from typing import Literal
 | |
| except ImportError:
 | |
|     from typing_extensions import Literal #type: ignore
 | |
| 
 | |
| BaseConfig.arbitrary_types_allowed = True
 | |
| 
 | |
| 
 | |
| class QueryRequest(BaseModel):
 | |
|     query: str
 | |
|     params: Optional[dict] = None
 | |
| 
 | |
| 
 | |
| class FilterRequest(BaseModel):
 | |
|     filters: Optional[Dict[str, Optional[Union[str, List[str]]]]] = None
 | |
| 
 | |
| 
 | |
| 
 | |
| @pydantic_dataclass
 | |
| class AnswerSerialized(Answer):
 | |
|     context: Optional[str] = None
 | |
| 
 | |
| @pydantic_dataclass
 | |
| class DocumentSerialized(Document):
 | |
|     content: str
 | |
|     embedding: List[float]
 | |
| 
 | |
| @pydantic_dataclass
 | |
| class LabelSerialized(Label):
 | |
|     document: DocumentSerialized
 | |
|     answer: Optional[AnswerSerialized] = None
 | |
| 
 | |
| 
 | |
| class QueryResponse(BaseModel):
 | |
|     query: str
 | |
|     answers: List[AnswerSerialized]
 | |
|     documents: Optional[List[DocumentSerialized]]
 | |
| 
 |