nora-lib-impl 1.3.0.dev1__tar.gz → 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/PKG-INFO +1 -1
  2. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/interactions/interactions_service.py +42 -20
  3. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/interactions/models.py +5 -23
  4. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib_impl.egg-info/PKG-INFO +1 -1
  5. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/README.md +0 -0
  6. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/pyproject.toml +0 -0
  7. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/setup.cfg +0 -0
  8. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/setup.py +0 -0
  9. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/__init__.py +0 -0
  10. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/__init__.py +0 -0
  11. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/context/__init__.py +0 -0
  12. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/context/agent_context.py +0 -0
  13. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/context/context_service.py +0 -0
  14. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/context/models.py +0 -0
  15. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/interactions/__init__.py +0 -0
  16. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/interactions/step_progress.py +0 -0
  17. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/pubsub.py +0 -0
  18. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/tasks/__init__.py +0 -0
  19. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/impl/tasks/state.py +0 -0
  20. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/progress/__init__.py +0 -0
  21. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/progress/models.py +0 -0
  22. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/progress/reporter.py +0 -0
  23. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/py.typed +0 -0
  24. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/serializers.py +0 -0
  25. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/tasks/__init__.py +0 -0
  26. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/tasks/models.py +0 -0
  27. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib/tasks/state.py +0 -0
  28. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib_impl.egg-info/SOURCES.txt +0 -0
  29. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib_impl.egg-info/dependency_links.txt +0 -0
  30. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib_impl.egg-info/requires.txt +0 -0
  31. {nora_lib_impl-1.3.0.dev1 → nora_lib_impl-1.4.0}/src/nora_lib_impl.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nora_lib-impl
3
- Version: 1.3.0.dev1
3
+ Version: 1.4.0
4
4
  Summary: For making and coordinating agents and tools
5
5
  Home-page: https://github.com/allenai/nora_lib/impl
6
6
  Requires-Python: >=3.9
@@ -45,9 +45,10 @@ class InteractionsService:
45
45
  if token:
46
46
  self.auth = BearerAuth(token)
47
47
 
48
- def _post(self, url: str, json: Dict[str, Any]) -> Response:
49
- return requests.post(
50
- url,
48
+ def _call(self, method: str, url: str, json: Dict[str, Any]) -> Response:
49
+ return requests.request(
50
+ method=method,
51
+ url=url,
51
52
  json=json,
52
53
  auth=self.auth,
53
54
  timeout=self.timeout,
@@ -61,7 +62,8 @@ class InteractionsService:
61
62
  :param virtual_thread_id: Optional ID of a virtual thread to associate with the message
62
63
  """
63
64
  message_url = f"{self.base_url}/interaction/v1/message"
64
- response = self._post(
65
+ response = self._call(
66
+ "post",
65
67
  message_url,
66
68
  message.model_dump(),
67
69
  )
@@ -85,8 +87,15 @@ class InteractionsService:
85
87
  Save an event to the Interaction Store. Returns an event id.
86
88
  :param virtual_thread_id: Optional ID of a virtual thread to associate with the event
87
89
  """
88
- event_url = f"{self.base_url}/interaction/v1/event"
89
- response = self._post(
90
+ if event.event_id:
91
+ event_url = f"{self.base_url}/interaction/v1/event/{event.event_id}"
92
+ method = "patch"
93
+ else:
94
+ event_url = f"{self.base_url}/interaction/v1/event"
95
+ method = "post"
96
+
97
+ response = self._call(
98
+ method,
90
99
  event_url,
91
100
  event.model_dump(),
92
101
  )
@@ -105,14 +114,17 @@ class InteractionsService:
105
114
  timestamp=event.timestamp,
106
115
  )
107
116
  self.save_event(event)
108
- response_message = json.loads(response.text)
109
- event_id = response_message["event_id"]
110
- return event_id
117
+ response_message = response.json()
118
+ if not event.event_id:
119
+ # If this is a new event, then we should have gotten back its ID.
120
+ event.event_id = response_message["event_id"]
121
+ return event.event_id
111
122
 
112
123
  def save_thread(self, thread: Thread) -> None:
113
124
  """Save a thread to the Interactions API"""
114
125
  thread_url = f"{self.base_url}/interaction/v1/thread"
115
- response = self._post(
126
+ response = self._call(
127
+ "post",
116
128
  thread_url,
117
129
  thread.model_dump(),
118
130
  )
@@ -191,7 +203,8 @@ class InteractionsService:
191
203
  },
192
204
  }
193
205
 
194
- response = self._post(
206
+ response = self._call(
207
+ "post",
195
208
  message_search_url,
196
209
  request_body,
197
210
  )
@@ -226,7 +239,8 @@ class InteractionsService:
226
239
  def save_annotation(self, annotation: AnnotationBatch) -> None:
227
240
  """Save an annotation to the Interactions API"""
228
241
  annotation_url = f"{self.base_url}/interaction/v1/annotation"
229
- response = self._post(
242
+ response = self._call(
243
+ "post",
230
244
  annotation_url,
231
245
  annotation.model_dump(),
232
246
  )
@@ -239,7 +253,8 @@ class InteractionsService:
239
253
  "id": message_id,
240
254
  "relations": {"thread": {}, "channel": {}, "events": {}, "annotations": {}},
241
255
  }
242
- response = self._post(
256
+ response = self._call(
257
+ "post",
243
258
  message_url,
244
259
  request_body,
245
260
  )
@@ -261,7 +276,8 @@ class InteractionsService:
261
276
  request_body = {
262
277
  "id": event_id,
263
278
  }
264
- response = self._post(
279
+ response = self._call(
280
+ "post",
265
281
  event_url,
266
282
  request_body,
267
283
  )
@@ -285,7 +301,8 @@ class InteractionsService:
285
301
  thread_event_types=thread_event_types,
286
302
  most_recent=most_recent,
287
303
  )
288
- response = self._post(
304
+ response = self._call(
305
+ "post",
289
306
  message_url,
290
307
  request_body,
291
308
  )
@@ -307,7 +324,8 @@ class InteractionsService:
307
324
  min_timestamp=min_timestamp,
308
325
  most_recent=most_recent,
309
326
  )
310
- response = self._post(
327
+ response = self._call(
328
+ "post",
311
329
  message_url,
312
330
  request_body,
313
331
  )
@@ -338,7 +356,8 @@ class InteractionsService:
338
356
  },
339
357
  }
340
358
 
341
- response = self._post(
359
+ response = self._call(
360
+ "post",
342
361
  thread_search_url,
343
362
  request_body,
344
363
  )
@@ -359,7 +378,8 @@ class InteractionsService:
359
378
  },
360
379
  }
361
380
 
362
- response = self._post(
381
+ response = self._call(
382
+ "post",
363
383
  message_search_url,
364
384
  request_body,
365
385
  )
@@ -418,7 +438,8 @@ class InteractionsService:
418
438
  },
419
439
  },
420
440
  }
421
- response = self._post(
441
+ response = self._call(
442
+ "post",
422
443
  channel_search_url,
423
444
  request_body,
424
445
  )
@@ -453,7 +474,8 @@ class InteractionsService:
453
474
  "events": event_query,
454
475
  },
455
476
  }
456
- response = self._post(
477
+ response = self._call(
478
+ "post",
457
479
  thread_search_url,
458
480
  request_body,
459
481
  )
@@ -17,6 +17,7 @@ from pydantic import (
17
17
  field_validator,
18
18
  model_validator,
19
19
  )
20
+ from typing_extensions import deprecated
20
21
 
21
22
 
22
23
  class Surface(str, Enum):
@@ -94,6 +95,7 @@ class Message(BaseModel):
94
95
  class Event(BaseModel):
95
96
  """event object to be sent to the interactions service; requires association with a message, thread or channel id"""
96
97
 
98
+ event_id: Optional[str] = None
97
99
  type: str
98
100
  actor_id: UUID = Field(
99
101
  description="identifies actor writing the event to the interaction service"
@@ -203,29 +205,9 @@ class Thread(BaseModel):
203
205
  status: ThreadStatus
204
206
 
205
207
 
206
- class ReturnedEvent(BaseModel):
207
- """Event format returned by the interaction service"""
208
-
209
- event_id: str
210
- type: str
211
- actor_id: UUID = Field(
212
- description="identifies actor writing the event to the interaction service"
213
- )
214
- timestamp: datetime
215
- text: Optional[str] = None
216
- data: dict = Field(default_factory=dict)
217
- message_id: Optional[str] = None
218
- thread_id: Optional[str] = None
219
- channel_id: Optional[str] = None
220
- surface: Optional[Surface] = None
221
-
222
- @field_serializer("actor_id")
223
- def serialize_actor_id(self, actor_id: UUID):
224
- return str(actor_id)
225
-
226
- @field_serializer("timestamp")
227
- def serialize_timestamp(self, timestamp: datetime):
228
- return timestamp.isoformat()
208
+ @deprecated("Use Event instead")
209
+ class ReturnedEvent(Event):
210
+ pass
229
211
 
230
212
 
231
213
  class ReturnedMessage(BaseModel):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nora_lib-impl
3
- Version: 1.3.0.dev1
3
+ Version: 1.4.0
4
4
  Summary: For making and coordinating agents and tools
5
5
  Home-page: https://github.com/allenai/nora_lib/impl
6
6
  Requires-Python: >=3.9