Skip to content

Runtimes

AsyncRuntime

Bases: Runtime

Async version of runtime that uses asyncio to process batch of records.

Source code in adala/runtimes/base.py
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
class AsyncRuntime(Runtime):
    """Async version of runtime that uses asyncio to process batch of records."""

    @abstractmethod
    async def record_to_record(
        self,
        record: Dict[str, str],
        input_template: str,
        instructions_template: str,
        output_template: str,
        extra_fields: Optional[Dict[str, Any]] = None,
        field_schema: Optional[Dict] = None,
        instructions_first: bool = True,
        response_model: Optional[Type[BaseModel]] = None,
    ) -> Dict[str, str]:
        """
        Processes a record.

        Args:
            record (Dict[str, str]): The record to process.
            input_template (str): The input template.
            instructions_template (str): The instructions template.
            output_template (str): The output template.
            extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
            field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
                i.e. analogous to {"field_n": {"type": "string"}}.
            instructions_first (bool): Whether to put instructions first. Defaults to True.
            response_model (Optional[Type[BaseModel]]): The response model to use for processing records. Defaults to None.
                                                        If set, the response will be generated according to this model and `output_template` and `field_schema` fields will be ignored.
                                                        Note, explicitly providing ResponseModel will be the default behavior for all runtimes in the future.

        Returns:
            Dict[str, str]: The processed record.
        """

    @abstractmethod
    async def batch_to_batch(
        self,
        batch: InternalDataFrame,
        input_template: str,
        instructions_template: str,
        response_model: Type[BaseModel],
        extra_fields: Optional[Dict[str, str]] = None,
        field_schema: Optional[Dict] = None,
        instructions_first: bool = True,
        output_template: Optional[
            str
        ] = None,  # TODO: deprecated in favor of response_model, can be removed
    ) -> InternalDataFrame:
        """
        Processes a record.

        Args:
            batch (InternalDataFrame): The batch to process.
            input_template (str): The input template.
            instructions_template (str): The instructions template.
            response_model (Optional[Type[BaseModel]]): The response model to use for processing records.
            extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
            field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
                i.e. analogous to {"field_n": {"type": "string"}}.
            instructions_first (bool): Whether to put instructions first. Defaults to True.
            output_template (str): The output template. Deprecated.

        Returns:
            InternalDataFrame: The processed batch.
        """
        output = batch.progress_apply(
            self.record_to_record,
            axis=1,
            result_type="expand",
            input_template=input_template,
            instructions_template=instructions_template,
            output_template=output_template,
            extra_fields=extra_fields,
            field_schema=field_schema,
            instructions_first=instructions_first,
            response_model=response_model,
        )
        return output

batch_to_batch(batch, input_template, instructions_template, response_model, extra_fields=None, field_schema=None, instructions_first=True, output_template=None) abstractmethod async

Processes a record.

Parameters:

Name Type Description Default
batch InternalDataFrame

The batch to process.

required
input_template str

The input template.

required
instructions_template str

The instructions template.

required
response_model Optional[Type[BaseModel]]

The response model to use for processing records.

required
extra_fields Optional[Dict[str, str]]

Extra fields to use in the templates. Defaults to None.

None
field_schema Optional[Dict]

Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}.

None
instructions_first bool

Whether to put instructions first. Defaults to True.

True
output_template str

The output template. Deprecated.

None

Returns:

Name Type Description
InternalDataFrame InternalDataFrame

The processed batch.

Source code in adala/runtimes/base.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
@abstractmethod
async def batch_to_batch(
    self,
    batch: InternalDataFrame,
    input_template: str,
    instructions_template: str,
    response_model: Type[BaseModel],
    extra_fields: Optional[Dict[str, str]] = None,
    field_schema: Optional[Dict] = None,
    instructions_first: bool = True,
    output_template: Optional[
        str
    ] = None,  # TODO: deprecated in favor of response_model, can be removed
) -> InternalDataFrame:
    """
    Processes a record.

    Args:
        batch (InternalDataFrame): The batch to process.
        input_template (str): The input template.
        instructions_template (str): The instructions template.
        response_model (Optional[Type[BaseModel]]): The response model to use for processing records.
        extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
        field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
            i.e. analogous to {"field_n": {"type": "string"}}.
        instructions_first (bool): Whether to put instructions first. Defaults to True.
        output_template (str): The output template. Deprecated.

    Returns:
        InternalDataFrame: The processed batch.
    """
    output = batch.progress_apply(
        self.record_to_record,
        axis=1,
        result_type="expand",
        input_template=input_template,
        instructions_template=instructions_template,
        output_template=output_template,
        extra_fields=extra_fields,
        field_schema=field_schema,
        instructions_first=instructions_first,
        response_model=response_model,
    )
    return output

record_to_record(record, input_template, instructions_template, output_template, extra_fields=None, field_schema=None, instructions_first=True, response_model=None) abstractmethod async

Processes a record.

Parameters:

Name Type Description Default
record Dict[str, str]

The record to process.

required
input_template str

The input template.

required
instructions_template str

The instructions template.

required
output_template str

The output template.

required
extra_fields Optional[Dict[str, str]]

Extra fields to use in the templates. Defaults to None.

None
field_schema Optional[Dict]

Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}.

None
instructions_first bool

Whether to put instructions first. Defaults to True.

True
response_model Optional[Type[BaseModel]]

The response model to use for processing records. Defaults to None. If set, the response will be generated according to this model and output_template and field_schema fields will be ignored. Note, explicitly providing ResponseModel will be the default behavior for all runtimes in the future.

None

Returns:

Type Description
Dict[str, str]

Dict[str, str]: The processed record.

Source code in adala/runtimes/base.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
@abstractmethod
async def record_to_record(
    self,
    record: Dict[str, str],
    input_template: str,
    instructions_template: str,
    output_template: str,
    extra_fields: Optional[Dict[str, Any]] = None,
    field_schema: Optional[Dict] = None,
    instructions_first: bool = True,
    response_model: Optional[Type[BaseModel]] = None,
) -> Dict[str, str]:
    """
    Processes a record.

    Args:
        record (Dict[str, str]): The record to process.
        input_template (str): The input template.
        instructions_template (str): The instructions template.
        output_template (str): The output template.
        extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
        field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
            i.e. analogous to {"field_n": {"type": "string"}}.
        instructions_first (bool): Whether to put instructions first. Defaults to True.
        response_model (Optional[Type[BaseModel]]): The response model to use for processing records. Defaults to None.
                                                    If set, the response will be generated according to this model and `output_template` and `field_schema` fields will be ignored.
                                                    Note, explicitly providing ResponseModel will be the default behavior for all runtimes in the future.

    Returns:
        Dict[str, str]: The processed record.
    """

Runtime

Bases: BaseModelInRegistry

Base class representing a generic runtime environment.

Attributes:

Name Type Description
verbose bool

Flag indicating if runtime outputs should be verbose. Defaults to False.

batch_size Optional[int]

The batch size to use for processing records. Defaults to None.

concurrency Optional[int]

The number of parallel processes to use for processing records. Defaults to 1. Note that when parallel processing is used, the memory footprint will be doubled compared to sequential processing.

response_model Optional[Type[BaseModel]]

The response model to use for processing records. Defaults to None. If set, the response will be generated according to this model and output_template and field_schema fields will be ignored. Note, explicitly providing ResponseModel will be the default behavior for all runtimes in the future.

Source code in adala/runtimes/base.py
 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
class Runtime(BaseModelInRegistry):
    """
    Base class representing a generic runtime environment.

    Attributes:
        verbose (bool): Flag indicating if runtime outputs should be verbose. Defaults to False.
        batch_size (Optional[int]): The batch size to use for processing records. Defaults to None.
        concurrency (Optional[int]): The number of parallel processes to use for processing records. Defaults to 1.
                                    Note that when parallel processing is used, the memory footprint will be doubled compared to sequential processing.
        response_model (Optional[Type[BaseModel]]): The response model to use for processing records. Defaults to None.
                                                    If set, the response will be generated according to this model and `output_template` and `field_schema` fields will be ignored.
                                                    Note, explicitly providing ResponseModel will be the default behavior for all runtimes in the future.
    """

    verbose: bool = False
    batch_size: Optional[int] = None
    concurrency: Optional[int] = Field(default=1, alias="concurrent_clients")

    @model_validator(mode="after")
    def init_runtime(self) -> "Runtime":
        """Initializes the runtime.

        This method should be used to validate and potentially initialize the runtime instance.

        Returns:
            Runtime: The initialized runtime instance.
        """
        return self

    @abstractmethod
    def record_to_record(
        self,
        record: Dict[str, str],
        input_template: str,
        instructions_template: str,
        response_model: Type[BaseModel],
        extra_fields: Optional[Dict[str, Any]] = None,
        field_schema: Optional[Dict] = None,
        instructions_first: bool = True,
        output_template: Optional[
            str
        ] = None,  # TODO: deprecated in favor of response_model, can be removed
    ) -> Dict[str, str]:
        """
        Processes a record.

        Args:
            record (Dict[str, str]): The record to process.
            input_template (str): The input template.
            instructions_template (str): The instructions template.
            response_model (Type[BaseModel]): The response model to use for processing records.
            extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
            field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
                i.e. analogous to {"field_n": {"type": "string"}}.
            instructions_first (bool): Whether to put instructions first. Defaults to True.
            output_template (str): The output template. Deprecated.

        Returns:
            Dict[str, str]: The processed record.
        """

    def batch_to_batch(
        self,
        batch: InternalDataFrame,
        input_template: str,
        instructions_template: str,
        response_model: Type[BaseModel],
        extra_fields: Optional[Dict[str, str]] = None,
        field_schema: Optional[Dict] = None,
        instructions_first: bool = True,
        output_template: Optional[
            str
        ] = None,  # TODO: deprecated in favor of response_model, can be removed
    ) -> InternalDataFrame:
        """
        Processes a record.
        It supports parallel processing of the batch:
         - when the `concurrency` is set to -1 (using all available CPUs),
         - when the `concurrency` is set to 1 (sequential processing),
         - when the `concurrency` is set to a fixed number of CPUs.
        Please note that parallel processing doubles the memory footprint compared to sequential processing.

        Args:
            batch (InternalDataFrame): The batch to process.
            input_template (str): The input template.
            instructions_template (str): The instructions' template.
            response_model (Type[BaseModel]): The response model to use for processing records.
            extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
            field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
                i.e. analogous to {"field_n": {"type": "string"}}.
            instructions_first (bool): Whether to put instructions first. Defaults to True.
            output_template (str): The output template. Deprecated.
        Returns:
            InternalDataFrame: The processed batch.
        """
        if self.concurrency == -1:
            # run batch processing each row in a parallel way, using all available CPUs
            logger.info("Running batch processing in parallel using all available CPUs")
            pandarallel.initialize(progress_bar=self.verbose)
            apply_func = batch.parallel_apply
        elif self.concurrency == 1:
            # run batch processing each row in a sequential way
            logger.info("Running batch processing sequentially")
            if self.verbose:
                apply_func = batch.progress_apply
            else:
                apply_func = batch.apply
        elif self.concurrency > 1:
            # run batch processing each row in a parallel way, using a fixed number of CPUs
            logger.info(
                f"Running batch processing in parallel using {self.concurrency} CPUs"
            )
            # Warning: parallel processing doubles the memory footprint compared to sequential processing
            # read more about https://nalepae.github.io/pandarallel/
            pandarallel.initialize(
                nb_workers=self.concurrency, progress_bar=self.verbose
            )
            apply_func = batch.parallel_apply
        else:
            raise ValueError(f"Invalid concurrency value: {self.concurrency}")

        output = apply_func(
            self.record_to_record,
            axis=1,
            result_type="expand",
            input_template=input_template,
            instructions_template=instructions_template,
            output_template=output_template,
            extra_fields=extra_fields,
            field_schema=field_schema,
            instructions_first=instructions_first,
            response_model=response_model,
        )
        return output

    def record_to_batch(
        self,
        record: Dict[str, str],
        input_template: str,
        instructions_template: str,
        response_model: Type[BaseModel],
        output_batch_size: int = 1,
        extra_fields: Optional[Dict[str, str]] = None,
        field_schema: Optional[Dict] = None,
        instructions_first: bool = True,
        output_template: Optional[
            str
        ] = None,  # TODO: deprecated in favor of response_model, can be removed
    ) -> InternalDataFrame:
        """
        Processes a record and return a batch.

        Args:
            record (Dict[str, str]): The record to process.
            input_template (str): The input template.
            instructions_template (str): The instructions template.
            response_model (Optional[Type[BaseModel]]): The response model to use for processing records. Defaults to None.
            output_batch_size (int): The batch size for the output. Defaults to 1.
            extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
            field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
                i.e. analogous to {"field_n": {"type": "string"}}.
            instructions_first (bool): Whether to put instructions first. Defaults to True.
            output_template (str): The output template. Deprecated.

        Returns:
            InternalDataFrame: The processed batch.
        """
        batch = InternalDataFrame([record] * output_batch_size)
        return self.batch_to_batch(
            batch=batch,
            input_template=input_template,
            instructions_template=instructions_template,
            output_template=output_template,
            extra_fields=extra_fields,
            field_schema=field_schema,
            instructions_first=instructions_first,
            response_model=response_model,
        )

    def get_cost_estimate(
        self, prompt: str, substitutions: List[Dict], output_fields: Optional[List[str]]
    ) -> CostEstimate:
        raise NotImplementedError("This runtime does not support cost estimates")

batch_to_batch(batch, input_template, instructions_template, response_model, extra_fields=None, field_schema=None, instructions_first=True, output_template=None)

Processes a record. It supports parallel processing of the batch: - when the concurrency is set to -1 (using all available CPUs), - when the concurrency is set to 1 (sequential processing), - when the concurrency is set to a fixed number of CPUs. Please note that parallel processing doubles the memory footprint compared to sequential processing.

Parameters:

Name Type Description Default
batch InternalDataFrame

The batch to process.

required
input_template str

The input template.

required
instructions_template str

The instructions' template.

required
response_model Type[BaseModel]

The response model to use for processing records.

required
extra_fields Optional[Dict[str, str]]

Extra fields to use in the templates. Defaults to None.

None
field_schema Optional[Dict]

Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}.

None
instructions_first bool

Whether to put instructions first. Defaults to True.

True
output_template str

The output template. Deprecated.

None

Returns: InternalDataFrame: The processed batch.

Source code in adala/runtimes/base.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def batch_to_batch(
    self,
    batch: InternalDataFrame,
    input_template: str,
    instructions_template: str,
    response_model: Type[BaseModel],
    extra_fields: Optional[Dict[str, str]] = None,
    field_schema: Optional[Dict] = None,
    instructions_first: bool = True,
    output_template: Optional[
        str
    ] = None,  # TODO: deprecated in favor of response_model, can be removed
) -> InternalDataFrame:
    """
    Processes a record.
    It supports parallel processing of the batch:
     - when the `concurrency` is set to -1 (using all available CPUs),
     - when the `concurrency` is set to 1 (sequential processing),
     - when the `concurrency` is set to a fixed number of CPUs.
    Please note that parallel processing doubles the memory footprint compared to sequential processing.

    Args:
        batch (InternalDataFrame): The batch to process.
        input_template (str): The input template.
        instructions_template (str): The instructions' template.
        response_model (Type[BaseModel]): The response model to use for processing records.
        extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
        field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
            i.e. analogous to {"field_n": {"type": "string"}}.
        instructions_first (bool): Whether to put instructions first. Defaults to True.
        output_template (str): The output template. Deprecated.
    Returns:
        InternalDataFrame: The processed batch.
    """
    if self.concurrency == -1:
        # run batch processing each row in a parallel way, using all available CPUs
        logger.info("Running batch processing in parallel using all available CPUs")
        pandarallel.initialize(progress_bar=self.verbose)
        apply_func = batch.parallel_apply
    elif self.concurrency == 1:
        # run batch processing each row in a sequential way
        logger.info("Running batch processing sequentially")
        if self.verbose:
            apply_func = batch.progress_apply
        else:
            apply_func = batch.apply
    elif self.concurrency > 1:
        # run batch processing each row in a parallel way, using a fixed number of CPUs
        logger.info(
            f"Running batch processing in parallel using {self.concurrency} CPUs"
        )
        # Warning: parallel processing doubles the memory footprint compared to sequential processing
        # read more about https://nalepae.github.io/pandarallel/
        pandarallel.initialize(
            nb_workers=self.concurrency, progress_bar=self.verbose
        )
        apply_func = batch.parallel_apply
    else:
        raise ValueError(f"Invalid concurrency value: {self.concurrency}")

    output = apply_func(
        self.record_to_record,
        axis=1,
        result_type="expand",
        input_template=input_template,
        instructions_template=instructions_template,
        output_template=output_template,
        extra_fields=extra_fields,
        field_schema=field_schema,
        instructions_first=instructions_first,
        response_model=response_model,
    )
    return output

init_runtime()

Initializes the runtime.

This method should be used to validate and potentially initialize the runtime instance.

Returns:

Name Type Description
Runtime Runtime

The initialized runtime instance.

Source code in adala/runtimes/base.py
67
68
69
70
71
72
73
74
75
76
@model_validator(mode="after")
def init_runtime(self) -> "Runtime":
    """Initializes the runtime.

    This method should be used to validate and potentially initialize the runtime instance.

    Returns:
        Runtime: The initialized runtime instance.
    """
    return self

record_to_batch(record, input_template, instructions_template, response_model, output_batch_size=1, extra_fields=None, field_schema=None, instructions_first=True, output_template=None)

Processes a record and return a batch.

Parameters:

Name Type Description Default
record Dict[str, str]

The record to process.

required
input_template str

The input template.

required
instructions_template str

The instructions template.

required
response_model Optional[Type[BaseModel]]

The response model to use for processing records. Defaults to None.

required
output_batch_size int

The batch size for the output. Defaults to 1.

1
extra_fields Optional[Dict[str, str]]

Extra fields to use in the templates. Defaults to None.

None
field_schema Optional[Dict]

Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}.

None
instructions_first bool

Whether to put instructions first. Defaults to True.

True
output_template str

The output template. Deprecated.

None

Returns:

Name Type Description
InternalDataFrame InternalDataFrame

The processed batch.

Source code in adala/runtimes/base.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
def record_to_batch(
    self,
    record: Dict[str, str],
    input_template: str,
    instructions_template: str,
    response_model: Type[BaseModel],
    output_batch_size: int = 1,
    extra_fields: Optional[Dict[str, str]] = None,
    field_schema: Optional[Dict] = None,
    instructions_first: bool = True,
    output_template: Optional[
        str
    ] = None,  # TODO: deprecated in favor of response_model, can be removed
) -> InternalDataFrame:
    """
    Processes a record and return a batch.

    Args:
        record (Dict[str, str]): The record to process.
        input_template (str): The input template.
        instructions_template (str): The instructions template.
        response_model (Optional[Type[BaseModel]]): The response model to use for processing records. Defaults to None.
        output_batch_size (int): The batch size for the output. Defaults to 1.
        extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
        field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
            i.e. analogous to {"field_n": {"type": "string"}}.
        instructions_first (bool): Whether to put instructions first. Defaults to True.
        output_template (str): The output template. Deprecated.

    Returns:
        InternalDataFrame: The processed batch.
    """
    batch = InternalDataFrame([record] * output_batch_size)
    return self.batch_to_batch(
        batch=batch,
        input_template=input_template,
        instructions_template=instructions_template,
        output_template=output_template,
        extra_fields=extra_fields,
        field_schema=field_schema,
        instructions_first=instructions_first,
        response_model=response_model,
    )

record_to_record(record, input_template, instructions_template, response_model, extra_fields=None, field_schema=None, instructions_first=True, output_template=None) abstractmethod

Processes a record.

Parameters:

Name Type Description Default
record Dict[str, str]

The record to process.

required
input_template str

The input template.

required
instructions_template str

The instructions template.

required
response_model Type[BaseModel]

The response model to use for processing records.

required
extra_fields Optional[Dict[str, str]]

Extra fields to use in the templates. Defaults to None.

None
field_schema Optional[Dict]

Field JSON schema to use in the templates. Defaults to all fields are strings, i.e. analogous to {"field_n": {"type": "string"}}.

None
instructions_first bool

Whether to put instructions first. Defaults to True.

True
output_template str

The output template. Deprecated.

None

Returns:

Type Description
Dict[str, str]

Dict[str, str]: The processed record.

Source code in adala/runtimes/base.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
@abstractmethod
def record_to_record(
    self,
    record: Dict[str, str],
    input_template: str,
    instructions_template: str,
    response_model: Type[BaseModel],
    extra_fields: Optional[Dict[str, Any]] = None,
    field_schema: Optional[Dict] = None,
    instructions_first: bool = True,
    output_template: Optional[
        str
    ] = None,  # TODO: deprecated in favor of response_model, can be removed
) -> Dict[str, str]:
    """
    Processes a record.

    Args:
        record (Dict[str, str]): The record to process.
        input_template (str): The input template.
        instructions_template (str): The instructions template.
        response_model (Type[BaseModel]): The response model to use for processing records.
        extra_fields (Optional[Dict[str, str]]): Extra fields to use in the templates. Defaults to None.
        field_schema (Optional[Dict]): Field JSON schema to use in the templates. Defaults to all fields are strings,
            i.e. analogous to {"field_n": {"type": "string"}}.
        instructions_first (bool): Whether to put instructions first. Defaults to True.
        output_template (str): The output template. Deprecated.

    Returns:
        Dict[str, str]: The processed record.
    """