Avoid copying runs (#26689)

Also, re-unify run trees. Use a single shared client.
This commit is contained in:
William FH
2024-09-20 10:57:41 -07:00
committed by GitHub
parent 90031b1b3e
commit 19ce95d3c9
14 changed files with 433 additions and 417 deletions

View File

@@ -24,6 +24,18 @@ class FinancialDatasetsAPIWrapper(BaseModel):
data, "financial_datasets_api_key", "FINANCIAL_DATASETS_API_KEY"
)
@property
def _api_key(self) -> str:
if self.financial_datasets_api_key is None:
raise ValueError(
"API key is required for the FinancialDatasetsAPIWrapper. "
"Please provide the API key by either:\n"
"1. Manually specifying it when initializing the wrapper: "
"FinancialDatasetsAPIWrapper(financial_datasets_api_key='your_api_key')\n"
"2. Setting it as an environment variable: FINANCIAL_DATASETS_API_KEY"
)
return self.financial_datasets_api_key
def get_income_statements(
self,
ticker: str,
@@ -47,7 +59,7 @@ class FinancialDatasetsAPIWrapper(BaseModel):
)
# Add the api key to the headers
headers = {"X-API-KEY": self.financial_datasets_api_key}
headers = {"X-API-KEY": self._api_key}
# Execute the request
response = requests.get(url, headers=headers)
@@ -78,7 +90,7 @@ class FinancialDatasetsAPIWrapper(BaseModel):
)
# Add the api key to the headers
headers = {"X-API-KEY": self.financial_datasets_api_key}
headers = {"X-API-KEY": self._api_key}
# Execute the request
response = requests.get(url, headers=headers)
@@ -110,7 +122,7 @@ class FinancialDatasetsAPIWrapper(BaseModel):
)
# Add the api key to the headers
headers = {"X-API-KEY": self.financial_datasets_api_key}
headers = {"X-API-KEY": self._api_key}
# Execute the request
response = requests.get(url, headers=headers)