message=f"{REFLEXION_FEW_SHOT}\n[previous impl]:\n{prev_func_impl}\n\n[unit test results from previous impl]:\n{feedback}\n\n[reflection on previous impl]:\n{self_reflection}\n\n[improved impl]:\n{func_sig}"
# func_bodies is a really bad name, as it can also be just 1 string
print('----------------------- SYSTEM MESSAGE -----------------------')
@ -9,12 +9,203 @@ PY_SIMPLE_COMPLETION_INSTRUCTION = "# Write the body of this function only."
PY_REFLEXION_COMPLETION_INSTRUCTION="You are PythonGPT. You will be given your past function implementation, a series of unit tests, and a hint to change the implementation appropriately. Apply the changes below by writing the body of this function only.\n\n-----"
PY_SELF_REFLECTION_COMPLETION_INSTRUCTION="You are PythonGPT. You will be given a function implementation and a series of unit tests. Your goal is to write a few sentences to explain why your implementation is wrong as indicated by the tests. You will need this as a hint when you try again later. Only provide the few sentence description in your answer, not the implementation.\n\n-----"
PY_SIMPLE_CHAT_INSTRUCTION="You are PythonGPT, an AI that only responds with python code, NOT ENGLISH. You will be given a function signature and its docstring by the user. Respond only in code with correct implementation of the function. Do not include provided the docstring in your response."# The first line of your response should have 4 spaces of indentation so that it fits syntactically with the user provided signature.
PY_REFLEXION_CHAT_INSTRUCTION="You are PythonGPT. You will be given your past function implementation, a series of unit tests, and a hint to change the implementation appropriately. Apply the changes below by writing the body of this function only. You should fill in the following text of the missing function body. For example, the first line of the completion should have 4 spaces for the indendation so that it fits syntactically with the preceding signature."
PY_SELF_REFLECTION_CHAT_INSTRUCTION="You are PythonGPT. You will be given a function implementation and a series of unit tests. Your goal is to write a few sentences to explain why your implementation is wrong as indicated by the tests. You will need this as a hint when you try again later. Only provide the few sentence description in your answer, not the implementation."
PY_SIMPLE_CHAT_INSTRUCTION="You are PythonGPT, an AI that only responds with only python code. You will be given a function signature and its docstring by the user. Respond only in code with a correct, efficient implementation of the function. Do not include provided the docstring in your response."# The first line of your response should have 4 spaces of indentation so that it fits syntactically with the user provided signature.
PY_REFLEXION_CHAT_INSTRUCTION="You are PythonGPT. You will be given your previous implementation of a function, a series of unit tests results, and your self-reflection on your previous implementation. Apply the necessary changes below by responding only with the improved body of the function. Do not include the signature in your response. The first line of your response should have 4 spaces of indentation so that it fits syntactically with the user provided signature. You will be given a few examples by the user."
Eachword's length is guaranteed to be greater than 0 and not exceed maxWidth.
Theinputarray`words`containsatleastoneword.
"""
ifnotwords:
return[]
res=[]
cur_line=[]
cur_len=0
forwordinwords:
ifcur_len+len(word)+len(cur_line)>maxWidth:
iflen(cur_line)==1:
res.append(cur_line[0]+''*(maxWidth-cur_len))
else:
spaces=maxWidth-cur_len
space_between=spaces//(len(cur_line)-1)
extra_spaces=spaces%(len(cur_line)-1)
line=''
fori,winenumerate(cur_line[:-1]):
line+=w+''*(space_between+(i<extra_spaces))
line+=cur_line[-1]
res.append(line)
cur_line=[]
cur_len=0
cur_line.append(word)
cur_len+=len(word)
last_line=''.join(cur_line)
last_line+=''*(maxWidth-len(last_line))
res.append(last_line)
returnres
ENDEXAMPLES
'''
PY_SELF_REFLECTION_CHAT_INSTRUCTION="You are PythonGPT. You will be given a function implementation and a series of unit test results. Your goal is to write a few sentences to explain why your implementation is wrong as indicated by the tests. You will need this as guidance when you try again later. Only provide the few sentence description in your answer, not the implementation. You will be given a few examples by the user."
PY_TEST_GENERATION_COMPLETION_INSTRUCTION=f"""You are PythonGPT, an AI coding assistant that can write unique, diverse, and intuitive unit tests for functions given the signature and docstring.
Okay,let's think of some test cases for this longest_subarray_with_sum_limit function. We need to cover various edge cases. First, let'stestwithasimplelistofpositiveintegersandatargetvaluewhereasubarrayexists.Next,wecouldtestwithatargetvaluegreaterthanthesumofallelementsinthelist,whichshouldreturntheentirelist.Weshouldalsotestacasewherenosubarrayfulfillsthecondition,sothefunctionshouldreturnanemptylist.Itwouldbeinterestingtoincludenegativenumbersinthelistandtestifthefunctionhandlesthemcorrectly.Finally,weshouldalsotestwithanemptylistanddifferenttargetvaluestomakesurethefunctioncanhandlethosecases.
[unittests]:
# Test case 1: Simple list of positive integers with existing subarray
# Test case 5: Empty list with different target values
assertlongest_subarray_with_sum_limit([],10)==[]
assertlongest_subarray_with_sum_limit([],0)==[]
assertlongest_subarray_with_sum_limit([],-5)==[]
ENDOFEXAMPLES
'''
PY_TEST_GENERATION_COMPLETION_INSTRUCTION=f"""You are PythonGPT, an AI coding assistant that can write unique, diverse, and intuitive unit tests for functions given the signature and docstring.
{PY_TEST_GENERATION_FEW_SHOT}"""
PY_TEST_GENERATION_CHAT_INSTRUCTION="""You are CodexGPT, an AI coding assistant that can write unique, diverse, and intuitive unit tests for functions given the signature and docstring."""
PY_TEST_GENERATION_CHAT_INSTRUCTION_REACT="""You are CodexGPT, an AI coding assistant that can write unique, diverse, and intuitive unit tests for functions given the description and signature. You will first 'think', brainstorming possible edge cases and points of failure. Then, you will write a series of unit tests that reflect your thinking. Make sure that tests conform to any constraints. You will be given a few examples."""