auto-labeling-pipeline icon indicating copy to clipboard operation
auto-labeling-pipeline copied to clipboard

Custom Request does not support lists

Open rmporsch opened this issue 4 years ago • 2 comments

Given we have the following request body:

{
  "instances": [
    {
      "text": "{{ text }}"
    }
    ]
}

The following method is unable to replace "{{ text }}" with the appropriate text.

def find_and_replace_value(obj, value, target='{{ text }}'):
    for k, v in obj.items():
        if v == target:
            obj[k] = value
            return
        if isinstance(v, dict):
            find_and_replace_value(v, value, target)

The proposed changes would address this issue.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • [x] Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

My test cases

Test A:

test_a = {
    "instances": [
        {
            "text": "{{ text }}"
        }
    ]
}

Test B

test_a = {
    "instances": [[
        {
            "text": "{{ text }}"
        }
    ]]
}

Checklist:

  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [x] My changes generate no new warnings
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] New and existing unit tests pass locally with my changes
  • [ ] Any dependent changes have been merged and published in downstream modules

rmporsch avatar Jun 22 '21 09:06 rmporsch

As a side question to this PR: image This seems not to be the correct way to do it. Since the value seems to be passed as string if I am not wrong. So how would I pass a nested dict in the body? Is the value ever serialized?

rmporsch avatar Jun 22 '21 09:06 rmporsch

@Hironsan not sure who the right person for this is but would love to get this merged.

rmporsch avatar Jul 27 '21 01:07 rmporsch