跳转至

New experiment

labridge.callback.experiment_log.new_experiment

labridge.callback.experiment_log.new_experiment.CreateNewExperimentLogOperation

Bases: CallBackOperationBase

This operation will create a new experiment record for a specific user.

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\new_experiment.py
 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class CreateNewExperimentLogOperation(CallBackOperationBase):
	r"""
	This operation will create a new experiment record for a specific user.

	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,
	):
		embed_model = embed_model or Settings.embed_model
		llm = llm or Settings.llm
		super().__init__(
			llm=llm,
			embed_model=embed_model,
			verbose=verbose,
			op_name=op_name or CreateNewExperimentLogOperation.__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 the new experiment.
			experiment_description (str): The description of the new experiment.

		Returns:
			str: The operation description.
		"""
		user_id = kwargs["user_id"]
		expr_name = kwargs[NEW_EXPERIMENT_NAME_KEY]
		expr_description = kwargs[NEW_EXPERIMENT_DESCRIPTION_KEY]

		op_description = CREATE_NEW_EXPERIMENT_DESCRIPTION.format(
			user_id=user_id,
			experiment_name=expr_name,
			experiment_description=expr_description,
		)
		return op_description

	def do_operation(self, **kwargs) -> OperationOutputLog:
		r"""
		Execute the operation to add a new experiment record.

		Args:
			user_id (str): The user id of a lab member.
			experiment_name (str): The name of the new experiment.
			experiment_description (str): The description of the new experiment.

		Returns:
			OperationOutputLog: The output and log of the operation.
		"""
		user_id = kwargs["user_id"]
		expr_name = kwargs[NEW_EXPERIMENT_NAME_KEY]
		expr_description = kwargs[NEW_EXPERIMENT_DESCRIPTION_KEY]
		expr_log_store = ExperimentLog.from_user_id(
			user_id=user_id,
			embed_model=self._embed_model,
		)

		expr_log_store.create_experiment(
			experiment_name=expr_name,
			description=expr_description,
		)
		expr_log_store.persist()

		op_log_str = (
			f"Have created a new experiment log record for the user {user_id}.\n"
			f"Experiment name: {expr_name}"
		)
		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.new_experiment.CreateNewExperimentLogOperation.do_operation(**kwargs)

Execute the operation to add a new experiment record.

PARAMETER DESCRIPTION
user_id

The user id of a lab member.

TYPE: str

experiment_name

The name of the new experiment.

TYPE: str

experiment_description

The description of the new experiment.

TYPE: str

RETURNS DESCRIPTION
OperationOutputLog

The output and log of the operation.

TYPE: OperationOutputLog

Source code in labridge\callback\experiment_log\new_experiment.py
 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
def do_operation(self, **kwargs) -> OperationOutputLog:
	r"""
	Execute the operation to add a new experiment record.

	Args:
		user_id (str): The user id of a lab member.
		experiment_name (str): The name of the new experiment.
		experiment_description (str): The description of the new experiment.

	Returns:
		OperationOutputLog: The output and log of the operation.
	"""
	user_id = kwargs["user_id"]
	expr_name = kwargs[NEW_EXPERIMENT_NAME_KEY]
	expr_description = kwargs[NEW_EXPERIMENT_DESCRIPTION_KEY]
	expr_log_store = ExperimentLog.from_user_id(
		user_id=user_id,
		embed_model=self._embed_model,
	)

	expr_log_store.create_experiment(
		experiment_name=expr_name,
		description=expr_description,
	)
	expr_log_store.persist()

	op_log_str = (
		f"Have created a new experiment log record for the user {user_id}.\n"
		f"Experiment name: {expr_name}"
	)
	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.new_experiment.CreateNewExperimentLogOperation.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 the new experiment.

TYPE: str

experiment_description

The description of the new experiment.

TYPE: str

RETURNS DESCRIPTION
str

The operation description.

TYPE: str

Source code in labridge\callback\experiment_log\new_experiment.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 the new experiment.
		experiment_description (str): The description of the new experiment.

	Returns:
		str: The operation description.
	"""
	user_id = kwargs["user_id"]
	expr_name = kwargs[NEW_EXPERIMENT_NAME_KEY]
	expr_description = kwargs[NEW_EXPERIMENT_DESCRIPTION_KEY]

	op_description = CREATE_NEW_EXPERIMENT_DESCRIPTION.format(
		user_id=user_id,
		experiment_name=expr_name,
		experiment_description=expr_description,
	)
	return op_description