Skip to content

Commit 8201270

Browse files
authored
Merge pull request #23 from macrocosm-os/gen_2014_add_on_demand_data_keyword_mode
GEN-2014: Add keyword_mode parameter to OnDemandData requests
2 parents 86b60c6 + 2851c40 commit 8201270

File tree

12 files changed

+319
-58
lines changed

12 files changed

+319
-58
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ print(polled_response)
8585

8686
SN13 is focused on large-scale data collection. With the OnDemandAPI, you can run precise, real-time queries against platforms like X (Twitter) and Reddit (YouTube forthcoming).
8787

88-
As of data-universe release [v1.9.8](https://github.com/macrocosm-os/data-universe/releases/tag/v1.9.8):
89-
- All keywords in the OnDemandData request will be present in the returned post/comment data.
88+
As of the latest data-universe [release](https://github.com/macrocosm-os/data-universe/releases/):
89+
- Users may select two post-filtering modes via the `keyword_mode` parameter:
90+
- `"any"`: Returns posts that contain any combination of the listed keywords.
91+
- `"all"`: Returns posts that contain all of the keywords (default).
9092
- For Reddit requests, the first keyword in the list corresponds to the requested subreddit, and subsequent keywords are treated as normal.
9193
- For YouTube requests, only one username should be supplied - corresponding to the channel name - while keywords are ignored (empty list).
9294

@@ -105,7 +107,8 @@ response = client.sn13.OnDemandData(
105107
keywords=["galaxy"], # Optional, up to 5 keywords
106108
start_date='2025-04-15', # Defaults to 24h range if not specified
107109
end_date='2025-05-15', # Defaults to current time if not specified
108-
limit=1000 # Optional, up to 1000 results
110+
limit=1000, # Optional, up to 1000 results
111+
keyword_mode='any' # Optional, "any" or "all"
109112
)
110113

111114
print(response)

examples/sn13_on_demand_data.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""
22
Example of using the SN13 On Demand Data Streaming service with Macrocosmos SDK.
33
4-
As of data-universe release v1.9.8:
5-
- All keywords in the OnDemandData request will be present in the returned post/comment data.
4+
As of the latest data-universe release:
5+
- Users may select two post-filtering modes via the keyword_mode parameter:
6+
- "any": Returns posts that contain any combination of the listed keywords.
7+
- "all": Returns posts that contain all of the keywords (default, if field omitted).
68
- For Reddit requests, the first keyword in the list corresponds to the requested subreddit, and subsequent keywords are treated as normal.
79
- For YouTube requests, only one username should be supplied - corresponding to the channel name - while keywords are ignored (empty list).
810
"""
@@ -21,7 +23,8 @@
2123
keywords=["photo", "space", "mars"],
2224
start_date="2024-04-01",
2325
end_date="2025-04-25",
24-
limit=3,
26+
limit=5,
27+
keyword_mode="any",
2528
)
2629

2730
print(response)

examples/sn13_on_demand_data_async.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
Example demonstrating concurrent async operations with the SN13 On Demand Data service.
33
Shows how multiple requests can be processed simultaneously in an async context.
44
5-
As of data-universe release v1.9.8:
6-
- All keywords in the OnDemandData request will be present in the returned post/comment data.
5+
As of the latest data-universe release:
6+
- Users may select two post-filtering modes via the keyword_mode parameter:
7+
- "any": Returns posts that contain any combination of the listed keywords.
8+
- "all": Returns posts that contain all of the keywords (default, if field omitted).
79
- For Reddit requests, the first keyword in the list corresponds to the requested subreddit, and subsequent keywords are treated as normal.
810
- For YouTube requests, only one username should be supplied - corresponding to the channel name - while keywords are ignored (empty list).
911
"""
1012

1113
import os
1214
import asyncio
1315
import time
16+
from typing import Optional
1417

1518
import macrocosmos as mc
1619

@@ -24,6 +27,7 @@ async def fetch_data(
2427
end_date: str,
2528
limit: int,
2629
request_id: int,
30+
keyword_mode: Optional[str] = None,
2731
):
2832
"""Fetch data for a single request and track its timing."""
2933
start_time = time.time()
@@ -36,6 +40,7 @@ async def fetch_data(
3640
start_date=start_date,
3741
end_date=end_date,
3842
limit=limit,
43+
keyword_mode=keyword_mode,
3944
)
4045

4146
end_time = time.time()
@@ -60,27 +65,34 @@ async def main():
6065
"keywords": [
6166
"photo",
6267
"space",
63-
], # Posts including both keywords will be returned
68+
], # Posts including either keyword will be returned
6469
"start_date": "2024-04-01",
6570
"end_date": "2024-04-30",
6671
"limit": 5,
6772
"request_id": 1,
73+
"keyword_mode": "any",
6874
},
6975
{
7076
"source": "reddit",
71-
"usernames": ["TheMuseumOfScience"],
72-
"keywords": ["r/nasa", "vision"], # First keyword is the subreddit
73-
"start_date": "2025-04-01",
74-
"end_date": "2025-08-25",
75-
"limit": 1,
77+
"usernames": [],
78+
"keywords": [
79+
"r/CasualUK",
80+
"moon",
81+
"tonight",
82+
"nice",
83+
], # First keyword is the subreddit, next keywords should all appear in returned posts
84+
"start_date": "2025-09-01",
85+
"end_date": "2025-09-08",
86+
"limit": 5,
7687
"request_id": 2,
88+
"keyword_mode": "all",
7789
},
7890
{
7991
"source": "youtube",
8092
"usernames": ["veritasium"],
8193
"keywords": [], # YouTube does not currently support keywords, list left empty
82-
"start_date": "2025-08-01",
83-
"end_date": "2025-08-06",
94+
"start_date": "2025-07-01",
95+
"end_date": "2025-09-06",
8496
"limit": 1,
8597
"request_id": 3,
8698
},

protos/apex/v1/apex.proto

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ service ApexService {
2525
rpc GetDeepResearcherJob(GetDeepResearcherJobRequest) returns (GetDeepResearcherJobResponse);
2626

2727
// GetChatSessions retrieves a user's chats
28-
rpc GetChatSessions(google.protobuf.Empty) returns (GetChatSessionsResponse);
28+
rpc GetChatSessions(GetChatSessionsRequest) returns (GetChatSessionsResponse);
2929

3030
// GetStoredChatCompletions retrieves a chat's completions
3131
rpc GetStoredChatCompletions(GetStoredChatCompletionsRequest) returns (GetStoredChatCompletionsResponse);
3232

33+
// GetChatCompletion retrieves a completion by its ID
34+
rpc GetChatCompletion(GetChatCompletionRequest) returns (StoredChatCompletion);
35+
3336
// UpdateChatAttributes updates specified attributes of a chat
3437
rpc UpdateChatAttributes(UpdateChatAttributesRequest) returns (UpdateChatAttributesResponse);
3538

@@ -461,12 +464,24 @@ message GetChatSessionsResponse {
461464
repeated ChatSession chat_sessions = 1;
462465
}
463466

467+
// A GetChatSessionsRequest message
468+
message GetChatSessionsRequest {
469+
// chat_type: type of chat (e.g. "apex" or "gravity")
470+
string chat_type = 1;
471+
}
472+
464473
// A GetStoredChatCompletionRequest request message
465474
message GetStoredChatCompletionsRequest {
466475
// chat_id: a unique identifier for a chat
467476
string chat_id = 1;
468477
}
469478

479+
// A GetChatCompletionRequest request message
480+
message GetChatCompletionRequest {
481+
// completion_id: a unique identifier for a completion
482+
string completion_id = 1;
483+
}
484+
470485

471486
// A StoredChatCompletion message repeated in GetStoredChatCompletionsResponse
472487
message StoredChatCompletion {
@@ -620,6 +635,8 @@ message UpdateCompletionAttributesRequest {
620635
optional string completion_text = 2;
621636
// metadata: metadata json blob (optional)
622637
google.protobuf.Struct metadata = 3;
638+
// user_prompt_text: the user's prompt text (optional)
639+
optional string user_prompt_text = 4;
623640
}
624641

625642
// An UpdateCompletionAttributes response

0 commit comments

Comments
 (0)