Map Operation¶
The Map operation applies a specified transformation in natural language to each item in a column of input data.
Core Implementation¶
nirvana.ops.map.MapOperation(user_instruction: str = '', input_columns: list[str] = [], output_columns: list[str] = [], context: list[dict] | str | None = None, model: str | None = None, tool: Callable | BaseTool | None = None, strategy: Literal['plain', 'fewshot', 'self-refine'] = 'plain', limit: int | None = None, rate_limit: int = 16, assertions: list[Callable] | None = [])
¶
Bases: BaseOperation
Map operator: Applies an LLM to perform a transformation on a column, producing a new column as output
Source code in nirvana/ops/map.py
Attributes¶
strategy_options = ['plain', 'fewshot', 'self-refine']
class-attribute
instance-attribute
¶
prompter = MapPrompter()
instance-attribute
¶
input_columns = input_columns
instance-attribute
¶
output_columns = output_columns
instance-attribute
¶
dependencies: list[str]
property
¶
generated_fields: list[str]
property
¶
op_kwargs
property
¶
Functions¶
execute(input_data: pd.DataFrame, **kwargs)
async
¶
Source code in nirvana/ops/map.py
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 232 233 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 | |
Output Class¶
nirvana.ops.map.MapOpOutputs(cost: float = 0.0, outputs: dict[str, list] = dict())
dataclass
¶
Bases: BaseOpOutputs
Attributes¶
outputs: dict[str, list] = field(default_factory=dict)
class-attribute
instance-attribute
¶
Functions¶
__add__(other: MapOpOutputs)
¶
Source code in nirvana/ops/map.py
Function Wrapper¶
nirvana.ops.map
¶
map_wrapper(input_data: DataFrame, user_instruction: str = None, input_columns: list[str] = None, output_columns: list[str] = None, context: list[dict] | str | None = None, model: str | None = None, func: Callable = None, strategy: Literal['plain', 'fewshot', 'self-refine'] = 'plain', limit: int | None = None, rate_limit: int = 16, assertions: list[Callable] | None = [], **kwargs)
A function wrapper for map operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
DataFrame
|
Input dataframe |
required |
user_instruction
|
str
|
User instruction. Defaults to None. |
None
|
input_columns
|
list[str]
|
Input column. Defaults to None. |
None
|
output_columns
|
list[str]
|
Output columns. Defaults to None. |
None
|
context
|
list[dict] | str
|
Context. Defaults to None. |
None
|
model
|
str
|
Model. Defaults to None. |
None
|
func
|
Callable
|
User function. Defaults to None. |
None
|
strategy
|
Literal['plain', 'fewshot', 'self-refine']
|
Strategy. Defaults to "plain". |
'plain'
|
limit
|
int
|
Maximum number of outputs to produce before stopping. |
None
|
rate_limit
|
int
|
Rate limit. Defaults to 16. |
16
|
assertions
|
list[Callable]
|
Assertions. Defaults to []. |
[]
|
**kwargs
|
Additional keyword arguments for OpenAI Clent. |
{}
|