跳转至

Pipeline

labridge.interact.collect.pipeline

labridge.interact.collect.pipeline.acollect_info_from_user(user_id, required_infos, query_str, llm=None) async

This is an asynchronous pipeline to collect information from the user.

PARAMETER DESCRIPTION
user_id

The user id of a Lab member.

TYPE: str

required_infos

The required information.

TYPE: List[CollectingInfoBase]

query_str

The query string to be sent to the user.

TYPE: str

llm

The used LLM.

TYPE: LLM DEFAULT: None

RETURNS DESCRIPTION

Optional[Dict[str, str]]: The collected information.

  • key: The information name.
  • value: The collected information.

If the user aborts the collecting, return None.

Source code in labridge\interact\collect\pipeline.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
async def acollect_info_from_user(
	user_id: str,
	required_infos: List[CollectingInfoBase],
	query_str: str,
	llm: LLM = None,
):
	r"""
	This is an asynchronous pipeline to collect information from the user.

	Args:
		user_id (str): The user id of a Lab member.
		required_infos (List[CollectingInfoBase]): The required information.
		query_str (str): The query string to be sent to the user.
		llm (LLM): The used LLM.

	Returns:
		Optional[Dict[str, str]]:
			The collected information.

			- key: The information name.
			- value: The collected information.

			If the user aborts the collecting, return None.
	"""
	# TODO: Send query_str to User
	print(f"Assistant: {query_str}")
	llm = llm or Settings.llm

	common_info_collector = CommonInfoCollector(
		llm=llm,
		required_infos=required_infos,
	)
	select_info_collector = SelectInfoCollector(
		llm=llm,
		required_infos=required_infos,
	)

	abort = False
	header_sent = False

	while not abort and not select_info_collector.collected:
		query = query_str if not header_sent else None
		abort = await select_info_collector.acollect(user_id=user_id, query_str=query)
		header_sent = True
	select_modify = True
	while not abort and select_modify:
		select_modify, abort = await select_info_collector.amodify(user_id=user_id)

	while not abort and not common_info_collector.collected:
		query = query_str if not header_sent else None
		abort = await common_info_collector.acollect(user_id=user_id, query_str=query)
		header_sent = True
	common_modify = True
	while not abort and common_modify:
		common_modify, abort = await common_info_collector.amodify(user_id=user_id)

	if abort:
		return None

	output_dict = {}
	common_info_dict = common_info_collector.collected_infos
	select_info_dict = select_info_collector.collected_infos
	if common_info_dict is not None:
		output_dict.update(common_info_dict)
	if select_info_dict is not None:
		output_dict.update(select_info_dict)
	return output_dict

labridge.interact.collect.pipeline.collect_info_from_user(user_id, required_infos, query_str, llm=None)

This is a pipeline to collect information from the user.

PARAMETER DESCRIPTION
user_id

The user id of a Lab member.

TYPE: str

required_infos

The required information.

TYPE: List[CollectingInfoBase]

query_str

The query string to be sent to the user.

TYPE: str

llm

The used LLM.

TYPE: LLM DEFAULT: None

RETURNS DESCRIPTION
Optional[Dict[str, str]]

Optional[Dict[str, str]]: The collected information.

  • key: The information name.
  • value: The collected information.

If the user aborts the collecting, return None.

Source code in labridge\interact\collect\pipeline.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
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
def collect_info_from_user(
	user_id: str,
	required_infos: List[CollectingInfoBase],
	query_str: str,
	llm: LLM = None,
) -> Optional[Dict[str, str]]:
	r"""
	This is a pipeline to collect information from the user.

	Args:
		user_id (str): The user id of a Lab member.
		required_infos (List[CollectingInfoBase]): The required information.
		query_str (str): The query string to be sent to the user.
		llm (LLM): The used LLM.

	Returns:
		Optional[Dict[str, str]]:
			The collected information.

			- key: The information name.
			- value: The collected information.

			If the user aborts the collecting, return None.
	"""
	# # TODO: Send query_str to User
	print(f"Assistant: {query_str}")
	llm = llm or Settings.llm

	# for info in required_infos:
	# 	print(info.info_name)

	common_info_collector = CommonInfoCollector(
		llm=llm,
		required_infos=required_infos,
	)
	select_info_collector = SelectInfoCollector(
		llm=llm,
		required_infos=required_infos,
	)

	abort = False
	header_sent = False

	while not abort and not select_info_collector.collected:
		query = query_str if not header_sent else None
		abort = select_info_collector.collect(user_id=user_id, query_str=query)
		header_sent = True
	select_modify = True
	while not abort and select_modify:
		select_modify, abort = select_info_collector.modify(user_id=user_id)

	while not abort and not common_info_collector.collected:
		query = query_str if not header_sent else None
		abort = common_info_collector.collect(user_id=user_id, query_str=query)
		header_sent = True
	common_modify = True
	while not abort and common_modify:
		common_modify, abort = common_info_collector.modify(user_id=user_id)

	if abort:
		return None

	output_dict = {}
	common_info_dict = common_info_collector.collected_infos
	select_info_dict = select_info_collector.collected_infos
	if common_info_dict is not None:
		output_dict.update(common_info_dict)
	if select_info_dict is not None:
		output_dict.update(select_info_dict)
	return output_dict