Skip to content

Commit d738c7c

Browse files
author
melih-unsal
committed
major bugs fixed
1 parent 1fc636f commit d738c7c

File tree

8 files changed

+52
-50
lines changed

8 files changed

+52
-50
lines changed

demogpt/chains/prompts/combine_v2.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
system_template = """
22
Regenerate the code by only combining the input parts into st.form.
33
It is really important not to change other parts.
4-
Copy all the function definitions as is and don't modify or replace them.
4+
Copy all the function definitions and library imports as is and don't modify or replace them.
55
Combine input-related parts under the st.form.
66
If a function needs an input from user via st.text_input, put it between st.form and st.form_submit_button so that the state is preserved.
77
Show the result when the form is submitted.
@@ -13,10 +13,9 @@
1313
"""
1414

1515
human_template = """
16-
BEFORE:
17-
import streamlit as st
18-
19-
st.title("My Adv Game")
16+
=============================================================
17+
DRAFT CODE 1:
18+
# all imports
2019
2120
def foo1():
2221
result = "res"
@@ -40,11 +39,9 @@ def foo2(half_story,user_choice):
4039
4140
if continued_story:
4241
st.markdown(continued_story)
43-
################################################################################################
44-
AFTER:
45-
import streamlit as st
46-
47-
st.title("My Adv Game")
42+
#############################################################
43+
FINAL CODE 1:
44+
# all imports
4845
4946
def foo1():
5047
result = "res"
@@ -64,13 +61,16 @@ def foo2(half_story,user_choice):
6461
user_choice = st.selectbox("What would you like to do next?", ["Choice1", "Choice2"])
6562
submit_button = st.form_submit_button(label='Submit Story')
6663
if submit_button:
67-
if text_input and user_choice and :
64+
if text_input and user_choice :
6865
continued_story = foo2(text_input,user_choice)
6966
st.markdown(continued_story)
70-
################################################################################################
71-
BEFORE:
67+
#############################################################
68+
69+
70+
=============================================================
71+
DRAFT CODE 2:
7272
{code_snippets}
73-
################################################################################################
74-
AFTER:
73+
#############################################################
74+
FINAL CODE 2:
7575
7676
"""

demogpt/chains/prompts/task_definitions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"name": "ui_output_text",
2727
"description": "Shows text output to the user.",
2828
"good_at": "Showing text to the user.",
29-
"input_data_type": "string",
29+
"input_data_type": "*",
3030
"output_data_type": "none",
3131
"purpose": "Displaying textual information to the user.",
3232
},
@@ -106,8 +106,8 @@
106106
"name": "python",
107107
"description": "Implement and call python function from given description.",
108108
"good_at": "Writing generic python code by AI",
109-
"input_data_type": "*string",
110-
"output_data_type": "string",
109+
"input_data_type": "*",
110+
"output_data_type": "*",
111111
"purpose": "It generates python code from general purpose instructions",
112112
},
113113
{
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
system_template = """
2-
You are a python developer and good at writing and testing the function for the given arguments.
3-
You will also take the previous code segment so that you can continue on it by implementing the function and then calling that function
4-
with the given arguments and assigning the result to the variable.
2+
As a proficient Python developer, follow the guidelines below:
3+
1. Build upon the given "Previous Code".
4+
2. Ensure to import all required libraries. Do NOT use pandas.compat.StringIO as it's deprecated.
5+
3. Implement the specified function.
6+
4. Invoke the function using the provided arguments, and store the result in the indicated variable.
7+
5. Ensure the resultant code is error-free and fits naturally as a continuation of the "Previous Code".
8+
9+
Let's get coding!
510
"""
611

712
human_template = """
8-
Instruction:{instruction}
13+
Instruction: {instruction}
914
Function Name: {function_name}
10-
Arguments:{argument}
11-
Variable:{variable}
12-
Previous Code:{code_snippets}
13-
Python Code:
15+
Arguments: {argument}
16+
Assigned Variable: {variable}
17+
Previous Code:
18+
{code_snippets}
19+
Python Code Continuation:
1420
"""

demogpt/chains/prompts/task_list/ui_input_file.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Write a streamlit file uploader code and return the path of uploaded file as a string depending on the instruction given to you:
33
Since st.file_uploader.name does not give full file path, you first need to save it then get a full file path like in the following:
44
5-
uploaded_file = st.file_uploader("Upload Txt File", type=["txt"])
5+
uploaded_file = st.file_uploader("Upload Txt File", type=["txt"], key='{variable}')
66
if uploaded_file is not None:
77
# Create a temporary file to store the uploaded content
88
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
@@ -12,12 +12,9 @@
1212
{variable} = ''
1313
1414
Suppose that, streamlit has been imported by "import streamlit as st" so you don't need to import it.
15-
Here is the part of the code that you are supposed to continue:
16-
{code_snippets}
17-
1815
Assign the file path to the variable called "{variable}"
1916
You will basically use file_uploader and get file path from it but nothing else.
20-
Not to loose the file path, please use st.session_state[<key>]
17+
Do not loose the file path and check if the file is uploaded. Otherwise, assign empty string to "{variable}"
2118
Don't read the file, only get the file path
2219
"""
2320

demogpt/chains/prompts/task_list/ui_output_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
args: medium_article
2929
instruction: Display the generated Medium article to the user
3030
code:
31-
if submitted:
31+
if medium_article:
3232
st.markdown(medium_article)
3333
3434
args: translated_text

demogpt/chains/task_chains.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def uiOutputText(cls, task, code_snippets):
5959
code = cls.getChain(
6060
human_template=prompts.ui_output_text.human_template,
6161
instruction=instruction,
62-
args=args,
62+
args=args
6363
)
6464
return utils.refine(code)
6565

demogpt/controllers.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ def refineKeyTypeCompatiblity(task):
1010
if task["output_data_type"] == "none":
1111
if task["output_key"] != "none":
1212
task["output_key"] = "none"
13-
return task
14-
13+
return task
1514

1615
def checkDTypes(tasks):
1716

@@ -37,6 +36,11 @@ def checkDTypes(tasks):
3736
if input_key != "none":
3837
feedback += f"Since {name} is the first task, its input data type is supposed to be none but it is {input_key}.Please find another way.\n"
3938

39+
elif reference_input == "*":
40+
continue
41+
42+
elif reference_input.startswith("*") and input_data_type == "list":
43+
continue
4044
# Check input data types
4145
elif reference_input.startswith("*"):
4246
reference_input = reference_input.replace("*", "")
@@ -45,6 +49,7 @@ def checkDTypes(tasks):
4549
feedback += f"""
4650
{name} expects all inputs as {reference_input} or none but the data type of {input_key} is {input_data_type} not {reference_input}. Please find another way.\n
4751
"""
52+
print("1:",)
4853
else:
4954
for res, data_type in zip(input_key, input_data_type):
5055
if data_type != reference_input:
@@ -56,11 +61,14 @@ def checkDTypes(tasks):
5661
{name} expects all inputs as {reference_input} but the data type of {input_key} is {input_data_type} not {reference_input}. Please find another way.\n
5762
"""
5863

64+
if reference_output == "*":
65+
continue
5966
# Check output data types
60-
if output_data_type != reference_output:
61-
feedback += f"""
62-
{name} should output in {reference_output} data type but it is {output_data_type} not {reference_output}. Please find another way.\n
63-
"""
67+
elif output_data_type != reference_output:
68+
if not (reference_output.startswith("*") and output_data_type != "list"):
69+
feedback += f"""
70+
{name} should output in {reference_output} data type but it is {output_data_type} not {reference_output}. Please find another way.\n
71+
"""
6472

6573
valid = len(feedback) == 0
6674

@@ -82,23 +90,16 @@ def checkPromptTemplates(templates, task):
8290
feedback = ""
8391
for input_key in inputs:
8492
if f"{{{input_key}}}" not in templates:
85-
feedback += f"{{{input_key}}} is not included in any of the templates. Please add it.\n"
93+
feedback += f"'{{{input_key}}}' is not included in any of the templates. You must add '{{{input_key}}}' inside of at least one of the templates.\n"
8694

8795
# now detect extras
8896

8997
matches = set(re.findall(r"\{([^}]+)\}", templates))
9098

9199
for match in matches:
92100
if match not in inputs:
93-
feedback += f"{{{match}}} cannot be included in any of the templates. Please remove it.\n"
94-
95-
print("templates:" + templates)
96-
print("matches:", matches)
97-
print("inputs:", inputs)
98-
print("feedback:", feedback)
101+
feedback += f"'{{{match}}}' cannot be included nowhere in the templates. You must remove '{{{match}}}'.\n"
99102

100103
valid = len(feedback) == 0
101104

102-
print("valid:", valid)
103-
104105
return {"feedback": feedback, "valid": valid}

demogpt/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ def getInputPosition(template, inputs):
133133
{variable} = ""
134134
"""
135135
input_variables = ["chat_history"] + inputs
136-
print("system_template:",system_template)
137-
print("inputs:",inputs)
138136
human_input = getInputPosition(system_template, inputs)
139137
code = f"""
140138

0 commit comments

Comments
 (0)