Skip to content

Commit b09aed9

Browse files
authored
Add timeout to apex (#7)
* Squashed 'protos/' changes from dd4bc46..a643df8 a643df8 Merge pull request #8 from macrocosm-os/gen-1139_add_auth_timing 1797152 GEN-1139 Improve auth and usage tracking 35cff72 Merge pull request #7 from macrocosm-os/gen-964-sub-reddits-secrets cf2273b Finalize ListTopics endpoint Rename protobuf definitions Rm gravity_api.go 5ed889b Finalize ListTopics endpoint Rename protobuf definitions Rm gravity_api.go 090da56 Introduce SN13 service b68b65f Add endpoint for validating sources (i.e. getting top labels by source) 7fbb132 Merge pull request #6 from macrocosm-os/codeowners e0ceca8 codeowners git-subtree-dir: protos git-subtree-split: a643df86c68b9376d7415953d2ca3aca440133de * Add timeout to Apex client
1 parent 9330409 commit b09aed9

21 files changed

+354
-105
lines changed

examples/apex_chat_client_async.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import time
88
from typing import List
99

10-
import grpc
11-
1210
import macrocosmos as mc
1311

1412

@@ -90,7 +88,7 @@ async def process_chat_completion(
9088

9189
return duration
9290

93-
except grpc.RpcError as e:
91+
except Exception as e:
9492
duration = time.time() - start_time
9593
print(
9694
f"RPC error in request {index} (after {duration:.2f}s): {e.code()}: {e.details()}"

examples/apex_chat_client_stream.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import asyncio
66
import os
77

8-
import grpc
9-
108
import macrocosmos as mc
119

1210

@@ -52,7 +50,7 @@ async def demo_chat_completion_stream():
5250
full_content += content
5351
print(content, end="", flush=True)
5452

55-
except grpc.RpcError as e:
53+
except Exception as e:
5654
print(f"RPC error: {e.code()}: {e.details()}")
5755

5856

examples/apex_chat_client_sync.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import time
77
from typing import List
88

9-
import grpc
10-
119
import macrocosmos as mc
1210

1311

@@ -87,7 +85,7 @@ def process_chat_completion(
8785

8886
return duration
8987

90-
except grpc.RpcError as e:
88+
except Exception as e:
9189
duration = time.time() - start_time
9290
print(
9391
f"RPC error in request {index} (after {duration:.2f}s): {e.code()}: {e.details()}"

examples/apex_chat_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import grpc
1212

1313
from macrocosmos import __package_name__, __version__
14-
from macrocosmos.client import DEFAULT_BASE_URL
14+
from macrocosmos.resources._client import DEFAULT_BASE_URL
1515
from macrocosmos.generated.apex.v1 import apex_pb2, apex_pb2_grpc
1616

1717

protos/.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* @cassova @metafeather
2+
/.github/CODEOWNERS @cassova @metafeather

protos/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@
22
Protobufs used by Macrocosmos products
33

44
# Usage
5-
Here is an example of how to add the Macrocosmos protobufs to a project:
5+
Here are instructions on how to add and update the protos from your own project repo.
6+
7+
> ⚠️ These commands must be run from the target repo's root directory
8+
9+
How to add the Macrocosmos protobufs to a project repo:
610

711
```bash
812
git subtree add --prefix=protos git@github.com:macrocosm-os/macrocosmos-protos.git main --squash
913
```
1014

11-
They can subsequently be updated with:
15+
You can pull the latest updates to `main` from this repo to your project repo with:
1216

1317
```bash
1418
git subtree pull --prefix=protos git@github.com:macrocosm-os/macrocosmos-protos.git main --squash
1519
```
20+
21+
To push changes back to this repo for other projects, run this to create a branch:
22+
23+
```bash
24+
git subtree push --prefix=protos git@github.com:macrocosm-os/macrocosmos-protos.git <your-branch-name>
25+
```
26+
27+
You'll then need to create a pull request for that branch to merge to `main`.

protos/apex/v1/apex.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ message ChatCompletionRequest {
4040
bool json_format = 10;
4141
// stream: whether to stream the completion.
4242
bool stream = 11;
43+
// timeout: the timeout for the completion in seconds.
44+
int64 timeout = 12;
4345
}
4446

4547
// The sampling parameters for the completion.
@@ -333,6 +335,8 @@ message WebRetrievalRequest {
333335
int64 n_results = 4;
334336
// max_response_time: the max response time to allow for the miners to respond in seconds.
335337
int64 max_response_time = 5;
338+
// timeout: the timeout for the web retrieval in seconds.
339+
int64 timeout = 6;
336340
}
337341

338342
// A web search result from Apex
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
syntax = "proto3";
2+
3+
package sn13.v1;
4+
5+
6+
option go_package = "macrocosm-os/rift/constellation_api/gen/sn13/v1";
7+
8+
9+
service Sn13Service {
10+
// ListTopics is the RPC method for getting the top topics
11+
rpc ListTopics(ListTopicsRequest) returns (ListTopicsResponse);
12+
}
13+
14+
// ListTopicsRequest is the request message for getting the top topics
15+
message ListTopicsRequest {
16+
// source: the source to validate
17+
string source = 1;
18+
}
19+
20+
// ListTopicsResponseDetail is the response message for getting the top topics
21+
message ListTopicsResponseDetail {
22+
// label_value: reddit or x topic
23+
string label_value = 1;
24+
// content_size_bytes: content size in bytes
25+
uint64 content_size_bytes = 2;
26+
// adj_content_size_bytes: adjacent content size in bytes
27+
uint64 adj_content_size_bytes = 3;
28+
}
29+
30+
// ListTopicsResponse is a list of ListTopicsResponseDetail(s) with top topics
31+
message ListTopicsResponse {
32+
// message: the response message
33+
repeated ListTopicsResponseDetail details = 1;
34+
}

src/macrocosmos/generated/apex/v1/apex_p2p.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# gen by protobuf_to_pydantic[v0.3.1.1](https://github.com/so1n/protobuf_to_pydantic)
33
# Protobuf Version: 5.29.4
44
# Pydantic Version: 2.11.0
5-
import typing
6-
75
from google.protobuf.message import Message # type: ignore
8-
from pydantic import BaseModel, Field
6+
from pydantic import BaseModel
7+
from pydantic import Field
8+
import typing
99

1010

1111
class ChatMessage(BaseModel):
@@ -64,6 +64,8 @@ class ChatCompletionRequest(BaseModel):
6464
json_format: bool = Field(default=False)
6565
# stream: whether to stream the completion.
6666
stream: bool = Field(default=False)
67+
# timeout: the timeout for the completion in seconds.
68+
timeout: int = Field(default=0)
6769

6870
class TopLogprob(BaseModel):
6971
"""
@@ -375,6 +377,8 @@ class WebRetrievalRequest(BaseModel):
375377
n_results: int = Field(default=0)
376378
# max_response_time: the max response time to allow for the miners to respond in seconds.
377379
max_response_time: int = Field(default=0)
380+
# timeout: the timeout for the web retrieval in seconds.
381+
timeout: int = Field(default=0)
378382

379383
class WebSearchResult(BaseModel):
380384
"""

0 commit comments

Comments
 (0)