haystack/rest_api/schema.py
Sara Zan a59bca3661
Apply black formatting (#2115)
* Testing black on ui/

* Applying black on docstores

* Add latest docstring and tutorial changes

* Create a single GH action for Black and docs to reduce commit noise to the minimum, slightly refactor the OpenAPI action too

* Remove comments

* Relax constraints on pydoc-markdown

* Split temporary black from the docs. Pydoc-markdown was obsolete and needs a separate PR to upgrade

* Fix a couple of bugs

* Add a type: ignore that was missing somehow

* Give path to black

* Apply Black

* Apply Black

* Relocate a couple of type: ignore

* Update documentation

* Make Linux CI run after applying Black

* Triggering Black

* Apply Black

* Remove dependency, does not work well

* Remove manually double trailing commas

* Update documentation

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2022-02-03 13:43:18 +01:00

52 lines
1.2 KiB
Python

from typing import Dict, List, Optional, Union, Any
from pydantic import BaseModel, Field, Extra
from haystack.schema 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
debug: Optional[bool] = False
class Config:
# Forbid any extra fields in the request to avoid silent failures
extra = Extra.forbid
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: Optional[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]]
debug: Optional[Dict] = Field(None, alias="_debug")