跳转至

Set current experiment

labridge.callback.experiment_log.set_current_experiment

labridge.callback.experiment_log.set_current_experiment.SetCurrentExperimentOperation

Bases: CallBackOperationBase

This operation will set a recorded experiment as the user's experiment in progress.

PARAMETER DESCRIPTION
llm

The used LLM.

TYPE: LLM DEFAULT: None

embed_model

The used embedding model.

TYPE: BaseEmbedding DEFAULT: None

verbose

Whether to show the inner progress.

TYPE: bool DEFAULT: False

Source code in labridge\callback\experiment_log\set_current_experiment.py
 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
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
class SetCurrentExperimentOperation(CallBackOperationBase):
	r"""
	This operation will set a recorded experiment as the user's experiment in progress.

	Args:
		llm (LLM): The used LLM.
		embed_model (BaseEmbedding): The used embedding model.
		verbose (bool): Whether to show the inner progress.
	"""
	def __init__(
		self,
		llm: LLM = None,
		embed_model: BaseEmbedding = None,
		verbose: bool = False,
		op_name: str = None,
	):

		llm = llm or Settings.llm
		embed_model = embed_model or Settings.embed_model
		super().__init__(
			llm=llm,
			embed_model=embed_model,
			verbose=verbose,
			op_name=op_name or SetCurrentExperimentOperation.__name__,
		)

	def operation_description(self, **kwargs) -> str:
		r"""
		Return the operation description, this description will be sent to the user for authorization.

		Args:
			user_id (str): The user id of a lab member.
			experiment_name (str): The name of a recorded experiment.
			experiment_duration (str): The duration of the experiment, in a format of "%Hh%Mm%Ss",
				refer to `common.utils.time`.

		Returns:
			str: The operation description.
		"""
		user_id = kwargs["user_id"]
		experiment_name = kwargs["experiment_name"]
		experiment_duration = kwargs["experiment_duration"]

		start_date, start_time = get_time()
		start = str_to_datetime(date_str=start_date, time_str=start_time)
		delta_time = str_to_delta_time(time_str=experiment_duration)
		end = start + delta_time
		end_date, end_time = datetime_to_str(date_time=end)
		op_description = SET_CURRENT_EXPERIMENT_DESCRIPTION.format(
			user_id=user_id,
			experiment_name=experiment_name,
			start_date=start_date,
			start_time=start_time,
			end_date=end_date,
			end_time=end_time,
		)
		return op_description

	def do_operation(self, **kwargs) -> OperationOutputLog:
		r"""
		Execute the operation set the experiment in progress for a user.

		Args:
			user_id (str): The user id of a lab member.
			experiment_name (str): The name of a recorded experiment.
			experiment_duration (str): The duration of the experiment, in a format of "%Hh%Mm%Ss",
				refer to `common.utils.time`.

		Returns:
			OperationOutputLog: The output and log of the operation.
		"""
		user_id = kwargs["user_id"]
		experiment_name = kwargs["experiment_name"]
		experiment_duration = kwargs["experiment_duration"]

		start_date, start_time = get_time()
		start = str_to_datetime(date_str=start_date, time_str=start_time)
		delta_time = str_to_delta_time(time_str=experiment_duration)
		end = start + delta_time
		end_date, end_time = datetime_to_str(date_time=end)

		expr_log_store = ExperimentLog.from_user_id(
			user_id=user_id,
			embed_model=self._embed_model
		)
		expr_log_store.set_recent_experiment(
			experiment_name=experiment_name,
			start_date=start_date,
			start_time=start_time,
			end_date=end_date,
			end_time=end_time,
		)
		expr_log_store.persist()
		op_log_str = (
			f"Set the experiment in progress for {user_id}.\n"
			f"Experiment name: {experiment_name}.\n"
			f"Start from {start_date}, {start_time} to {end_date}, {end_time}."
		)
		return OperationOutputLog(
			operation_name=self.op_name,
			operation_output=None,
			log_to_user=None,
			log_to_system={
				OP_DESCRIPTION: op_log_str,
				OP_REFERENCES: None,
			}
		)

	async def ado_operation(self, **kwargs) -> OperationOutputLog:
		return self.do_operation(**kwargs)

labridge.callback.experiment_log.set_current_experiment.SetCurrentExperimentOperation.do_operation(**kwargs)

Execute the operation set the experiment in progress for a user.

PARAMETER DESCRIPTION
user_id

The user id of a lab member.

TYPE: str

experiment_name

The name of a recorded experiment.

TYPE: str

experiment_duration

The duration of the experiment, in a format of "%Hh%Mm%Ss", refer to common.utils.time.

TYPE: str

RETURNS DESCRIPTION
OperationOutputLog

The output and log of the operation.

TYPE: OperationOutputLog

Source code in labridge\callback\experiment_log\set_current_experiment.py
 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
def do_operation(self, **kwargs) -> OperationOutputLog:
	r"""
	Execute the operation set the experiment in progress for a user.

	Args:
		user_id (str): The user id of a lab member.
		experiment_name (str): The name of a recorded experiment.
		experiment_duration (str): The duration of the experiment, in a format of "%Hh%Mm%Ss",
			refer to `common.utils.time`.

	Returns:
		OperationOutputLog: The output and log of the operation.
	"""
	user_id = kwargs["user_id"]
	experiment_name = kwargs["experiment_name"]
	experiment_duration = kwargs["experiment_duration"]

	start_date, start_time = get_time()
	start = str_to_datetime(date_str=start_date, time_str=start_time)
	delta_time = str_to_delta_time(time_str=experiment_duration)
	end = start + delta_time
	end_date, end_time = datetime_to_str(date_time=end)

	expr_log_store = ExperimentLog.from_user_id(
		user_id=user_id,
		embed_model=self._embed_model
	)
	expr_log_store.set_recent_experiment(
		experiment_name=experiment_name,
		start_date=start_date,
		start_time=start_time,
		end_date=end_date,
		end_time=end_time,
	)
	expr_log_store.persist()
	op_log_str = (
		f"Set the experiment in progress for {user_id}.\n"
		f"Experiment name: {experiment_name}.\n"
		f"Start from {start_date}, {start_time} to {end_date}, {end_time}."
	)
	return OperationOutputLog(
		operation_name=self.op_name,
		operation_output=None,
		log_to_user=None,
		log_to_system={
			OP_DESCRIPTION: op_log_str,
			OP_REFERENCES: None,
		}
	)

labridge.callback.experiment_log.set_current_experiment.SetCurrentExperimentOperation.operation_description(**kwargs)

Return the operation description, this description will be sent to the user for authorization.

PARAMETER DESCRIPTION
user_id

The user id of a lab member.

TYPE: str

experiment_name

The name of a recorded experiment.

TYPE: str

experiment_duration

The duration of the experiment, in a format of "%Hh%Mm%Ss", refer to common.utils.time.

TYPE: str

RETURNS DESCRIPTION
str

The operation description.

TYPE: str

Source code in labridge\callback\experiment_log\set_current_experiment.py
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
def operation_description(self, **kwargs) -> str:
	r"""
	Return the operation description, this description will be sent to the user for authorization.

	Args:
		user_id (str): The user id of a lab member.
		experiment_name (str): The name of a recorded experiment.
		experiment_duration (str): The duration of the experiment, in a format of "%Hh%Mm%Ss",
			refer to `common.utils.time`.

	Returns:
		str: The operation description.
	"""
	user_id = kwargs["user_id"]
	experiment_name = kwargs["experiment_name"]
	experiment_duration = kwargs["experiment_duration"]

	start_date, start_time = get_time()
	start = str_to_datetime(date_str=start_date, time_str=start_time)
	delta_time = str_to_delta_time(time_str=experiment_duration)
	end = start + delta_time
	end_date, end_time = datetime_to_str(date_time=end)
	op_description = SET_CURRENT_EXPERIMENT_DESCRIPTION.format(
		user_id=user_id,
		experiment_name=experiment_name,
		start_date=start_date,
		start_time=start_time,
		end_date=end_date,
		end_time=end_time,
	)
	return op_description