nora-lib 0.0.7.dev1__tar.gz → 0.1.7__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.
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/PKG-INFO +1 -1
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/context/context_service.py +2 -12
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/interactions/interactions_service.py +15 -80
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/interactions/models.py +0 -15
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib.egg-info/PKG-INFO +1 -1
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/setup.py +1 -1
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/README.md +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/__init__.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/context/__init__.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/context/models.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/interactions/__init__.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/py.typed +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/tasks/__init__.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/tasks/models.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib/tasks/state.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib.egg-info/SOURCES.txt +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib.egg-info/dependency_links.txt +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib.egg-info/requires.txt +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/nora_lib.egg-info/top_level.txt +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/pyproject.toml +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/setup.cfg +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/tests/tasks/__init__.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/tests/tasks/test_state.py +0 -0
- {nora_lib-0.0.7.dev1 → nora_lib-0.1.7}/tests/test_placeholder.py +0 -0
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
from
|
|
2
|
-
from typing import List, Optional
|
|
3
|
-
from uuid import UUID
|
|
1
|
+
from typing import Optional
|
|
4
2
|
|
|
5
3
|
from nora_lib.interactions.interactions_service import InteractionsService
|
|
6
|
-
from nora_lib.interactions.models import
|
|
7
|
-
ReturnedMessage,
|
|
8
|
-
ReturnedAgentContextMessage,
|
|
9
|
-
ReturnedAgentContextEvent,
|
|
10
|
-
EventType,
|
|
11
|
-
AgentMessageData,
|
|
12
|
-
Event,
|
|
13
|
-
)
|
|
14
|
-
from nora_lib.context.models import WrappedTaskObject
|
|
4
|
+
from nora_lib.interactions.models import ReturnedMessage
|
|
15
5
|
|
|
16
6
|
|
|
17
7
|
class ContextService:
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
import logging
|
|
3
1
|
import requests
|
|
4
|
-
from typing import
|
|
2
|
+
from typing import Optional
|
|
5
3
|
import json
|
|
6
4
|
|
|
7
5
|
from nora_lib.interactions.models import (
|
|
8
6
|
AnnotationBatch,
|
|
9
7
|
Event,
|
|
10
|
-
EventType,
|
|
11
8
|
Message,
|
|
12
9
|
ReturnedMessage,
|
|
13
10
|
ThreadRelationsResponse,
|
|
14
|
-
ThreadForkEventData,
|
|
15
11
|
)
|
|
16
12
|
|
|
17
13
|
|
|
@@ -83,11 +79,18 @@ class InteractionsService:
|
|
|
83
79
|
|
|
84
80
|
return res
|
|
85
81
|
|
|
86
|
-
def fetch_all_threads_by_channel(
|
|
82
|
+
def fetch_all_threads_by_channel(
|
|
83
|
+
self,
|
|
84
|
+
channel_id: str,
|
|
85
|
+
min_timestamp: str,
|
|
86
|
+
thread_event_types: Optional[list[str]] = None,
|
|
87
|
+
) -> dict:
|
|
87
88
|
"""Fetch a message from the Interactions API"""
|
|
88
89
|
message_url = f"{self.base_url}/interaction/v1/search/channel"
|
|
89
90
|
request_body = self._channel_lookup_request(
|
|
90
|
-
channel_id=channel_id,
|
|
91
|
+
channel_id=channel_id,
|
|
92
|
+
min_timestamp=min_timestamp,
|
|
93
|
+
thread_event_types=thread_event_types,
|
|
91
94
|
)
|
|
92
95
|
response = requests.post(
|
|
93
96
|
message_url,
|
|
@@ -98,42 +101,6 @@ class InteractionsService:
|
|
|
98
101
|
response.raise_for_status()
|
|
99
102
|
return response.json()
|
|
100
103
|
|
|
101
|
-
def fetch_messages_and_agent_context_events_for_thread(
|
|
102
|
-
self, message_id: str, event_type: str
|
|
103
|
-
) -> List[ReturnedMessage]:
|
|
104
|
-
"""Build a history of messages for a given message including associated events.
|
|
105
|
-
This includes messages from pre-forked threads."""
|
|
106
|
-
messages_with_events: List[ReturnedMessage] = []
|
|
107
|
-
|
|
108
|
-
messages_for_thread: ThreadRelationsResponse = (
|
|
109
|
-
self.fetch_thread_messages_and_events_for_message(
|
|
110
|
-
message_id, [event_type, EventType.THREAD_FORK.value]
|
|
111
|
-
)
|
|
112
|
-
)
|
|
113
|
-
messages_with_events.extend(messages_for_thread.messages)
|
|
114
|
-
|
|
115
|
-
# Process any thread_fork events
|
|
116
|
-
try:
|
|
117
|
-
for msg in messages_for_thread.messages:
|
|
118
|
-
for event in msg.events:
|
|
119
|
-
if event.type == EventType.THREAD_FORK.value:
|
|
120
|
-
event_data = ThreadForkEventData.model_validate(event.data)
|
|
121
|
-
forked_thread: ThreadRelationsResponse = (
|
|
122
|
-
self.fetch_thread_messages_and_events_for_message(
|
|
123
|
-
event_data.previous_message_id, [event_type]
|
|
124
|
-
)
|
|
125
|
-
)
|
|
126
|
-
messages_with_events.extend(forked_thread.messages)
|
|
127
|
-
except Exception as e: # pylint: disable=broad-except
|
|
128
|
-
logging.exception(
|
|
129
|
-
"Failed to fetch forked thread messages for message %s: %s",
|
|
130
|
-
message_id,
|
|
131
|
-
e,
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
messages_with_events.sort(key=lambda x: x.ts)
|
|
135
|
-
return messages_with_events
|
|
136
|
-
|
|
137
104
|
def fetch_thread_messages_and_events_for_message(
|
|
138
105
|
self, message_id: str, event_types: list[str]
|
|
139
106
|
) -> ThreadRelationsResponse:
|
|
@@ -182,41 +149,6 @@ class InteractionsService:
|
|
|
182
149
|
response.raise_for_status()
|
|
183
150
|
return response.json()
|
|
184
151
|
|
|
185
|
-
def fetch_messages_and_events_for_forked_thread(
|
|
186
|
-
self, message_id: str, event_type: str
|
|
187
|
-
) -> List[ReturnedMessage]:
|
|
188
|
-
"""Build a history of messages for a given message including associated events.
|
|
189
|
-
This includes messages from pre-forked threads."""
|
|
190
|
-
returned_messages: List[ReturnedMessage] = []
|
|
191
|
-
|
|
192
|
-
messages_for_thread: ThreadRelationsResponse = (
|
|
193
|
-
self.fetch_thread_messages_and_events_for_message(message_id, [event_type])
|
|
194
|
-
)
|
|
195
|
-
if messages_for_thread.messages:
|
|
196
|
-
returned_messages.extend(messages_for_thread.messages)
|
|
197
|
-
|
|
198
|
-
# Lookup any thread_fork events (conversation across surfaces)
|
|
199
|
-
thread_fork_events = self.fetch_messages_and_events_for_thread(
|
|
200
|
-
messages_for_thread.thread_id, EventType.THREAD_FORK.value
|
|
201
|
-
)
|
|
202
|
-
for forked_thread_event in thread_fork_events.get("thread", {}).get(
|
|
203
|
-
"events", []
|
|
204
|
-
):
|
|
205
|
-
event_data = ThreadForkEventData.model_validate(
|
|
206
|
-
forked_thread_event.get("data", {})
|
|
207
|
-
)
|
|
208
|
-
forked_thread: ThreadRelationsResponse = (
|
|
209
|
-
self.fetch_thread_messages_and_events_for_message(
|
|
210
|
-
event_data.previous_message_id, [event_type]
|
|
211
|
-
)
|
|
212
|
-
)
|
|
213
|
-
if forked_thread.messages:
|
|
214
|
-
returned_messages.extend(forked_thread.messages)
|
|
215
|
-
|
|
216
|
-
returned_messages.sort(key=lambda x: x.ts)
|
|
217
|
-
|
|
218
|
-
return returned_messages
|
|
219
|
-
|
|
220
152
|
def fetch_events_for_message(
|
|
221
153
|
self,
|
|
222
154
|
message_id: str,
|
|
@@ -241,7 +173,9 @@ class InteractionsService:
|
|
|
241
173
|
return response.json()
|
|
242
174
|
|
|
243
175
|
@staticmethod
|
|
244
|
-
def _channel_lookup_request(
|
|
176
|
+
def _channel_lookup_request(
|
|
177
|
+
channel_id: str, min_timestamp: str, thread_event_types: Optional[list[str]]
|
|
178
|
+
) -> dict:
|
|
245
179
|
"""Interaction service API request to get threads and messages for a channel"""
|
|
246
180
|
return {
|
|
247
181
|
"id": channel_id,
|
|
@@ -251,7 +185,8 @@ class InteractionsService:
|
|
|
251
185
|
"messages": {
|
|
252
186
|
"filter": {"min_timestamp": min_timestamp},
|
|
253
187
|
"apply_annotations_from_actors": ["*"],
|
|
254
|
-
}
|
|
188
|
+
},
|
|
189
|
+
"events": {"filter": {"type": thread_event_types or []}},
|
|
255
190
|
}
|
|
256
191
|
}
|
|
257
192
|
},
|
|
@@ -55,15 +55,6 @@ class Message(BaseModel):
|
|
|
55
55
|
return ts.isoformat()
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
class EventType(str, Enum):
|
|
59
|
-
"""Event types for the interactions service"""
|
|
60
|
-
|
|
61
|
-
AGENT_CONTEXT = "agent:message_context"
|
|
62
|
-
S2_ANNOTATION = "s2_annotation"
|
|
63
|
-
THREAD_FORK = "thread_fork"
|
|
64
|
-
UI_INTERACTION = "ui_interaction"
|
|
65
|
-
|
|
66
|
-
|
|
67
58
|
class Event(BaseModel):
|
|
68
59
|
"""event object to be sent to the interactions service; requires association with a message, thread or channel id"""
|
|
69
60
|
|
|
@@ -141,12 +132,6 @@ class ReturnedAgentContextMessage(BaseModel):
|
|
|
141
132
|
events: List[ReturnedAgentContextEvent] = Field(default_factory=list)
|
|
142
133
|
|
|
143
134
|
|
|
144
|
-
class ThreadForkEventData(BaseModel):
|
|
145
|
-
"""Event data for a thread fork event"""
|
|
146
|
-
|
|
147
|
-
previous_message_id: str
|
|
148
|
-
|
|
149
|
-
|
|
150
135
|
class ThreadRelationsResponse(BaseModel):
|
|
151
136
|
"""Thread format returned by interaction service for thread relations in a search response"""
|
|
152
137
|
|
|
@@ -7,7 +7,7 @@ dev_requirements = ["mypy", "pytest", "black", "types-requests"]
|
|
|
7
7
|
|
|
8
8
|
setuptools.setup(
|
|
9
9
|
name="nora_lib",
|
|
10
|
-
version="0.
|
|
10
|
+
version="0.1.7",
|
|
11
11
|
description="For making and coordinating agents and tools",
|
|
12
12
|
url="https://github.com/allenai/nora_lib",
|
|
13
13
|
packages=setuptools.find_packages(exclude=(["tests"])),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|