rosemariafontana commited on
Commit
632b9a9
·
verified ·
1 Parent(s): 471eb6e

Update script_for_automation.py

Browse files
Files changed (1) hide show
  1. script_for_automation.py +168 -9
script_for_automation.py CHANGED
@@ -1,4 +1,5 @@
1
  import requests
 
2
 
3
  # The purpose of this script is to automate running a bunch of tests
4
  # This script will take an input folder
@@ -23,10 +24,17 @@ import requests
23
 
24
  BASEROW_API_KEY = os.getenv("BASEROW_API_KEY")
25
 
26
- def get_baserow_data():
27
  BASEROW_API_BASE = "https://baserow.f11804a1.federatedcomputer.net/api"
 
 
 
 
 
 
28
  TABLE_ID = "560"
29
- baserow_url = f"{BASEROW_API_BASE}/database/rows/table/{TABLE_ID}/?user_field_names=true"
 
30
 
31
  headers = {
32
  "Authorization": f"Token {os.environ["BASEROW_API_KEY"]}",
@@ -34,7 +42,7 @@ def get_baserow_data():
34
  }
35
 
36
  try:
37
- response = requests.get(baserow_url, headers=headers)
38
  response.raise_for_status()
39
  rows = response.json()
40
  results = rows.get("results", [])
@@ -46,26 +54,177 @@ def get_baserow_data():
46
  liz_carrot_plantings_gold_standard = row.get("Plantings and Fields - Gold Standard")
47
  liz_carrot_interactions_gold_standard = row.get("Interactions - Gold Standard")
48
  liz_carrot_trials_gold_standard = row.get("Trials - Gold Standard")
 
 
 
 
49
  elif row.get("id") == 3:
50
  ben_soybean_plantings_gold_standard = row.get("Plantings and Fields - Gold Standard")
51
  ben_soybean_interactions_gold_standard = row.get("Interactions - Gold Standard")
52
  ben_soybean_trials_gold_standard = row.get("Trials - Gold Standard")
 
 
 
 
53
  elif row.get("id") == 5:
54
  wally_squash_plantings_gold_standard = row.get("Plantings and Fields - Gold Standard")
55
  wally_squash_interactions_gold_standard = row.get("Interactions - Gold Standard")
56
  wally_squash_trials_gold_standard = row.get("Trials - Gold Standard")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- result_list = [
59
- liz_carrot_plantings_gold_standard, liz_carrot_interactions_gold_standard, liz_carrot_trials_gold_standard,
60
- ben_soybean_plantings_gold_standard, ben_soybean_interactions_gold_standard, ben_soybean_trials_gold_standard,
61
- wally_squash_plantings_gold_standard, wally_squash_interactions_gold_standard, wally_squash_trials_gold_standard
62
- ]
63
 
64
- return result_list
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  except requests.exceptions.RequestException as e:
67
  print(f"Failed to fetch rows: {e}")
68
 
 
 
 
 
 
 
 
 
 
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
 
 
 
 
 
 
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
+ from jsondiff import diff
3
 
4
  # The purpose of this script is to automate running a bunch of tests
5
  # This script will take an input folder
 
24
 
25
  BASEROW_API_KEY = os.getenv("BASEROW_API_KEY")
26
 
27
+ def get_baserow_url(table_id):
28
  BASEROW_API_BASE = "https://baserow.f11804a1.federatedcomputer.net/api"
29
+ return f"{BASEROW_API_BASE}/database/rows/table/{table_id}/?user_field_names=true"
30
+
31
+ def get_baserow_data():
32
+ # This is to get the gold standards from baserow
33
+ # We will also get the input data
34
+
35
  TABLE_ID = "560"
36
+
37
+ BASEROW_URL = get_baserow_url(TABLE_ID)
38
 
39
  headers = {
40
  "Authorization": f"Token {os.environ["BASEROW_API_KEY"]}",
 
42
  }
43
 
44
  try:
45
+ response = requests.get(BASEROW_URL, headers=headers)
46
  response.raise_for_status()
47
  rows = response.json()
48
  results = rows.get("results", [])
 
54
  liz_carrot_plantings_gold_standard = row.get("Plantings and Fields - Gold Standard")
55
  liz_carrot_interactions_gold_standard = row.get("Interactions - Gold Standard")
56
  liz_carrot_trials_gold_standard = row.get("Trials - Gold Standard")
57
+
58
+ liz_carrot_input_data_raw_interview = row.get("Raw Interview")
59
+ liz_carrot_otter_summary_preprocessing = row.get("Otter Summary")
60
+ liz_carrot_greg_summary_preprocessing = row.get("Post-Interview Summary")
61
  elif row.get("id") == 3:
62
  ben_soybean_plantings_gold_standard = row.get("Plantings and Fields - Gold Standard")
63
  ben_soybean_interactions_gold_standard = row.get("Interactions - Gold Standard")
64
  ben_soybean_trials_gold_standard = row.get("Trials - Gold Standard")
65
+
66
+ ben_soybean_input_data_raw_interview = row.get("Raw Interview")
67
+ ben_soybean_otter_summary_preprocessing = row.get("Otter Summary")
68
+ ben_soybean_greg_summary_preprocessing = row.get("Post-Interview Summary")
69
  elif row.get("id") == 5:
70
  wally_squash_plantings_gold_standard = row.get("Plantings and Fields - Gold Standard")
71
  wally_squash_interactions_gold_standard = row.get("Interactions - Gold Standard")
72
  wally_squash_trials_gold_standard = row.get("Trials - Gold Standard")
73
+
74
+ wally_squash_input_data_raw_interview = row.get("Raw Interview")
75
+ wally_squash_otter_summary_preprocessing = row.get("Otter Summary")
76
+ wally_squash_greg_summary_preprocessing = row.get("Post-Interview Summary")
77
+
78
+ gold_standards = {
79
+ "planting_gold_standards": {
80
+ "liz_carrot": liz_carrot_plantings_gold_standard,
81
+ "ben_soybean": ben_soybean_plantings_gold_standard,
82
+ "wally_squash": wally_squash_plantings_gold_standard
83
+ },
84
+ "interactions_gold_standards": {
85
+ "liz_carrot": liz_carrot_interactions_gold_standard,
86
+ "ben_soybean": ben_soybean_interactions_gold_standard,
87
+ "wally_squash": wally_squash_interactions_gold_standard
88
+ },
89
+ "trial_gold_standards": {
90
+ "liz_carrot": liz_carrot_trials_gold_standard,
91
+ "ben_soybean": ben_soybean_trials_gold_standard,
92
+ "wally_squash": wally_squash_trials_gold_standard
93
+ }
94
+ }
95
 
96
+ # How to retrieve this data
97
+ # liz_carrot_planting = gold_standards["planting_gold_standards"]["liz_carrot"]
98
+ # ben_soybean_interactions = gold_standards["interactions_gold_standards"]["ben_soybean"]
99
+ # wally_squash_trial = gold_standards["trial_gold_standards"]["wally_squash"]
 
100
 
101
+ input_data = {
102
+ "raw_interview": {
103
+ "liz_carrot": liz_carrot_input_data_raw_interview,
104
+ "ben_soybean": ben_soybean_input_data_raw_interview,
105
+ "wally_squash": wally_squash_input_data_raw_interview
106
+ },
107
+ "otter_summary": {
108
+ "liz_carrot": liz_carrot_otter_summary_preprocessing,
109
+ "ben_soybean": ben_soybean_otter_summary_preprocessing,
110
+ "wally_squash": wally_squash_otter_summary_preprocessing
111
+ },
112
+ "summary": {
113
+ "liz_carrot": liz_carrot_greg_summary_preprocessing,
114
+ "ben_soybean": ben_soybean_greg_summary_preprocessing,
115
+ "wally_squash": wally_squash_greg_summary_preprocessing
116
+ }
117
+ }
118
+
119
+ return gold_standards, input_data
120
 
121
  except requests.exceptions.RequestException as e:
122
  print(f"Failed to fetch rows: {e}")
123
 
124
+ def get_recipes():
125
+ TABLE_ID = "578"
126
+
127
+ BASEROW_URL = get_baserow_url(TABLE_ID)
128
+
129
+ headers = {
130
+ "Authorization": f"Token {os.environ["BASEROW_API_KEY"]}",
131
+ "Content-Type": "application/json"
132
+ }
133
 
134
+ try:
135
+ response = requests.get(BASEROW_URL, headers=headers)
136
+ response.raise_for_status()
137
+ rows = response.json()
138
+ results = rows.get("results", [])
139
+
140
+ my_recipes = []
141
+ for row in results:
142
+ print(f"Row ID: {row.get('id')}, Data: {row}")
143
+ recipe_schema_processing_model = row.get("Schema Processing Model")
144
+ pre_processing_strategy = row.get("Pre-Processing Strategy")
145
+ pre_processing_text = row.get("Preprocessing Model")
146
+ prompting_strategy = row.get("Prompting Strategy")
147
+ plantings_and_fields_prompt = row.get("Plantings and Fields Prompting Text")
148
+ interactions_prompt = row.get("Interactions Prompting Text")
149
+ treatments_prompt = row.get("Treatments Prompting Text")
150
+
151
+ recipe_dict = {
152
+ "schema_processing_model": recipe_schema_processing_model,
153
+ "pre_processing_strategy": pre_processing_strategy,
154
+ "pre_processing_text": pre_processing_text,
155
+ "prompting_strategy": prompting_strategy,
156
+ "plantings_and_fields_prompt": plantings_and_fields_prompt,
157
+ "interactions_prompt": interactions_prompt,
158
+ "treatments_prompt": treatments_prompt
159
+ }
160
+
161
+ my_recipes.append(recipe_dict)
162
+
163
+ return my_recipes
164
+
165
+ except requests.exceptions.RequestException as e:
166
+ print(f"Failed to fetch rows: {e}")
167
+
168
+ def fill_out_survey(recipe_dict, input_data):
169
+ survey_id = "673b4994aef86f0533b3546c"
170
 
171
+ base_url = "https://app.surveystack.io/api/submissions"
172
+
173
+ if recipe_dict.get("pre_processing_text") is None:
174
+ pre_processing = False
175
+ pre_process = "no"
176
+ pre_process_model_version = "None"
177
 
178
+ # Set the prompting strategy to be a variable from the list
179
+ # Do this here
180
+
181
+ if pre_processing:
182
+ submission_data = {
183
+ "survey": survey_id,
184
+ "data": {
185
+ "inputstyle": "big-block-input-text",
186
+ "onelonginputtext": recipe_dict["schema_processing_model"],
187
+ "schema_prompt": {
188
+ "firstschemaprompt": recipe_dict["plantings_and_fields_prompt"],
189
+ "secondschemaprompt": recipe_dict["interactions_prompt"],
190
+ "thirdschemaprompt": recipe_dict["treatments_prompt"],
191
+ },
192
+ "parameters": {
193
+ "model_version": recipe_dict["schema_processing_model"],
194
+ "pre_process": ["yes"],
195
+ "promptstyle": recipe_dict["prompting_strategy"], # replace this one
196
+ "preprocessmodelversion": "2.0",
197
+ "multiplepreprompts": "no",
198
+ "prepromptstyle": recipe_dict["pre_processing_strategy"],
199
+ "preprocessingprompt1": recipe_dict["pre_processing_text"],
200
+ }
201
+ }
202
+ }
203
+
204
+ else:
205
+ submission_data = {
206
+ "survey": survey_id,
207
+ "data": {
208
+ "inputstyle": "big-block-input-text",
209
+ "onelonginputtext": recipe_dict["schema_processing_model"],
210
+ "schema_prompt": {
211
+ "firstschemaprompt": recipe_dict["plantings_and_fields_prompt"],
212
+ "secondschemaprompt": recipe_dict["interactions_prompt"],
213
+ "thirdschemaprompt": recipe_dict["treatments_prompt"],
214
+ },
215
+ "parameters": {
216
+ "model_version": recipe_dict["schema_processing_model"],
217
+ "pre_process": "no",
218
+ "prompt_style": recipe_dict["prompting_strategy"], # replace this one
219
+ }
220
+ }
221
+ }
222
+
223
+
224
+
225
+ return "pumpkin"
226
+
227
+ def drive_process():
228
+ # this is to drive the processing process
229
+ return "banana"
230
+