Skip to content

Commit 40700bb

Browse files
committed
added support for AgentCoder to either generate question or code
1 parent 2a7d76a commit 40700bb

File tree

4 files changed

+30
-76
lines changed

4 files changed

+30
-76
lines changed

Diff for: AgentFramework/programmer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def fetch_completion(data_entry, model, times=5):
3131
return data_entry
3232

3333
prompt = data_entry["prompt"]
34+
# clarity will only be added to the prompt if the question is modified
35+
clarity = "" if "clarity_prompt" not in data_entry else data_entry["clarity_prompt"]
3436
text = f"""
3537
{construct_few_shot_prompt}
36-
38+
{clarity}
3739
**Input Code Snippet**:
3840
```python
3941
{prompt}

Diff for: generate_response.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
PROMPT_START_3_v2 = 'You are an expert software developer who writes high quality code. With below information, please either generate Python3 code (Respond directly with code only with markdown), or ask clarifying questions: \n'
3939
# TODO: try this new prompt
4040
PROMPT_START_3_v3 = 'You are an expert software developer who writes high quality code. With below information, please either generate Python3 code (only one code block with markdown in response), or ask clarifying questions (no markdown in response): \n'
41+
PROMPT_START_3_v4 = '\n Based on the information below, you can choose to either generate Python3 code (Respond directly with code only with markdown), or ask clarifying questions. \n'
4142
ORIGINAL_PROMPT_START_0 = 'You are an expert software developer who writes high quality code. With below information, please generate Python3 code (Respond directly with code only with markdown): \n'
4243

4344
PROMPT_EVALUATE_QUESTIONS_V1 = 'The original description of a coding problem is modified so that the requirements become inconsistent, incomplete, or ambiguous. Given the modified description, some clarifying questions were raised to clarify the description. Given the original and modified problem description, evaluate the quality of the questions. Please provide an integer representing the quality of questions (3: Good questions that recover all missing info. 2: Fair questions that recover some missing info. 1: Bad questions or irrelevant content).\n QUALITY=[your int] \n Please also provide answers to the questions to recover the missing requirements! Be sure to add what is new or different in the original descrpition in your answer, compared with the modified problem description! \n ANSWERS=```[your answer]``` \n Please strictly follow the format QUALITY=[the int] and ANSWERS=```[the answer]``` in the response! Surround your answer with markup! \n\n ### Questions: {clarifying_questions} \n ### Problem Description: {problem} \n ### Original Description: {missing_information} \n'
@@ -841,15 +842,18 @@ def generate_response(model, msgs, topn, temperature, args, open_source_model, t
841842
response_list.append(i['message']['content'])
842843
return response_list
843844

844-
def description_2_code_multi_rounds(task_id, entry_point, prompt, user_input, original_prompt, model, topn, temperature, args, open_source_model, tokenizer, cached_response, cached_qq, cached_answer):
845+
def description_2_code_multi_rounds(prompt_modified, task_id, entry_point, prompt, user_input, original_prompt, model, topn, temperature, args, open_source_model, tokenizer, cached_response, cached_qq, cached_answer):
845846

846847
messages = []
847848
response_list = []
848849
model_2nd_round = OK_MODEL if model == 'Okanagan' else model
849850
# ROUND 1
850851
if model == "AgentCoder":
851852
# Adding the following: entry_point, task_id, original_prompt for AgentCoder
852-
messages.append({"task_id": task_id,"prompt": original_prompt, "entry_point": entry_point})
853+
if prompt_modified == False:
854+
messages.append({"task_id": task_id,"prompt": original_prompt, "entry_point": entry_point})
855+
else:
856+
messages.append({"task_id": task_id,"prompt": original_prompt, "entry_point": entry_point, "clarity_prompt": PROMPT_START_3_v4})
853857
else:
854858
## 1st round: initial code generation
855859
full_prompt = OK_PROMPT_CODEGEN + user_input if model == 'Okanagan' else prompt + user_input
@@ -901,9 +905,15 @@ def description_2_code_multi_rounds(task_id, entry_point, prompt, user_input, or
901905
if model == "AgentCoder":
902906
# We can only send one prompt to AgentCoder for now. Adding multiple roles requires major code changes in the original AgentCoder repo
903907
new_prompt = "Original Question: " + original_prompt + " First Response: " + response + " Feedback: " + answer + " " + PROMPT_2ND_ROUND
908+
# For the third round, we dont tell the model that our prompt contained the phrase "generate clarifying questions, that is why we send original question"
904909
messages[-1]["prompt"] = new_prompt
905910
msgs_i = messages.copy()
906911

912+
for message in messages:
913+
# Check if 'clarity_prompt' exists in the dictionary and then remove it for third round
914+
if 'clarity_prompt' in message:
915+
del message['clarity_prompt']
916+
907917
# # directly send third round request to GPT
908918
# messages.clear()
909919
# messages.append({"role": "user","content": full_prompt})
@@ -1031,8 +1041,16 @@ def HumanEval_experiment(dataset, dataset_loc, option, model, topn, temperature,
10311041
original_prompt = problem['prompt']
10321042
entry_point = problem['entry_point']
10331043
task_id = problem['name']
1034-
prompt_start = ORIGINAL_PROMPT_START_0 if input_prompt == 'prompt' else PROMPT_START_3_v2
1035-
response_list, code_list, qq_list, ans_list = description_2_code_multi_rounds(task_id, entry_point, prompt_start, description, original_prompt, model, topn, temperature, args, open_source_model, tokenizer, cached_responses.get(key, ''), cached_qqs.get(key, 0), cached_answers.get(key, ''))
1044+
# prompt_start = ORIGINAL_PROMPT_START_0 if input_prompt == 'prompt' else PROMPT_START_3_v2
1045+
# We will use "Prompt_Modified" to check whether AgentCoder is getting a modified prompt or an original prompt, based on which, we decide whether to send in a "generate clarifying questions" prompt or not.
1046+
# A new prompt called PROMPT_START_3_v4 has been created for the same.
1047+
Prompt_Modified = False
1048+
if input_prompt == 'prompt':
1049+
prompt_start = ORIGINAL_PROMPT_START_0
1050+
else:
1051+
prompt_start = PROMPT_START_3_v2
1052+
Prompt_Modified = True
1053+
response_list, code_list, qq_list, ans_list = description_2_code_multi_rounds(Prompt_Modified, task_id, entry_point, prompt_start, description, original_prompt, model, topn, temperature, args, open_source_model, tokenizer, cached_responses.get(key, ''), cached_qqs.get(key, 0), cached_answers.get(key, ''))
10361054
except Exception as e:
10371055
print('%s---------%s' % (problem['name'], e), flush=True)
10381056
continue

Diff for: prompts/attribution.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
Please note that these prompts have been copied and modified from the following repository.
22
Repository: https://github.com/huangd1999/AgentCoder/tree/main
33
Original Author: Dong Huang, Jie M.Zhang, Michael Luck, Qingwen Bu, Yuhao Qing, Heming Cui
4-
License: MIT
4+
License: MIT
5+
6+
Please note that the humaneval_prompt_update has been changed from a CoT FewShot approach to just a CoT approach because of dataset rendering issues. Moreoever, the keyword "Markdown" has been added to follow the format of HumanEvalComm.

Diff for: prompts/humaneval_prompt_update.txt

+2-70
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,9 @@
11
**Role**: You are a software programmer.
22

3-
**Task**: As a programmer, you are required to complete the function. Use a Chain-of-Thought approach to break down the problem, create pseudocode, and then write the code in Python language.
3+
**Task**: As a programmer, you are required to complete the function. Use a Chain-of-Thought approach to break down the problem, create pseudocode, and then write the code in Python language (Markdown).
44

55
**Code Formatting**: Please write code in
66
```python
77
[Code]
88
```
9-
format.
10-
11-
# For example:
12-
13-
## Prompt 1:
14-
```python
15-
from typing import List
16-
17-
18-
def has_close_elements(numbers: List[float], threshold: float) -> bool:
19-
""" Check if in given list of numbers, are any two numbers closer to each other than
20-
given threshold.
21-
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
22-
False
23-
>>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
24-
True
25-
"""
26-
27-
```
28-
29-
## Completion 1:
30-
```python
31-
for idx, elem in enumerate(numbers):
32-
for idx2, elem2 in enumerate(numbers):
33-
if idx != idx2:
34-
distance = abs(elem - elem2)
35-
if distance < threshold:
36-
return True
37-
38-
return False
39-
40-
```
41-
42-
## Prompt 2:
43-
```python
44-
from typing import List
45-
46-
47-
def separate_paren_groups(paren_string: str) -> List[str]:
48-
""" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
49-
separate those group into separate strings and return the list of those.
50-
Separate groups are balanced (each open brace is properly closed) and not nested within each other
51-
Ignore any spaces in the input string.
52-
>>> separate_paren_groups('( ) (( )) (( )( ))')
53-
['()', '(())', '(()())']
54-
"""
55-
56-
```
57-
58-
## Completion 2:
59-
```python
60-
result = []
61-
current_string = []
62-
current_depth = 0
63-
64-
for c in paren_string:
65-
if c == '(':
66-
current_depth += 1
67-
current_string.append(c)
68-
elif c == ')':
69-
current_depth -= 1
70-
current_string.append(c)
71-
72-
if current_depth == 0:
73-
result.append(''.join(current_string))
74-
current_string.clear()
75-
76-
return result
77-
```
9+
format.

0 commit comments

Comments
 (0)