Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request_id to response #21

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
summary = GenerateText(prompt=sb.concat("Summarize this story: ", story.future.text))

response = substrate.run(story, summary)
print(response.api_response.json)
print(response.api_response.status_code)
print(response)

# summary_out = response.get(summary)
# print(summary_out.text)
summary_out = response.get(summary)
print(summary_out.text)

# viz = Substrate.visualize(ry)
# print(viz)
12 changes: 12 additions & 0 deletions substrate/substrate_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class SubstrateResponse:
def __init__(self, api_response: APIResponse):
self._api_response = api_response

def __str__(self):
return f"SubstrateResponse(request_id={self.request_id}, api_response={self._api_response.status_code})"

@property
def request_id(self) -> Optional[str]:
"""
The request id.
"""
if self.json:
return self.json.get("substrate_request_id")
return None

def get(self, node: CoreNode[OT]) -> OT:
"""
Get the output of a specific node.
Expand Down
Loading