Skip to content

Commit

Permalink
Update prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
NourEldin-Ali committed Jan 18, 2024
1 parent 49748fd commit 92177c2
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 87 deletions.
49 changes: 35 additions & 14 deletions integration-openai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,33 @@ def generateGherkin():
f = open("check_gherkin.prompt", "r")
template = f.read()

prompt = PromptTemplate(template=template, input_variables=["inputs","description","output"])
prompt = PromptTemplate(template=template, input_variables=["inputs","description","output","gherkin"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
prompt_input = {'output':output, 'inputs':request.form['inputs'], 'description':result}
prompt_input = {'output':output, 'inputs':request.form['inputs'], 'description':request.form['description'],'gherkin':result}
result1 = llm_chain.run(prompt_input)

# resutls
print([result1,"###",result])
if("NO" in result1):
return "INVALID REQUEST, CHECK IF YOUR DATA INPUTS AND DESCRIPTION ARE COHERENT, AND TRY AGAIN"
# return [result1,"###",result]
return result

cleaned_gherkin = extract_code_and_remove_specific_lines(
result1,
"GHERKIN:\n",
"```"
)
if(cleaned_gherkin.count('- YES')):
cleaned_gherkin = extract_code_and_remove_specific_lines(
result,
"GHERKIN:\n",
"```"
)
return cleaned_gherkin

def extract_code_and_remove_specific_lines(text, start_marker, line_marker):
# Extract the code between the start and end markers
start_idx = text.find(start_marker) + len(start_marker)
code_block = text[start_idx:].strip()

# Remove lines containing the specific line marker
cleaned_code = "\n".join([line for line in code_block.split('\n') if not line.startswith(line_marker)])
return cleaned_code

@app.route("/groovy", methods=['post'])
def generateGroovy():
Expand Down Expand Up @@ -110,14 +125,20 @@ def generateGroovy():
f = open("check_groovy.prompt", "r")
template = f.read()

prompt = PromptTemplate(template=template, input_variables=["inputs","description","output"])
prompt = PromptTemplate(template=template, input_variables=["inputs","description","output","groovy"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
prompt_input = {'output':output, 'inputs':request.form['inputs'], 'description':result}
prompt_input = {'output':output, 'inputs':request.form['inputs'], 'description':request.form['description'], 'groovy':result}
result2 = llm_chain.run(prompt_input)

print(result,"################################",result2)
if("NO" in result2):
return "CANNOT CONVERT GHERKIN TO CODE, TRY AGAIN"
return result
cleaned_code = extract_code_and_remove_specific_lines(
result2,
"GROOVY:\n",
"```"
)
return cleaned_code
# print(result,"################################",result2)
# if("NO" in result2):
# return "CANNOT CONVERT GHERKIN TO CODE, TRY AGAIN"
# return result

app.run(debug=True,host='0.0.0.0',port=3001)
41 changes: 34 additions & 7 deletions integration-openai/check_gherkin.prompt
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
You will take some examples about accepted and rejected scenarios, based on the input data and the description of the scenario.
Whole the input should be a part of the description and the description inputs should be a part on the inputs list.
The description should be in Gherkin format.
You are an AI assitant expert in Gherkin language.
You are extremely skilled in writing and validating a Gherkin syntax from a textual description.
Analyze the Gherkin syntax and the textual description, it should be coherent.

We will have inputs and output. Whole the input should be a part of the description and the description inputs should be a part on the inputs list.
The input should be a list of variable names.
you should show me only "YES" or "NO" without any other information.
Result ONLY YES or NO!

Analyse the inputs and the output, it should be validated in the Gherkin scenario. If there are not, please rewrite a new scenario that contains the input and output.
You dont need to add the name of the variable to the Gherkin scenario, just I need to be present in a clear way within the Gherkin scenario.
If the Gherkin scenario uses an input that is not defined in the variables list (inputs), the result should be 'CANNOT GENERATE GHERKIN, ERROR IN INPUTS'.

Don't make any mistakes in the syntax of Gherkin language.
Don't make any changes to the description needed to convert.
Return one scenario for each condition of the description, without any example.

Write your response using the following order:
RESULTS:
-YES
-NO
it is based on the correctness of the Gherkin syntax based on the description and the description inputs and output.

GHERKIN:
The valid Gherkin syntax.
---
<<<Human>>>
Inputs:{inputs}
Output:{output}
Description: {description}
Result: ?
Description: ``` {description} ```
Gherkin: ``` {gherkin} ```

<<<AI>>>
RESULTS:
?

GHERKIN:
```
?
```
---
93 changes: 39 additions & 54 deletions integration-openai/check_groovy.prompt
Original file line number Diff line number Diff line change
@@ -1,59 +1,44 @@
You will take some examples about accepted and rejected scenarios, based on the inputs/output data and the description of the scenario.
Whole the input should be a part of the description and the description inputs should be a part on the inputs list.
The description should be in Groovy script.
The inputs are in the form of a list ([x,y,z] is a list) . Each one already defines and should use it directly, that means used x and y and z directly.
The input should be a list of variable names, and should be used as it is in the groovy script.
you should show me only "YES" or "NO" without any other information.
Result ONLY YES or NO!
---
Example1: acceptable scenario
Inputs: [list_of_item]
Output: sum_of_amount_after_discount
Description:
def totalSum = list_of_item.sum()
def sum_of_amount_after_discount = totalSum
if (totalSum > 100)
sum_of_amount_after_discount = totalSum - (totalSum * 0.1)
if (list_of_item.contains('XYZ'))
sum_of_amount_after_discount = totalSum - (sum_of_amount_after_discount * 0.05)
return sum_of_amount_after_discount
Answer: YES
---
Example2: rejected scenario (no inputs)
Inputs: []
Output: sum_of_amount_after_discount
Description:
def totalSum = list_of_item.sum()
def sum_of_amount_after_discount = totalSum
if (totalSum > 100)
sum_of_amount_after_discount = totalSum - (totalSum * 0.1)
if (list_of_item.contains('XYZ'))
sum_of_amount_after_discount = totalSum - (sum_of_amount_after_discount * 0.05)
return sum_of_amount_after_discount
Answer: NO
---
Example3: rejected scenario (wrong inputs)
Inputs: [water_intake]
Output: sum_of_amount_after_discount
Description:
def net_salary_after_tax = 0
if (gross_salary <= 10722)
net_salary_after_tax=gross_salary
else if (gross_salary> 10722 && gross_salary <= 27478)
net_salary_after_tax=gross_salary - (gross_salary * 0.11)
else if (gross_salary> 27478 && gross_salary <= 78570)
net_salary_after_tax=gross_salary - (gross_salary * 0.3)
else if (gross_salary> 78570 && gross_salary <= 168994)
net_salary_after_tax=gross_salary - (gross_salary * 0.41)
else if (gross_salary> 168994)
net_salary_after_tax = gross_salary - (gross_salary * 0.45)
return net_salary_after_tax
Answer: NO
You are an AI assitant expert in Groovy-Scripts.
You are extremely skilled in writing Groovy-Scripts from a Gherkin language.
Analyze the Gherkin description steps to understand the meaning, then to convert to Groovy script.

Analyse the inputs and the output, it should be validated in the Groovy script. If there are not, please rewrite a new script that contains the input and output.

Write your response using the following order:
RESULTS:
-YES
-NO
it is based on the correctness of the Gherkin syntax based on the description and the description inputs and output.

GROOVY:
The valid Groovy script, without add symbols to the script, such as '---', '```', or any other characters.

Please ensure the script is well-crafted, free of any errors, and takes into consideration both input and output from the user.
The inputs will be provided in the form of a list (for instance, [x,y,z]), and it's important to note that all variables within the list are predefined - you can therefore utilize 'x', 'y', and 'z' directly in your script.
Please focus on producing only the Groovy script as the end result. You are required to incorporate the input and the output within the Groovy script itself, without creating any additional functions. Be sure to carefully structure your script so that it runs without producing any errors.
Please remember, the output should be the return value of the script. This means that the last evaluated expression in the script will be the output. Be sure to structure your script in a way that the desired output is the last evaluated expression.
We appreciate your attention to detail in ensuring this script is free of errors and well-structured to meet the task requirements.
If you want to define a function within the Groovy script, call it. I need to directly use the return value.
If the script uses an input that is not defined in the variables list (inputs), the result should be 'CANNOT GENERATE GROOVY, ERROR IN INPUTS'.


Do not add symbols to the script, such as '---', '```', or any other characters. If there exists, remove them from the script.
I need executable script.
The resutls should be only code without any other informations about the function.

---
<<<Human>>>
Inputs:{inputs}
Output:{output}
Description: {description}
Answer: ?
---
Gherkin: ``` {description} ```
Groovy: ``` {groovy} ```

<<<AI>>>
RESULTS:
?

GROOVY:
```
?
```
---
19 changes: 15 additions & 4 deletions integration-openai/gherkin.prompt
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
Please convert the following description into Gherkin language.
You are an AI assitant expert in Gherkin language.
You are extremely skilled in writing Gherkin syntax from a textual description.
Analyze the textual description steps to understand the meaning.
Finally, look at the different steps and construct the Gherkin syntaxt.

Don't make any mistakes in the syntax of Gherkin language.
Don't make any changes to the description needed to transfer.
Return only one scenario for the description, without any example.
Write well Gherkin without ambiguity.
Don't make any changes to the description needed to convert.
Return one scenario for each condition of the description, without any example.

Please convert the following description into Gherkin language.

###
Description need to transfer: {description}
<<<Human>>>
Description need to convert: ``` {description} ```

<<<AI>>>
?
###
35 changes: 27 additions & 8 deletions integration-openai/groovy.prompt
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
As an expert in Groovy script development, your task is to convert Gherkin syntax into a Groovy script. Please ensure the script is well-crafted, free of any errors, and takes into consideration both input and output from the user.
You are an AI assitant expert in Groovy-Scripts.
You are extremely skilled in writing Groovy-Scripts from a Gherkin language.
Analyze the Gherkin description steps to understand the meaning, then to convert to Groovy script.


Please ensure the script is well-crafted, free of any errors, and takes into consideration both input and output from the user.
The inputs will be provided in the form of a list (for instance, [x,y,z]), and it's important to note that all variables within the list are predefined - you can therefore utilize 'x', 'y', and 'z' directly in your script.
Please focus on producing only the Groovy script as the end result. You are required to incorporate the input and the output within the Groovy script itself, without creating any additional functions. Be sure to carefully structure your script so that it runs without producing any errors.
Please remember, the output should be the return value of the script. This means that the last evaluated expression in the script will be the output. Be sure to structure your script in a way that the desired output is the last evaluated expression.
We appreciate your attention to detail in ensuring this script is free of errors and well-structured to meet the task requirements.
If you want to define a function within the Groovy script, call it. I need to directly use the return value.
The resutls should be only code without any other informations about the function.

Do not add symbols to the script, such as '---', '```', or any other characters. If there exists, remove them from the script.
I need executable script.
The resutls should be only script without any other informations about the function.
---
Example:
<<<Human>>>
Inputs: [gross_salary]
Output: sum_of_amount_after_discount
Description: Given the user's gross salary
Description:
```
Given the user's gross salary
When the income is up to 10,722
Then the salary is tax free
When the income is between 10,777 and 27,478
Expand All @@ -20,7 +31,10 @@ When the income is between 78,570 and 168,994
Then the salary is taxed at 41%
When the income is above 168,994
Then the salary is taxed at 45%
Result:
```

<<<AI>>>
```
def net_salary_after_tax = 0
if (gross_salary <= 10722)
net_salary_after_tax=gross_salary
Expand All @@ -33,10 +47,15 @@ else if (gross_salary> 78570 && gross_salary <= 168994)
else if (gross_salary> 168994)
net_salary_after_tax = gross_salary - (gross_salary * 0.45)
return net_salary_after_tax

```
---
<<<Human>>>
Inputs:{inputs}
Output:{output}
Description: {description}
Result: ?
Output: {output}
Gherkin: ``` {description} ```

<<<AI>>>
```
?
```
---
Loading

0 comments on commit 92177c2

Please sign in to comment.