Rank Operation¶
The Rank operation ranks records in a column of input data based on a natural language condition.
Core Implementation¶
nirvana.ops.rank.RankOperation(user_instruction: str = '', input_columns: list[str] = [], descend: bool = True, context: list[dict] | str | None = None, model: str | None = None, tool: Callable | BaseTool | None = None, strategy: Literal['plain'] = 'plain', rate_limit: int = 16, assertions: list[Callable] | None = [])
¶
Bases: BaseOperation
RankOperation ranks the rows of a DataFrame column according to a user-specified natural language instruction.
Source code in nirvana/ops/rank.py
Attributes¶
prompter = RankPrompter()
instance-attribute
¶
input_columns = input_columns
instance-attribute
¶
descend = descend
instance-attribute
¶
dependencies: list[str]
property
¶
generated_fields: list[str]
property
¶
op_kwargs: dict
property
¶
Functions¶
partition(data: pd.Series, ranking: list, low: int, high: int, user_instruction: str, dtype: str, **kwargs)
async
¶
Source code in nirvana/ops/rank.py
quick_sort(data: pd.Series, ranking: list, low: int, high: int, user_instruction: str, dtype: str, **kwargs)
async
¶
Source code in nirvana/ops/rank.py
execute(input_data: pd.DataFrame, **kwargs)
async
¶
Source code in nirvana/ops/rank.py
Output Class¶
nirvana.ops.rank.RankOpOutputs(cost: float = 0.0, ranking: list[int] = list(), ranked_indices: list[int] = list())
dataclass
¶
Function Wrapper¶
nirvana.ops.rank
¶
rank_wrapper(input_data: DataFrame, user_instruction: str = None, input_column: str = None, descend: bool = True, context: list[dict] | str | None = None, model: str | None = None, func: Callable = None, strategy: Literal['plain'] = 'plain', rate_limit: int = 16, assertions: list[Callable] | None = [], **kwargs)
A function wrapper for rank operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
DataFrame
|
Input dataframe |
required |
user_instruction
|
str
|
User instruction. Defaults to None. |
None
|
input_column
|
str
|
Input column. Defaults to None. |
None
|
descend
|
bool
|
Whether to rank in descending order (True) or ascending order (False). Defaults to True. |
True
|
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']
|
Strategy. Defaults to "plain". |
'plain'
|
rate_limit
|
int
|
Rate limit. Defaults to 16. |
16
|
assertions
|
list[Callable]
|
Assertions. Defaults to []. |
[]
|
**kwargs
|
Additional keyword arguments for OpenAI Clent. |
{}
|