跳转至

Query engines

labridge.common.query_engine.query_engines

labridge.common.query_engine.query_engines.SingleQueryEngine

Bases: BaseQueryEngine

A single query engine.

PARAMETER DESCRIPTION
llm

The used LLM.

TYPE: LLM

prompt_tmpl

The prompt template.

TYPE: str

Source code in labridge\common\query_engine\query_engines.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class SingleQueryEngine(BaseQueryEngine):
	r"""
	A single query engine.

	Args:
		llm (LLM): The used LLM.
		prompt_tmpl (str): The prompt template.
	"""
	def __init__(self, llm: LLM, prompt_tmpl: str):
		if llm is not None:
			self.llm = llm
		else:
			self.llm = Settings.llm
		self.prompt_tmpl = prompt_tmpl
		super().__init__(callback_manager=None)

	def _query(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:
		return self.single_query(query_bundle.query_str)

	async def _aquery(self, query_bundle: QueryBundle) -> RESPONSE_TYPE:
		return self.single_query(query_bundle.query_str)

	def _get_prompt_modules(self) -> Dict[str, Any]:
		"""Get prompts."""
		return {}

	def single_query(self, query_str: str) -> Union[RESPONSE_TYPE, str]:
		query = self.prompt_tmpl.format(query_str)
		motivation_str = self.llm.complete(prompt=query)
		motivation = Response(motivation_str.text)
		return motivation