Update process_data.py
Browse files- process_data.py +14 -21
process_data.py
CHANGED
|
@@ -118,7 +118,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 118 |
input_data: (dict) The input data, preprocessed, from the user. Aka what will fill in the JSON
|
| 119 |
input_data["input_text"] = (str) the preprocessed input text
|
| 120 |
input_data["input_context"] = (str) depending on levers, empty or what is put in front of the prompt
|
| 121 |
-
input_data["input_text_pieces"] = (dict) containing the individual split up prompt pieces: field_data_input, planting_data_input,
|
| 122 |
|
| 123 |
parameters: (dict) All of the individual parameters and "flippers"
|
| 124 |
parameters["model_version"] = (str) what model should be used
|
|
@@ -142,14 +142,14 @@ def generate_json_pieces(input_data, parameters):
|
|
| 142 |
print("Pre prompt is true")
|
| 143 |
field_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["field_data_input"]
|
| 144 |
planting_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["planting_data_input"]
|
| 145 |
-
|
| 146 |
soil_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["soil_data_input"]
|
| 147 |
yield_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["yield_data_input"]
|
| 148 |
else:
|
| 149 |
print("Pre prompt is false")
|
| 150 |
field_data_input = input_data["input_text_pieces"]["field_data_input"]
|
| 151 |
planting_data_input = input_data["input_text_pieces"]["planting_data_input"]
|
| 152 |
-
|
| 153 |
soil_data_input = input_data["input_text_pieces"]["soil_data_input"]
|
| 154 |
yield_data_input = input_data["input_text_pieces"]["yield_data_input"]
|
| 155 |
|
|
@@ -166,8 +166,8 @@ def generate_json_pieces(input_data, parameters):
|
|
| 166 |
# figure out what happens when there's
|
| 167 |
# chaining, pre-prompts, context, etc ....
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
# farm_prompt = input_data["input_text_pieces"]["field_data_input"] + farm_prompt
|
| 172 |
# farm_prompt = input_data["input_text_pieces"]["field_data_input"] + farm_prompt
|
| 173 |
# farm_prompt = input_data["input_text_pieces"]["field_data_input"] + farm_prompt
|
|
@@ -179,7 +179,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 179 |
model=model_version, # Use GPT model that supports structured output
|
| 180 |
messages=[
|
| 181 |
{"role": "system", "content": field_prompt},
|
| 182 |
-
{"role": "user", "content":
|
| 183 |
],
|
| 184 |
response_format=FarmActivitiesLite,
|
| 185 |
)
|
|
@@ -188,7 +188,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 188 |
model=model_version, # Use GPT model that supports structured output
|
| 189 |
messages=[
|
| 190 |
{"role": "system", "content": plant_prompt},
|
| 191 |
-
{"role": "user", "content":
|
| 192 |
],
|
| 193 |
response_format=PlantingLite,
|
| 194 |
)
|
|
@@ -197,7 +197,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 197 |
model=model_version, # Use GPT model that supports structured output
|
| 198 |
messages=[
|
| 199 |
{"role": "system", "content": log_prompt},
|
| 200 |
-
{"role": "user", "content":
|
| 201 |
],
|
| 202 |
response_format=Log,
|
| 203 |
)
|
|
@@ -206,7 +206,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 206 |
model=model_version, # Use GPT model that supports structured output
|
| 207 |
messages=[
|
| 208 |
{"role": "system", "content": soil_prompt},
|
| 209 |
-
{"role": "user", "content":
|
| 210 |
],
|
| 211 |
response_format=Soil,
|
| 212 |
)
|
|
@@ -215,7 +215,7 @@ def generate_json_pieces(input_data, parameters):
|
|
| 215 |
model=model_version, # Use GPT model that supports structured output
|
| 216 |
messages=[
|
| 217 |
{"role": "system", "content": yield_prompt},
|
| 218 |
-
{"role": "user", "content":
|
| 219 |
],
|
| 220 |
response_format=Yield,
|
| 221 |
)
|
|
@@ -244,7 +244,7 @@ def pre_processing(input_data, parameters):
|
|
| 244 |
input_data: (dict) The input data, preprocessed, from the user. Aka what will fill in the JSON
|
| 245 |
input_data["input_text"] = (str) the preprocessed input text
|
| 246 |
input_data["input_context"] = (str) depending on levers, empty or what is put in front of the prompt
|
| 247 |
-
input_data["input_text_pieces"] = (dict) containing the individual split up prompt pieces: field_data_input, planting_data_input,
|
| 248 |
|
| 249 |
parameters: (dict) All of the individual parameters and "flippers"
|
| 250 |
parameters["model_version"] = (str) what model should be used
|
|
@@ -261,14 +261,6 @@ def pre_processing(input_data, parameters):
|
|
| 261 |
if input_data["stepwise_json_creation"] == "stepwisejsoncreation":
|
| 262 |
|
| 263 |
if parameters["chaining"]:
|
| 264 |
-
pre_processing_prompts = [parameters["context_pre_prompt"], parameters["summary_pre_prompt"], parameters["conversation_pre_prompt"], parameters["example_pre_prompt"]]
|
| 265 |
-
one_giant_preprompt = ""
|
| 266 |
-
input_data["input_text_pieces"]["pre_processed_pieces"] = {}
|
| 267 |
-
|
| 268 |
-
for pre_prompt in pre_processing_prompts:
|
| 269 |
-
if pre_prompt:
|
| 270 |
-
one_giant_preprompt += pre_prompt
|
| 271 |
-
|
| 272 |
for text_label, text_body in input_data["input_text_pieces"].items():
|
| 273 |
|
| 274 |
response = client.chat.completions.create(
|
|
@@ -282,7 +274,8 @@ def pre_processing(input_data, parameters):
|
|
| 282 |
response_text = response.choices[0].message.content
|
| 283 |
input_data["input_text_pieces"]["pre_processed_pieces"][text_label] = response_text
|
| 284 |
else:
|
| 285 |
-
|
|
|
|
| 286 |
input_data["input_context"] = input_context
|
| 287 |
return input_data
|
| 288 |
|
|
@@ -342,7 +335,7 @@ def process_specifications(input_data, parameters):
|
|
| 342 |
input_data: (dict) The input data, preprocessed, from the user. Aka what will fill in the JSON
|
| 343 |
input_data["input_text"] = (str) the preprocessed input text
|
| 344 |
input_data["input_context"] = (str) depending on levers, empty or what is put in front of the prompt
|
| 345 |
-
input_data["input_text_pieces"] = (dict) containing the individual split up prompt pieces: field_data_input, planting_data_input,
|
| 346 |
|
| 347 |
parameters: (dict) All of the individual parameters and "flippers"
|
| 348 |
parameters["pre_prompt"] = (bool) whether or not there is a pre-prompt to process through pre_processing()
|
|
|
|
| 118 |
input_data: (dict) The input data, preprocessed, from the user. Aka what will fill in the JSON
|
| 119 |
input_data["input_text"] = (str) the preprocessed input text
|
| 120 |
input_data["input_context"] = (str) depending on levers, empty or what is put in front of the prompt
|
| 121 |
+
input_data["input_text_pieces"] = (dict) containing the individual split up prompt pieces: field_data_input, planting_data_input, log_data_input, soil_data_input, yield_data_input
|
| 122 |
|
| 123 |
parameters: (dict) All of the individual parameters and "flippers"
|
| 124 |
parameters["model_version"] = (str) what model should be used
|
|
|
|
| 142 |
print("Pre prompt is true")
|
| 143 |
field_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["field_data_input"]
|
| 144 |
planting_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["planting_data_input"]
|
| 145 |
+
log_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["log_data_input"]
|
| 146 |
soil_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["soil_data_input"]
|
| 147 |
yield_data_input = input_data["input_text_pieces"]["pre_processed_pieces"]["yield_data_input"]
|
| 148 |
else:
|
| 149 |
print("Pre prompt is false")
|
| 150 |
field_data_input = input_data["input_text_pieces"]["field_data_input"]
|
| 151 |
planting_data_input = input_data["input_text_pieces"]["planting_data_input"]
|
| 152 |
+
log_data_input = input_data["input_text_pieces"]["log_data_input"]
|
| 153 |
soil_data_input = input_data["input_text_pieces"]["soil_data_input"]
|
| 154 |
yield_data_input = input_data["input_text_pieces"]["yield_data_input"]
|
| 155 |
|
|
|
|
| 166 |
# figure out what happens when there's
|
| 167 |
# chaining, pre-prompts, context, etc ....
|
| 168 |
|
| 169 |
+
if input_data["input_context"]:
|
| 170 |
+
field_prompt = input_data["input_text_pieces"]["field_data_input"] + field_prompt
|
| 171 |
# farm_prompt = input_data["input_text_pieces"]["field_data_input"] + farm_prompt
|
| 172 |
# farm_prompt = input_data["input_text_pieces"]["field_data_input"] + farm_prompt
|
| 173 |
# farm_prompt = input_data["input_text_pieces"]["field_data_input"] + farm_prompt
|
|
|
|
| 179 |
model=model_version, # Use GPT model that supports structured output
|
| 180 |
messages=[
|
| 181 |
{"role": "system", "content": field_prompt},
|
| 182 |
+
{"role": "user", "content": field_data_input}
|
| 183 |
],
|
| 184 |
response_format=FarmActivitiesLite,
|
| 185 |
)
|
|
|
|
| 188 |
model=model_version, # Use GPT model that supports structured output
|
| 189 |
messages=[
|
| 190 |
{"role": "system", "content": plant_prompt},
|
| 191 |
+
{"role": "user", "content": planting_data_input}
|
| 192 |
],
|
| 193 |
response_format=PlantingLite,
|
| 194 |
)
|
|
|
|
| 197 |
model=model_version, # Use GPT model that supports structured output
|
| 198 |
messages=[
|
| 199 |
{"role": "system", "content": log_prompt},
|
| 200 |
+
{"role": "user", "content": log_data_input}
|
| 201 |
],
|
| 202 |
response_format=Log,
|
| 203 |
)
|
|
|
|
| 206 |
model=model_version, # Use GPT model that supports structured output
|
| 207 |
messages=[
|
| 208 |
{"role": "system", "content": soil_prompt},
|
| 209 |
+
{"role": "user", "content": soil_data_input}
|
| 210 |
],
|
| 211 |
response_format=Soil,
|
| 212 |
)
|
|
|
|
| 215 |
model=model_version, # Use GPT model that supports structured output
|
| 216 |
messages=[
|
| 217 |
{"role": "system", "content": yield_prompt},
|
| 218 |
+
{"role": "user", "content": yield_data_input}
|
| 219 |
],
|
| 220 |
response_format=Yield,
|
| 221 |
)
|
|
|
|
| 244 |
input_data: (dict) The input data, preprocessed, from the user. Aka what will fill in the JSON
|
| 245 |
input_data["input_text"] = (str) the preprocessed input text
|
| 246 |
input_data["input_context"] = (str) depending on levers, empty or what is put in front of the prompt
|
| 247 |
+
input_data["input_text_pieces"] = (dict) containing the individual split up prompt pieces: field_data_input, planting_data_input, log_data_input, soil_data_input, yield_data_input
|
| 248 |
|
| 249 |
parameters: (dict) All of the individual parameters and "flippers"
|
| 250 |
parameters["model_version"] = (str) what model should be used
|
|
|
|
| 261 |
if input_data["stepwise_json_creation"] == "stepwisejsoncreation":
|
| 262 |
|
| 263 |
if parameters["chaining"]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
for text_label, text_body in input_data["input_text_pieces"].items():
|
| 265 |
|
| 266 |
response = client.chat.completions.create(
|
|
|
|
| 274 |
response_text = response.choices[0].message.content
|
| 275 |
input_data["input_text_pieces"]["pre_processed_pieces"][text_label] = response_text
|
| 276 |
else:
|
| 277 |
+
# Add in here the other schemas (interactions and trials)
|
| 278 |
+
input_context = f"You are processing farm activity data. Here's important context of the data {parameters['combined_prompt']}. With this context in mind, "
|
| 279 |
input_data["input_context"] = input_context
|
| 280 |
return input_data
|
| 281 |
|
|
|
|
| 335 |
input_data: (dict) The input data, preprocessed, from the user. Aka what will fill in the JSON
|
| 336 |
input_data["input_text"] = (str) the preprocessed input text
|
| 337 |
input_data["input_context"] = (str) depending on levers, empty or what is put in front of the prompt
|
| 338 |
+
input_data["input_text_pieces"] = (dict) containing the individual split up prompt pieces: field_data_input, planting_data_input, log_data_input, soil_data_input, yield_data_input
|
| 339 |
|
| 340 |
parameters: (dict) All of the individual parameters and "flippers"
|
| 341 |
parameters["pre_prompt"] = (bool) whether or not there is a pre-prompt to process through pre_processing()
|