跳转至

Utils

labridge.interact.collect.utils

labridge.interact.collect.utils.acondition_analyze(llm, prompt, condition_true_word, **kwargs) async

Asynchronously choose from two conditions according to the input.

PARAMETER DESCRIPTION
llm

The used LLM.

TYPE: LLM

prompt

The prompt template.

TYPE: PromptTemplate

condition_true_word

The word that the LLM is supposed to output in the True condition.

TYPE: str

**kwargs

DEFAULT: {}

RETURNS DESCRIPTION
bool

True condition or False.

TYPE: bool

Source code in labridge\interact\collect\utils.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
async def acondition_analyze(
	llm: LLM,
	prompt: PromptTemplate,
	condition_true_word: str,
	**kwargs,
) -> bool:
	r"""
	Asynchronously choose from two conditions according to the input.

	Args:
		llm (LLM): The used LLM.
		prompt (PromptTemplate): The prompt template.
		condition_true_word (str): The word that the LLM is supposed to output in the True condition.
		**kwargs:

	Returns:
		bool: True condition or False.
	"""
	llm_response = await llm.apredict(
		prompt=prompt,
		**kwargs,
	)

	llm_str = filter(lambda x: x.isalpha(), [char for char in llm_response])
	llm_str = "".join(llm_str)
	return llm_str == condition_true_word

labridge.interact.collect.utils.condition_analyze(llm, prompt, condition_true_word, **kwargs)

Choose from two conditions according to the input.

PARAMETER DESCRIPTION
llm

The used LLM.

TYPE: LLM

prompt

The prompt template.

TYPE: PromptTemplate

condition_true_word

The word that the LLM is supposed to output in the True condition.

TYPE: str

**kwargs

DEFAULT: {}

RETURNS DESCRIPTION
bool

True condition or False.

TYPE: bool

Source code in labridge\interact\collect\utils.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def condition_analyze(
	llm: LLM,
	prompt: PromptTemplate,
	condition_true_word: str,
	**kwargs,
) -> bool:
	r"""
	Choose from two conditions according to the input.

	Args:
		llm (LLM): The used LLM.
		prompt (PromptTemplate): The prompt template.
		condition_true_word (str): The word that the LLM is supposed to output in the True condition.
		**kwargs:

	Returns:
		bool: True condition or False.
	"""
	llm_response = llm.predict(
		prompt=prompt,
		**kwargs,
	)

	llm_str = filter(lambda x: x.isalpha(), [char for char in llm_response])
	llm_str = "".join(llm_str)
	return llm_str.lower() == condition_true_word.lower()