Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] KeyError on choice #122

Closed
irgolic opened this issue Apr 11, 2023 · 1 comment
Closed

[bug] KeyError on choice #122

irgolic opened this issue Apr 11, 2023 · 1 comment

Comments

@irgolic
Copy link
Contributor

irgolic commented Apr 11, 2023

Could we automatically fix this? (try to put all the other kwargs into the desired choice attribute)
At the least, it should reask like my schema

This is my schema:

<choice
    name="action"
    on-fail-choice="reask"
>
<case
    name="new_file"
>
<object
    name="new_file"
>
<string
    name="filepath"
    description="Path to the newly created file."
    required="true"
/>
<string
    name="description"
    description="Description of the contents of the new file."
    required="true"
/>

</object>
</case>
<case
    name="edit_file"
>
<object
    name="edit_file"
>
<string
    name="filepath"
    description="Path to the file to be edited."
    required="true"
/>
<string
    name="description"
    description="Description of the changes to be made to the file."
    required="true"
/>
<integer
    name="start_line"
    description="The line number of the first line of the hunk to be edited."
    format="positive"
    required="false"
    on-fail="noop"
/>
<integer
    name="end_line"
    description="The line number of the last line of the hunk to be edited. Keep the hunk as short as possible while fulfilling the description."
    format="positive"
    required="false"
    on-fail="noop"
/>
</object>
</case>
<case
    name="finished"
>
<string
    name="commit_message"
    description="A more appropriate commit message based on the actions taken."
    required="true"
/>
</case>
</choice>

This is the generated schema:

<output>
    <string name="action" choices="new_file,edit_file,finished"/>
    <object name="new_file" description="new_file" if="action==new_file">
        <string name="filepath" description="Path to the newly created file." required="true"/>
        <string name="description" description="Description of the contents of the new file." required="true"/>
    </object>
    <object name="edit_file" description="edit_file" if="action==edit_file">
        <string name="filepath" description="Path to the file to be edited." required="true"/>
        <string name="description" description="Description of the changes to be made to the file." required="true"/>
        <integer name="start_line" description="The line number of the first line of the hunk to be edited." format="positive" required="false" on-fail="noop"/>
        <integer name="end_line" description="The line number of the last line of the hunk to be edited. Keep the hunk as short as possible while fulfilling the description." format="positive" required="false" on-fail="noop"/>
    </object>
    <string name="finished" description="commit_message: A more appropriate commit message based on the actions taken." required="true" if="action==finished"/>
</output>

This is the generated string:

{
  "action": "edit_file",
  "filepath": "autopr/utils/repo.py",
  "description": "Update the function call at line 124 to use the new tiktoken implementation.",
  "start_line": 124,
  "end_line": 124
}

This is the stack trace fragment:

  File "/github/workspace/autopr/services/rail_service.py", line 56, in run_rail_object
    raw_o, dict_o = pr_guard(
  File "/venv/lib/python3.9/site-packages/guardrails/guard.py", line 135, in __call__
    guard_history = runner(prompt_params=prompt_params)
  File "/venv/lib/python3.9/site-packages/guardrails/run.py", line 86, in __call__
    validated_output, reasks = self.step(
  File "/venv/lib/python3.9/site-packages/guardrails/run.py", line 136, in step
    validated_output = self.validate(index, output_as_dict, output_schema)
  File "/venv/lib/python3.9/site-packages/guardrails/run.py", line 237, in validate
    validated_output = output_schema.validate(output_as_dict)
  File "/venv/lib/python3.9/site-packages/guardrails/schema.py", line 328, in validate
    validated_response = self[field].validate(
  File "/venv/lib/python3.9/site-packages/guardrails/datatypes.py", line 344, in validate
    selected_value = schema[selected_key]
KeyError: 'edit_file'
@irgolic
Copy link
Contributor Author

irgolic commented Sep 12, 2023

This bug is gone after the new Choice changes.

@irgolic irgolic closed this as completed Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant