searxng/searx/answerers/models.py
Grant Lanham fed105b09e Implement models for searx/answerers
sort froms

Import List from typing to support Python 3.8

Use SearchQuery model

Remove list for List

use Dict instead of dict

Use RawTextQuery instead of SearchQuery, type a dict, and remove unecessary str() method in webapp

improve docstring, remove test code

Implement a BaseQuery class and use that, improve answerer tests based on updated types

Add back sys

fix new linting issues

add space

Update answerer.py - use dict

use future annotations

use BaseQuery for RawTextQuery
2024-03-19 19:54:13 -04:00

38 lines
1,019 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring
from __future__ import annotations
from typing import TypedDict, Tuple
from abc import abstractmethod, ABC
from searx.search.models import BaseQuery
class AnswerDict(TypedDict):
"""The result of a given answer response"""
answer: str
class AnswerSelfInfoDict(TypedDict):
"""The information about the AnswerModule"""
name: str
description: str
examples: list[str]
class AnswerModule(ABC):
"""A module which returns possible answers for auto-complete requests"""
@property
@abstractmethod
def keywords(self) -> Tuple[str]:
"""Keywords which will be used to determine if the answer should be called"""
@abstractmethod
def answer(self, query: BaseQuery) -> list[AnswerDict]:
"""From a query, get the possible auto-complete answers"""
@abstractmethod
def self_info(self) -> AnswerSelfInfoDict:
"""Provides information about the AnswerModule"""