mirror of https://github.com/searxng/searxng
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 RawTextQuerypull/3316/head
parent
e2af3e4970
commit
fed105b09e
@ -0,0 +1 @@
|
||||
3.8.0
|
@ -0,0 +1,38 @@
|
||||
# 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"""
|
Loading…
Reference in New Issue