cursor icon indicating copy to clipboard operation
cursor copied to clipboard

Code modification did not meet expectations.

Open jkxiongxin opened this issue 2 years ago • 2 comments

Many times when AI modifies the code, it includes code that I did not select, which forces me to select all the code every time for modification.

jkxiongxin avatar Apr 13 '23 01:04 jkxiongxin

I think the reason the function did not perform as expected is due to issues with the prompt statement. The correct prompt statement should be in the following format:

Describe the function, such as modifying or generating code. Provide an example:

  1. Context.
  2. Code in selected area.
  3. Requirement content.
  4. Expected result.

Begin: Actual context. Code in selected area. Actual requirement content.

jkxiongxin avatar Apr 13 '23 01:04 jkxiongxin

There is a prompt for change code:

Modify the code. I will provide context, selected code, requirements and example output. You only need to provide the output part in your reply, without description or repetition. Example: Context: from selenium.webdriver.common.by import By def is_input_element(element): return element.tag_name.lower() == "input" def get_element_xpath(element, driver): xpath = "" if element.get_attribute("id"): return f"//[@id='{element.get_attribute('id')}']" while element != driver.find_element(By.XPATH, '/html'): parent = element.find_element(By.XPATH, './..') siblings = parent.find_elements(By.XPATH, './child::') index = 0 for i, sibling in enumerate(siblings): if sibling == element: index = i + 1 break tag = element.tag_name xpath = f"/{tag}[{index}]{xpath}" element = parent return f"/html{xpath}" Selected code: def is_input_element(element): return element.tag_name.lower() == "input" Requirement: Modify to is_textarea_element method Output: def is_textarea_element(element): return element.tag_name.lower() == "textarea" Note: The output does not need to include context. Start modifying: Context: from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get("https://www.google.com") driver.quit() Selected code: driver = webdriver.Chrome() Requirement: Modify to use Firefox Output modified code:

jkxiongxin avatar Apr 13 '23 01:04 jkxiongxin