haystack/rest_api/schema.py
Sara Zan 40328a57b6
Introduce pylint & other improvements on the CI (#2130)
* Make mypy check also ui and rest_api, fix ui

* Remove explicit type packages from extras, mypy now downloads them

* Make pylint and mypy run on every file except tests

* Rename tasks

* Change cache key

* Fix mypy errors in rest_api

* Normalize python versions to avoid cache misses

* Add all exclusions to make pylint pass

* Run mypy on rest_api and ui as well

* test if installing the package really changes outcome

* Comment out installation of packages

* Experiment: randomize tests

* Add fallback installation steps on cache misses

* Remove randomization

* Add comment on cache

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

52 lines
1.3 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]] # type: ignore
@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")