Skip to content

Instantly share code, notes, and snippets.

@bbartling
Last active October 10, 2023 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbartling/f88928de9fa7c28dd502307efe24a4f7 to your computer and use it in GitHub Desktop.
Save bbartling/f88928de9fa7c28dd502307efe24a4f7 to your computer and use it in GitHub Desktop.
concept idea prompt engineering template for controls hardware or application engineering to select valves for a job
import openai
import json
# Example usage of a valve for a job:
flow_rate = 5 # GPM
delta_p = 3 # PSI
specific_gravity = 1
fluid_type = "water"
is_three_way = False
product_literature = [
{"max_cv": 1.3, "connection_size": "1/2", "model_two_way": "G212", "model_three_way": None},
{"max_cv": 4.1, "connection_size": "1/2", "model_two_way": "G213", "model_three_way": None},
{"max_cv": 7.0, "connection_size": "1/2", "model_two_way": "G214", "model_three_way": "G314"},
{"max_cv": 13.9, "connection_size": "1/2", "model_two_way": "G215", "model_three_way": "G315"},
{"max_cv": 17.4, "connection_size": "3/4", "model_two_way": "G219", "model_three_way": None},
{"max_cv": 23.7, "connection_size": "3/4", "model_two_way": "G220", "model_three_way": "G320"},
{"max_cv": 32.0, "connection_size": "1", "model_two_way": "G224", "model_three_way": None},
{"max_cv": 44.0, "connection_size": "1", "model_two_way": "G225", "model_three_way": "G325"},
{"max_cv": 63.0, "connection_size": "1-1/4", "model_two_way": "G232", "model_three_way": "G332"},
{"max_cv": 89.0, "connection_size": "1-1/2", "model_two_way": "G240", "model_three_way": "G340"},
{"max_cv": 126.0, "connection_size": "2", "model_two_way": "G250", "model_three_way": "G350"}
]
class OpenAIAgent:
def __init__(self, api_key):
self.api_key = api_key
openai.api_key = self.api_key
self.max_tokens = 3000
self.completion_model = 'gpt-3.5-turbo'
def get_completion(self, messages):
response = openai.ChatCompletion.create(
model=self.completion_model,
messages=messages,
temperature=0
)
return response.choices[0].message['content']
def generate_insights(self, insights_prompt):
messages = [
{"role": "system", "content": "You are a knowledgeable assistant specializing in valve selection."},
{"role": "user", "content": insights_prompt}
]
response = self.get_completion(messages)
return response.strip()
def generate_valve_insights(self, valve_data, product_literature):
insights_prompt = f"Select a valve for a flow rate of {valve_data['flow_rate']} GPM, \
delta P of {valve_data['delta_p']} PSI, specific gravity of {valve_data['specific_gravity']}, \
fluid type of {valve_data['fluid_type']}, and is_three_way={valve_data['is_three_way']} based on \
the product literature of available valves {json.dumps(product_literature)} \
based on the process that controls engineer's do in {json.dumps(valve_data)}."
return self.generate_insights(insights_prompt)
def get_valve_selection(flow_rate, delta_p, specific_gravity, fluid_type, is_three_way, product_literature, openai_agent):
valve_data = {
"cv": flow_rate * ((delta_p / specific_gravity) ** 0.5),
"flow_rate": flow_rate,
"selected_valve": None,
"delta_p": delta_p,
"specific_gravity": specific_gravity,
"fluid_type": fluid_type,
"is_three_way": is_three_way,
"selection_considerations": {
"valve_flow_characteristic": "Ensure matching with the application (linear, equal percentage, quick opening, etc.)",
"size": "Suitable to the piping and flow requirements.",
"valve_body_and_trim_materials": "Compatible with the fluid and operating conditions.",
"noise": "Within acceptable limits.",
"cavitation_or_flashing": "Analyze and mitigate potential for damage.",
"actuator_type_and_size": "Suitable and adequately sized for the application.",
"dynamic_response": "Effective response to control signal changes and stable in the control loop."
},
"final_selection_and_verification": {
"documentation": "Ensure all calculations and selections are documented.",
"verification": "Validate under actual operating conditions.",
"feedback": "Obtain and utilize feedback from the operational team."
}
}
# Call the API with the organized data and avoid nested calls
insights = openai_agent.generate_valve_insights(valve_data, product_literature)
return insights
# Example usage
api_key = "YOUR_OPENAI_API_KEY"
openai_agent = OpenAIAgent(api_key)
insights = get_valve_selection(flow_rate, delta_p, specific_gravity, fluid_type, is_three_way, product_literature, openai_agent)
print(insights)
'''
Based on the given information, we need to select a valve for a flow rate of 5 GPM, delta P of 3 PSI, specific gravity of 1, fluid type of water, and is_three_way=False.
From the available valve options, we can consider the following two-way valves:
1. Model: G212
- Max CV: 1.3
- Connection Size: 1/2
2. Model: G213
- Max CV: 4.1
- Connection Size: 1/2
3. Model: G214
- Max CV: 7.0
- Connection Size: 1/2
4. Model: G215
- Max CV: 13.9
- Connection Size: 1/2
5. Model: G219
- Max CV: 17.4
- Connection Size: 3/4
6. Model: G220
- Max CV: 23.7
- Connection Size: 3/4
7. Model: G224
- Max CV: 32.0
- Connection Size: 1
8. Model: G225
- Max CV: 44.0
- Connection Size: 1
9. Model: G232
- Max CV: 63.0
- Connection Size: 1-1/4
10. Model: G240
- Max CV: 89.0
- Connection Size: 1-1/2
11. Model: G250
- Max CV: 126.0
- Connection Size: 2
To make the selection, we need to consider the valve's CV (flow coefficient) value. The CV value represents the flow capacity of the valve. We can calculate the required CV value using the formula:
CV = Flow Rate / (sqrt(delta P) * Specific Gravity)
CV = 5 / (sqrt(3) * 1) = 2.886751345948129
Based on the calculated CV value, we can select the valve with the closest or slightly higher CV value. In this case, the valve with the closest CV value is G213 with a CV of 4.1. Therefore, the recommended valve for this application is Model G213 with a connection size of 1/2.
Please note that this selection is based on the given information and the process followed by control engineers. It is always recommended to verify the selection under actual operating conditions and consider other selection considerations mentioned in the process, such as valve flow characteristic, size, valve body and trim materials, noise, cavitation or flashing, actuator type and size, and dynamic response.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment