Skip to content

Commit

Permalink
update prompt engineering
Browse files Browse the repository at this point in the history
  • Loading branch information
NourEldin-Ali committed Jul 31, 2023
1 parent 9c92f47 commit c7fb4a0
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 81 deletions.
81 changes: 33 additions & 48 deletions integration-openai/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,19 @@ def generateGherkin():
if('output' in request.form):
output = request.form['output']


# description to Gherkin syntax

# llm = OpenAI(openai_api_key=api_key,
# temperature=temperature,
# model='text-davinci-003')


llm = ChatOpenAI(
model_name='gpt-3.5-turbo',
temperature=temperature,
openai_api_key=api_key)
# print(llm)
temperature=temperature,
api_key=api_key)

f = open("gherkin.prompt", "r")
template = f.read()

Expand All @@ -42,59 +45,26 @@ def generateGherkin():
prompt_input = {'description':request.form['description']}
result = llm_chain.run(prompt_input)

#check gerkin
#Check gerkin
llm = OpenAI(openai_api_key=api_key,
temperature=temperature,
model='text-davinci-003')

f = open("check_gherkin.prompt", "r")
template = f.read()

prompt = PromptTemplate(template=template, input_variables=["inputs","description","output"])
llm_chain = LLMChain(prompt=prompt, llm=llm)
prompt_input = {'output':output, 'inputs':request.form['inputs'], 'description':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

# @app.route("/verify_gherkin", methods=['post'])
# def verifyGherkin():
# # if('openai-api-key' not in request.headers):
# # return "Error: OpenAI API key"
# # if('openai-organization' not in request.headers):
# # return "Error: OpenAI Organization"

# # api_key = request.headers['openai-api-key']
# # orga_key = request.headers['openai-organization']

# api_key = sys.argv[1]
# if('inputs' not in request.form):
# return "Error: Inputs are required"
# if('description' not in request.form):
# return "Error: Description is required"

# output = ""
# if('output' in request.form):
# output = request.form['output']

# # llm = OpenAI(openai_api_key=api_key,
# # temperature=temperature)

# llm = ChatOpenAI(
# temperature=temperature,
# openai_api_key=api_key)
# # print(llm)
# f = open("check_gherkin.prompt", "r")
# template = f.read()

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


@app.route("/groovy", methods=['post'])
def generateGroovy():
Expand All @@ -116,21 +86,36 @@ def generateGroovy():

api_key = sys.argv[1]

llm = OpenAI(openai_api_key=api_key,
temperature=temperature
)

# llm = ChatOpenAI(
# temperature=temperature,
# openai_api_key=api_key)
# print(llm)
llm = ChatOpenAI(
model_name='gpt-3.5-turbo',
temperature=temperature,
openai_api_key=api_key
)

f = open("groovy.prompt", "r")
template = f.read()

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


llm = OpenAI(
openai_api_key=api_key,
temperature=temperature,
model='text-davinci-003'
)

f = open("check_groovy.prompt", "r")
template = f.read()

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

print(result,"################################",result2)
return result

app.run(debug=True,host='0.0.0.0',port=3001)
80 changes: 80 additions & 0 deletions integration-openai/check_groovy.prompt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
You will take some example about accepted and rejected senarios, based on the inputs/output data and the description of the senario.
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 input are in form of list ([x,y,z] is a list) each one already define and should use it directly, that mean used x and y and z directly.
The input should be a list of variable names, and shoud be used as it is in the groovy script.
you should show me only "YES" or "NO" without any other inforamtion.
Result ONLY YES or NO!
---
Example1: acceptable senario
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 senario (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 senario (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
---

Example4: acceptable senario
Inputs: [gross_salary]
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: YES
---

Inputs:{inputs}
Output:{output}
Description: {description}
Answer: ?
---
66 changes: 33 additions & 33 deletions integration-openai/groovy.prompt
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
You are expert in Groovy script developmenet. Convert Gherkin syntax to Groovy script.
The script should be well implemented without any error. You should take input from user and if there is output to add return. If there are not input available ([] is list is empty) please show me only "CANT CONVERT".
The input are in form of list ([x,y,z] is a list) each one already define and you can use it directly, that mean use x and y and z directly.

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.
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 funtion within the Groovy script call it the return value of the script. I need to directly use the return value.
---
Example1: acceptable senario
Inputs: [list_of_item]
Example: acceptable senario
Inputs: [gross_salary]
Output: sum_of_amount_after_discount
Description: Given a list of items
When the total sum of the items exceeds 100
Then a discount of 10% will be applied
And when the item 'XYZ' is included in the list
Then a discount of 5% will be given on the amount
Answer:
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
---
Desciption: 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
Then the salary is taxed at 11%
When the income is between 27,478 and 78,570
Then the salary is taxed at 30%
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:
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

Example2: rejected senario (no inputs)
Inputs: []
Output: sum_of_amount_after_discount
Description: 'Given a list of items
When the total sum of the items exceeds 100
Then a discount of 10% will be applied
And when the item 'XYZ' is included in the list
Then a discount of 5% will be given on the amount'
Answer: CANT CONVERT
---

Inputs:{inputs}
Output:{output}
Description: {description}
Answer: ?
Result: ?
---

0 comments on commit c7fb4a0

Please sign in to comment.