From 029ee292c985db263aae3969670bad30cb65cf1b Mon Sep 17 00:00:00 2001 From: benzguo Date: Wed, 12 Jun 2024 03:04:47 -0400 Subject: [PATCH] add req id --- examples/basic.py | 7 +++---- substrate/substrate_response.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/basic.py b/examples/basic.py index 1204e5b..96b4f75 100755 --- a/examples/basic.py +++ b/examples/basic.py @@ -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) diff --git a/substrate/substrate_response.py b/substrate/substrate_response.py index e53522e..ae7c9e2 100644 --- a/substrate/substrate_response.py +++ b/substrate/substrate_response.py @@ -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.