|
| 1 | +from evals.eval_types import NotebookState, PromptGenerator |
| 2 | + |
| 3 | +__all__ = ['multi_shot_pandas_focussed_prompt'] |
| 4 | + |
| 5 | +class _MultiShotPandasFocussedPrompt(PromptGenerator): |
| 6 | + prompt_name = "multi_shot_pandas_focussed_prompt" |
| 7 | + |
| 8 | + def get_prompt(self, user_input: str, notebook_state: NotebookState) -> str: |
| 9 | + |
| 10 | + return f"""You are an expert python programmer writing a script in a Jupyter notebook. You are given a set of variables, existing code, and a task. |
| 11 | +
|
| 12 | +Respond with the updated active code cell and a short explanation of the changes you made. |
| 13 | +
|
| 14 | +When responding: |
| 15 | +- Do not use the word "I" |
| 16 | +- Do not recreate variables that already exist |
| 17 | +- Keep as much of the original code as possible |
| 18 | +
|
| 19 | +<Example 1> |
| 20 | +
|
| 21 | +Defined Variables: |
| 22 | +{{ |
| 23 | + 'loan_multiplier': 1.5, |
| 24 | + 'sales_df': pd.DataFrame({{ |
| 25 | + 'transaction_date': ['2024-01-02', '2024-01-02', '2024-01-02', '2024-01-02', '2024-01-03'], |
| 26 | + 'price_per_unit': [10, 9.99, 13.99, 21.00, 100], |
| 27 | + 'units_sold': [1, 2, 1, 4, 5], |
| 28 | + 'total_price': [10, 19.98, 13.99, 84.00, 500] |
| 29 | + }}) |
| 30 | +}} |
| 31 | +
|
| 32 | +Code in the active code cell: |
| 33 | +```python |
| 34 | +import pandas as pd |
| 35 | +sales_df = pd.read_csv('./sales.csv') |
| 36 | +``` |
| 37 | +
|
| 38 | +Your task: convert the transaction_date column to datetime and then multiply the total_price column by the sales_multiplier. |
| 39 | +
|
| 40 | +Output: |
| 41 | +
|
| 42 | +```python |
| 43 | +import pandas as pd |
| 44 | +sales_df = pd.read_csv('./sales.csv') |
| 45 | +sales_df['transaction_date'] = pd.to_datetime(sales_df['transaction_date']) |
| 46 | +sales_df['total_price'] = sales_df['total_price'] * sales_multiplier |
| 47 | +``` |
| 48 | +
|
| 49 | +Converted the `transaction_date` column to datetime using the built-in pd.to_datetime function and multiplied the `total_price` column by the `sales_multiplier` variable. |
| 50 | +</Example 1> |
| 51 | +
|
| 52 | +<Example 2> |
| 53 | +Defined Variables: |
| 54 | +{{ |
| 55 | + 'df': pd.DataFrame({{ |
| 56 | + 'id': ['id-49830', 'id-39301', 'id-85011', 'id-51892', 'id-99111'], |
| 57 | + 'name': ['Tamir', 'Aaron', 'Grace', 'Nawaz', 'Julia'], |
| 58 | + 'age': [29, 31, 26, 21, 30], |
| 59 | + 'dob': ['1994-06-15', '1992-03-27', '1997-04-11', '2002-07-05', '1993-08-22'], |
| 60 | + 'city': ['San Francisco', 'New York', 'Los Angeles', 'Chicago', 'Houston'], |
| 61 | + 'state': ['CA', 'NY', 'CA', 'IL', 'TX'], |
| 62 | + 'zip': ['94103', '10001', '90038', '60611', '77002'], |
| 63 | + 'start_date': ['2024-01-01', '2024-01-01', '2024-01-01', '2024-01-01', '2024-01-01'], |
| 64 | + 'department': ['Engineering', 'Sales', 'Marketing', 'Operations', 'Finance'], |
| 65 | + 'salary': ['$100,000', '$50,000', '$60,000', '$55,000', '$70,000'] |
| 66 | + }}) |
| 67 | +}} |
| 68 | +
|
| 69 | +Code in the active code cell: |
| 70 | +```python |
| 71 | +
|
| 72 | +``` |
| 73 | +
|
| 74 | +Your task: Calculate the weekly salary for each employee. |
| 75 | +
|
| 76 | +Output: |
| 77 | +
|
| 78 | +```python |
| 79 | +df['salary'] = df['salary'].str[1:].replace(',', '', regex=True).astype('float') |
| 80 | +df['weekly_salary'] = df['salary'] / 52 |
| 81 | +``` |
| 82 | +
|
| 83 | +Remove the `$` and `,` from the `salary` in order to convert it to a float. Then, divide the salary by 52 to get the weekly salary. |
| 84 | +</Example 2> |
| 85 | +
|
| 86 | +Defined Variables: |
| 87 | +{notebook_state.global_vars} |
| 88 | +
|
| 89 | +Code in the active code cell: |
| 90 | +
|
| 91 | +```python |
| 92 | +{notebook_state.cell_contents[-1] if len(notebook_state.cell_contents) > 0 else ""} |
| 93 | +``` |
| 94 | +
|
| 95 | +Your task: ${user_input}""" |
| 96 | + |
| 97 | +multi_shot_pandas_focussed_prompt = _MultiShotPandasFocussedPrompt() |
0 commit comments