Skip to content

Commit

Permalink
adding on client
Browse files Browse the repository at this point in the history
  • Loading branch information
XaviPeiro committed Sep 24, 2024
1 parent 229a0c0 commit ce21d64
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ai_engine_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ async def make_api_request(
api_key: str,
method: str,
endpoint: str,
payload: Optional[dict] = None
payload: Optional[dict] = None,
params: Optional[dict] = None
) -> dict:
params = {} if params is None else params
body = json.dumps(payload) if payload else None

headers = {
Expand All @@ -95,7 +97,13 @@ async def make_api_request(
logger.debug(f"\n\n 📤 Request triggered : {method} {api_base_url}{endpoint}")
logger.debug(f"{body=}")
logger.debug("---------------------------\n\n")
async with session.request(method, f"{api_base_url}{endpoint}", headers=headers, data=body) as response:
async with session.request(
method,
f"{api_base_url}{endpoint}",
headers=headers,
data=body,
params=params
) as response:
if not bool(re.search(pattern="^2..$", string=str(response.status))):
raise Exception(f"Request failed with status {response.status} to {method}: {endpoint}")
return await response.json()
Expand Down Expand Up @@ -482,12 +490,14 @@ async def get_functions_by_function_group(self, function_group_id: str) -> list[
return result


async def get_functions(self) -> list[Function]:
async def get_functions(self, params: Optional[dict] = None) -> list[Function]:
params = {} if params is None else params
raw_response: dict = await make_api_request(
api_base_url=self._api_base_url,
api_key=self._api_key,
method='GET',
endpoint=f"/v1beta1/functions/"
endpoint=f"/v1beta1/functions/",
params=params
)
return list(
map(
Expand Down

0 comments on commit ce21d64

Please sign in to comment.