rosemariafontana commited on
Commit
e7a3afa
·
verified ·
1 Parent(s): 462da2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +387 -0
app.py CHANGED
@@ -8,6 +8,393 @@ os.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")
8
  MODEL_NAME = "claude-3-opus-20240229"
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def respond(message, tool_options, tool_name):
12
  if tool_options == "Force Use Specific Tool":
13
  message = client.messages.create(
 
8
  MODEL_NAME = "claude-3-opus-20240229"
9
 
10
 
11
+ tools = [
12
+ {
13
+ "name": "interactions_schema",
14
+ "description": "Record from an interview transcript of an interaction between a Technical Assistance Provider (TAP) and a producer the information about the people involved in the interview and important information discussed during the interaction using a well-structured JSON",
15
+ "input_schema": {
16
+ "type": "array",
17
+ "description": "Key summary information from an interaction (phone call, in person discussion, or post-conversation summary) with a producer by a technical assistance provider",
18
+ "items": {
19
+ "type": "object",
20
+ "description": "A single summarized interaction",
21
+ "properties": {
22
+ "people": {
23
+ "type": ["array", "null"],
24
+ "description": "An array of people involved in or mentioned in this interaction",
25
+ "items": {
26
+ "type": "object",
27
+ "description": "An individual person and their role",
28
+ "properties": {
29
+ "name": {
30
+ "type": "string",
31
+ "description": "Name of this person",
32
+ },
33
+ "role": {
34
+ "type": ["string", "null"],
35
+ "enum": ["partner", "staff", "agronomist", "other"],
36
+ "description": "Role of this person",
37
+ }
38
+ },
39
+ "additionalProperties": false,
40
+ "required": [
41
+ "name",
42
+ "role"
43
+ ]
44
+ }
45
+ },
46
+ "date": {
47
+ "anyOf": [
48
+ {
49
+ "type": "null"
50
+ },
51
+ {
52
+ "type": "string",
53
+ "format": "date",
54
+ "description": "Date of the interaction",
55
+ },
56
+ ]
57
+ },
58
+ "next_meeting": {
59
+ "anyOf": [
60
+ {
61
+ "type": "null"
62
+ },
63
+ {
64
+ "type": "string",
65
+ "format": "date",
66
+ "description": "Proposed date for the next interaction",
67
+ },
68
+ ]
69
+ },
70
+ "next_steps": {
71
+ "type": ["array", "null"],
72
+ "description": "Array containing a list of next steps from the interaction",
73
+ "items": {
74
+ "type": ["string", "null"],
75
+ "description": "An individual next step",
76
+ }
77
+ },
78
+ "summary": {
79
+ "type": ["string", "null"],
80
+ "description": "A summary of the interaction",
81
+ }
82
+ },
83
+ "additionalProperties": false,
84
+ "required": [
85
+ "people",
86
+ "date",
87
+ "next_meeting",
88
+ "next_steps",
89
+ "summary"
90
+ ]
91
+ }
92
+ }
93
+ },
94
+ {
95
+ "name": "plantings_and_fields_schema",
96
+ "description": "Record from an interview transcript of an interaction between a Technical Assistance Provider (TAP) and a producer the information regarding the crops planted, information regarding the fields the crops were planted on, and information regarding the activities that took place on the fields using a well-structured JSON",
97
+ "input_schema": {
98
+ "type": "array",
99
+ "description": "An array of the producer's fields and their plantings. Also includes the list of logs which are associated with those plantings",
100
+ "items": {
101
+ "type": "object",
102
+ "description": "An individual field",
103
+ "properties": {
104
+ "name": {
105
+ "type": "string",
106
+ "description": "The name of the field",
107
+ },
108
+ "description": {
109
+ "type": ["string", "null"],
110
+ "description": "The description of the field",
111
+ },
112
+ "plantings": {
113
+ "type": "array",
114
+ "description": "An array of all the plantings which have occurred on this field",
115
+ "items": {
116
+ "type": "object",
117
+ "description": "An individual planting",
118
+ "properties": {
119
+ "name": {
120
+ "type": ["string", "null"],
121
+ "description": "The name of the planting",
122
+ },
123
+ "status": {
124
+ "anyOf": [
125
+ {
126
+ "type": "null"
127
+ },
128
+ {
129
+ "type": "string",
130
+ "enum": ["active", "archived"],
131
+ "description": "The status of the planting. \"active\" is a planting which is currently still in the field. \"archived\" is a planting which is no longer in the field (has been terminated or harvested)",
132
+ },
133
+ ]
134
+ },
135
+ "crop": {
136
+ "type": "array",
137
+ "items": {
138
+ "type": ["string", "null"],
139
+ "description": "An array of the crops in this planting",
140
+ }
141
+ },
142
+ "variety": {
143
+ "type": "array",
144
+ "items": {
145
+ "type": ["string", "null"],
146
+ "description": "An array of the varieties in this planting",
147
+ }
148
+ },
149
+ "logs": {
150
+ "type": ["array", "null"],
151
+ "description": "An array of all logs that are associated with this individual planting",
152
+ "items": {
153
+ "type": "object",
154
+ "description": "An individual log",
155
+ "properties": {
156
+ "convention": {
157
+ "anyOf": [
158
+ {
159
+ "type": "null"
160
+ },
161
+ {
162
+ "type": "string",
163
+ "enum": ["log--activity", "log--observation", "log--activity--flaming", "log--activity--grazing", "log--activity--mowing", "log--activity--solarization", "log--activity--termination", "log--activity--tillage", "log--harvest--harvest", "log--input--herbicide_or_pesticide", "log--input--irrigation", "log--input--lime", "log--input--organic_matter", "log--input--seed_treatment", "log--input--seedling_treatment", "log--lab_test--modus_lab_test", "log--seeding--seeding", "log--transplanting--transplanting"],
164
+ "description": "This log's convention (ie this log's category or type)",
165
+ },
166
+ ]
167
+ },
168
+ "date": {
169
+ "anyOf": [
170
+ {
171
+ "type": "null"
172
+ },
173
+ {
174
+ "type": "string",
175
+ "format": "date",
176
+ "description": "The date of this log",
177
+ },
178
+ ]
179
+ },
180
+ "description": {
181
+ "type": ["string", "null"],
182
+ "description": "A description of the details of the log",
183
+ }
184
+ },
185
+ "additionalProperties": false,
186
+ "required": [
187
+ "convention",
188
+ "description",
189
+ "date"
190
+ ]
191
+ }
192
+ },
193
+ "soil": {
194
+ "type": ["object", "null"],
195
+ "description": "Information about the soil associated with or observed during the time of this planting",
196
+ "properties": {
197
+ "description": {
198
+ "type": ["string", "null"],
199
+ "description": "A general description of the soil",
200
+ },
201
+ "structure": {
202
+ "anyOf": [
203
+ {
204
+ "type": "null"
205
+ },
206
+ {
207
+ "type": "array",
208
+ "items": {
209
+ "type": "string",
210
+ "enum": ["clay", "sandy clay", "silty clay", "sandy clay loam", "silty clay loam", "clay loam", "sandy loam", "silt loam", "loam", "loamy sand", "sand", "silt"],
211
+ "description": "The structure of the soil using options from the major soil texture classes (sand, clay, silt)"
212
+ }
213
+ }
214
+ ]
215
+ },
216
+ "biology": {
217
+ "type": ["string", "null"],
218
+ "description": "Biological activity levels of the soil, including fluffiness, worms and bugs, and other evidence of soil biological activity",
219
+ }
220
+ },
221
+ "additionalProperties": false,
222
+ "required": [
223
+ "description",
224
+ "structure",
225
+ "biology"
226
+ ]
227
+ },
228
+ "yield": {
229
+ "type": ["object", "null"],
230
+ "properties": {
231
+ "quantity": {
232
+ "type": ["string", "null"],
233
+ "description": "A description of the the total yield (harvested amount) from this planting, including units when available",
234
+ },
235
+ "quality": {
236
+ "type": ["string", "null"],
237
+ "description": "The product quality of the harvest. For example, small or large fruits, sweet or tart flavor, easily molding or containing mold, high number of product seconds, etc.",
238
+ }
239
+ },
240
+ "additionalProperties": false,
241
+ "required": [
242
+ "quantity",
243
+ "quality"
244
+ ]
245
+ }
246
+ },
247
+ "additionalProperties": false,
248
+ "required": [
249
+ "name",
250
+ "status",
251
+ "crop",
252
+ "variety",
253
+ "logs",
254
+ "soil",
255
+ "yield"
256
+ ]
257
+ }
258
+ }
259
+ },
260
+ "additionalProperties": false,
261
+ "required": [
262
+ "name",
263
+ "description",
264
+ "plantings"
265
+ ]
266
+ }
267
+ }
268
+ },
269
+ {
270
+ "name": "trials_and_treatments_schema",
271
+ "description": "Record from an interview transcript of an interaction between a Technical Assistance Provider (TAP) and a producer the information surrounding the scientific experiment that was performed using a well-structured JSON",
272
+ "input_schema": {
273
+ "type": "array",
274
+ "description": "An array of on-farm trials (ie experiments) performed by producers with support from staff, agronomists and others",
275
+ "items": {
276
+ "type": "object",
277
+ "description": "An individual trial",
278
+ "properties": {
279
+ "name": {
280
+ "type": ["string", "null"],
281
+ "description": "The name of this trial"
282
+ },
283
+ "description": {
284
+ "type": ["string", "null"],
285
+ "description": "A description of this trial"
286
+ },
287
+ "treatments": {
288
+ "type": "array",
289
+ "description": "An array of different treatments (strips or blocks with the same conditions applied) performed by the partner",
290
+ "items": {
291
+ "type": "object",
292
+ "description": "An individual treatment",
293
+ "properties": {
294
+ "name": {
295
+ "type": ["string", "null"],
296
+ "description": "The treatment name"
297
+ },
298
+ "description": {
299
+ "type": ["string", "null"],
300
+ "description": "The treatment description, including the conditions within this treatment"
301
+ },
302
+ "crops": {
303
+ "type": ["array", "null"],
304
+ "description": "An array of crops being tested in this treatment",
305
+ "items": {
306
+ "type": "string",
307
+ "description": "An individual crop"
308
+ }
309
+ },
310
+ "fields": {
311
+ "type": ["array", "null"],
312
+ "description": "An array of fields in which this treatment has occurred or will occur",
313
+ "items": {
314
+ "type": "string",
315
+ "description": "An individual field where this treatment has or will occur"
316
+ }
317
+ }
318
+ },
319
+ "additionalProperties": false,
320
+ "required": [
321
+ "name",
322
+ "description",
323
+ "crops",
324
+ "fields"
325
+ ]
326
+
327
+ }
328
+ },
329
+ "learnings": {
330
+ "type": ["array", "null"],
331
+ "description": "An array of lessons learned from this experiment",
332
+ "items": {
333
+ "type": "string",
334
+ "description": "An individual lesson learned"
335
+ }
336
+ },
337
+ "variables": {
338
+ "type": "object",
339
+ "description": "Variables (ie factors) in this experiment. Some variables are constant (controlled) and some will vary in order to learn something (independent)",
340
+ "properties": {
341
+ "controlled": {
342
+ "type": ["array", "null"],
343
+ "description": "An array of controlled variables, which will be constant (controlled) across all trials",
344
+ "items": {
345
+ "type": "string",
346
+ "description": "An individual controlled variable, meaning a variable which is constant across all trials"
347
+ }
348
+ },
349
+ "independent": {
350
+ "type": ["array", "null"],
351
+ "description": "An array of independent variables (ie treatments), which will be intentionally varied across one or more trials",
352
+ "items": {
353
+ "type": "string",
354
+ "description": "An individual independent variable (ie treatments), meaning a variable which will be intentionally varied across one or more trials"
355
+ }
356
+ },
357
+ "outcome": {
358
+ "type": ["array", "null"],
359
+ "description": "An array of outcome variables (ie dependent or response variables) which is hypothesized to change across the trials",
360
+ "items": {
361
+ "type": "string",
362
+ "description": "An individual outcome variable (ie dependent or response variables)"
363
+ }
364
+ }
365
+ },
366
+ "additionalProperties": false,
367
+ "required": [
368
+ "controlled",
369
+ "independent",
370
+ "outcome"
371
+ ]
372
+ },
373
+ "confounding_factors": {
374
+ "type": ["array", "null"],
375
+ "description": "An array of factors which may impact the outcomes of the experiment that were not planned for.",
376
+ "items": {
377
+ "type": "string",
378
+ "description": "An individual confounding factor"
379
+ }
380
+ }
381
+ },
382
+ "additionalProperties": false,
383
+ "required": [
384
+ "name",
385
+ "description",
386
+ "treatments",
387
+ "learnings",
388
+ "variables",
389
+ "confounding_factors"
390
+ ]
391
+ }
392
+
393
+ }
394
+ }
395
+ ]
396
+
397
+
398
  def respond(message, tool_options, tool_name):
399
  if tool_options == "Force Use Specific Tool":
400
  message = client.messages.create(