|
3 | 3 | from datetime import date |
4 | 4 | from os import listdir, remove as remove_file, makedirs |
5 | 5 | from os.path import dirname, isfile, isdir |
6 | | -from typing import Optional |
7 | | -from ovos_plugin_manager.templates.solvers import QuestionSolver |
| 6 | +from typing import Dict, Optional, List, Any, Tuple |
| 7 | + |
| 8 | +from ovos_plugin_manager.templates.agents import RetrievalEngine |
8 | 9 | from ovos_utils.log import LOG |
9 | 10 | from ovos_utils.xdg_utils import xdg_data_home |
10 | 11 |
|
@@ -94,31 +95,29 @@ def shutdown(self): |
94 | 95 | self.kernel.resetBrain() # Manual remove |
95 | 96 |
|
96 | 97 |
|
97 | | -class AIMLSolver(QuestionSolver): |
98 | | - def __init__(self, config=None): |
| 98 | +class AIMLSolver(RetrievalEngine): |
| 99 | + def __init__(self, config: Optional[Dict[str, Any]] = None): |
99 | 100 | config = config or {"lang": "en-us"} |
100 | 101 | lang = config.get("lang") or "en-us" |
101 | 102 | if lang != "en-us" and lang not in os.listdir(AimlBot.XDG_PATH): |
102 | | - config["lang"] = lang = "en-us" |
103 | | - super().__init__(config, internal_lang=lang, enable_tx=True, priority = 95) |
104 | | - self.brain = AimlBot(lang) |
| 103 | + config["lang"] = "en-us" |
| 104 | + super().__init__(config) |
| 105 | + self.brain = AimlBot(self.config.get("lang")) |
105 | 106 | self.brain.load_brain() |
106 | 107 |
|
107 | | - def get_spoken_answer(self, query: str, |
108 | | - lang: Optional[str] = None, |
109 | | - units: Optional[str] = None) -> Optional[str]: |
| 108 | + def query(self, query: str, lang: Optional[str] = None, k: int = 3) -> List[Tuple[str, float]]: |
110 | 109 | """ |
111 | | - Obtain the spoken answer for a given query. |
| 110 | + Searches the knowledge base for relevant documents or data. |
112 | 111 |
|
113 | 112 | Args: |
114 | | - query (str): The query text. |
115 | | - lang (Optional[str]): Optional language code. Defaults to None. |
116 | | - units (Optional[str]): Optional units for the query. Defaults to None. |
| 113 | + query: The search string. |
| 114 | + lang: BCP-47 language code. |
| 115 | + k: The maximum number of results to return. |
117 | 116 |
|
118 | 117 | Returns: |
119 | | - str: The spoken answer as a text response. |
| 118 | + List of tuples (content, score) for the top k matches. |
120 | 119 | """ |
121 | | - return self.brain.ask(query) |
| 120 | + return [(self.brain.ask(query), 0.5)] |
122 | 121 |
|
123 | 122 |
|
124 | 123 | if __name__ == "__main__": |
|
0 commit comments