跳转至

Common info

labridge.interact.collect.types.common_info

labridge.interact.collect.types.common_info.CollectingCommonInfo

Bases: CollectingBatchInfoBase

This class defines the common information to be collected from the user. The common information can be collected in batch mode.

PARAMETER DESCRIPTION
info_name

The name of the information to be collected.

TYPE: str

info_description

The description of the information to be collected.

TYPE: str

Source code in labridge\interact\collect\types\common_info.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
class CollectingCommonInfo(CollectingBatchInfoBase):
	r"""
	This class defines the common information to be collected from the user.
	The common information can be collected in batch mode.

	Args:
		info_name (str): The name of the information to be collected.
		info_description (str): The description of the information to be collected.
	"""
	def __init__(
		self,
		info_name: str,
		info_description: str,
	):
		self.info_dict = {
			CollectPromptKeys.required_infos_key: {info_name: info_description}
		}
		super().__init__(
			info_name=info_name,
			info_description=info_description,
			info_type=CollectingInfoType.COMMON,
		)

	def insert_info(self, info: CollectingInfoBase):
		r"""
		Insert a new CommonInfo to current one.

		Args:
			info (CollectingInfoBase): The new CollectingCommonInfo.

		Returns:
			None.
		"""
		self.info_dict[CollectPromptKeys.required_infos_key].update(
			{info.info_name: info.info_description}
		)

	def _collected(self) -> bool:
		r""" Whether all information is collected. """
		return len(self.collecting_keys) == 0

	def _required_infos(self) -> Dict[str, str]:
		r""" Return the required information names and descriptions. """
		return self.info_dict[CollectPromptKeys.required_infos_key]

	def update_collected_info(self, collected_info_dict: Dict[str, str]):
		r""" Update the collected information. """
		for key in collected_info_dict.keys():
			if key in self.required_infos:
				self._collected_infos[key] = collected_info_dict[key]

	def _collecting_keys(self) -> List[str]:
		r""" Return the information names to be collected currently. """
		collecting_keys = set(self.required_infos.keys()) - set(self._collected_infos.keys())
		return list(collecting_keys)

	def info_content(self) -> Iterator[Dict[str, str]]:
		r""" Yield a batch of information names and descriptions to the LLM for extraction """
		info_keys = self.collecting_keys
		info_num = len(info_keys)
		start = 0
		while start < info_num:
			batch_keys = info_keys[start: start + COMMON_COLLECT_BATCH_SIZE]
			start += COMMON_COLLECT_BATCH_SIZE
			batch_info = {key: self.required_infos[key] for key in batch_keys}
			yield {
				CollectPromptKeys.required_infos_key: json.dumps(batch_info),
				CollectPromptKeys.extra_info_key: DEFAULT_EXTRA_INFO,
			}

	def modify_info_content(self) -> Iterator[Dict[str, str]]:
		r""" Yield a batch of information names, descriptions and collected content to the LLM for modification. """
		info_keys = list(self.collected_infos.keys())
		info_num = len(info_keys)
		start = 0
		while start < info_num:
			batch_keys = info_keys[start: start + COMMON_COLLECT_BATCH_SIZE]
			start += COMMON_COLLECT_BATCH_SIZE
			batch_info = {key: self.required_infos[key] for key in batch_keys}
			batch_collected_info = {key: self.collected_infos[key] for key in batch_keys}
			yield {
				ModifyPromptKeys.required_infos_key: json.dumps(batch_info),
				ModifyPromptKeys.collected_infos_key: json.dumps(batch_collected_info),
				ModifyPromptKeys.extra_info_key: DEFAULT_EXTRA_INFO,
			}

labridge.interact.collect.types.common_info.CollectingCommonInfo.info_content()

Yield a batch of information names and descriptions to the LLM for extraction

Source code in labridge\interact\collect\types\common_info.py
77
78
79
80
81
82
83
84
85
86
87
88
89
def info_content(self) -> Iterator[Dict[str, str]]:
	r""" Yield a batch of information names and descriptions to the LLM for extraction """
	info_keys = self.collecting_keys
	info_num = len(info_keys)
	start = 0
	while start < info_num:
		batch_keys = info_keys[start: start + COMMON_COLLECT_BATCH_SIZE]
		start += COMMON_COLLECT_BATCH_SIZE
		batch_info = {key: self.required_infos[key] for key in batch_keys}
		yield {
			CollectPromptKeys.required_infos_key: json.dumps(batch_info),
			CollectPromptKeys.extra_info_key: DEFAULT_EXTRA_INFO,
		}

labridge.interact.collect.types.common_info.CollectingCommonInfo.insert_info(info)

Insert a new CommonInfo to current one.

PARAMETER DESCRIPTION
info

The new CollectingCommonInfo.

TYPE: CollectingInfoBase

RETURNS DESCRIPTION

None.

Source code in labridge\interact\collect\types\common_info.py
44
45
46
47
48
49
50
51
52
53
54
55
56
def insert_info(self, info: CollectingInfoBase):
	r"""
	Insert a new CommonInfo to current one.

	Args:
		info (CollectingInfoBase): The new CollectingCommonInfo.

	Returns:
		None.
	"""
	self.info_dict[CollectPromptKeys.required_infos_key].update(
		{info.info_name: info.info_description}
	)

labridge.interact.collect.types.common_info.CollectingCommonInfo.modify_info_content()

Yield a batch of information names, descriptions and collected content to the LLM for modification.

Source code in labridge\interact\collect\types\common_info.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def modify_info_content(self) -> Iterator[Dict[str, str]]:
	r""" Yield a batch of information names, descriptions and collected content to the LLM for modification. """
	info_keys = list(self.collected_infos.keys())
	info_num = len(info_keys)
	start = 0
	while start < info_num:
		batch_keys = info_keys[start: start + COMMON_COLLECT_BATCH_SIZE]
		start += COMMON_COLLECT_BATCH_SIZE
		batch_info = {key: self.required_infos[key] for key in batch_keys}
		batch_collected_info = {key: self.collected_infos[key] for key in batch_keys}
		yield {
			ModifyPromptKeys.required_infos_key: json.dumps(batch_info),
			ModifyPromptKeys.collected_infos_key: json.dumps(batch_collected_info),
			ModifyPromptKeys.extra_info_key: DEFAULT_EXTRA_INFO,
		}

labridge.interact.collect.types.common_info.CollectingCommonInfo.update_collected_info(collected_info_dict)

Update the collected information.

Source code in labridge\interact\collect\types\common_info.py
66
67
68
69
70
def update_collected_info(self, collected_info_dict: Dict[str, str]):
	r""" Update the collected information. """
	for key in collected_info_dict.keys():
		if key in self.required_infos:
			self._collected_infos[key] = collected_info_dict[key]