[Profiler] Add per-session profiling controls to Python and Rust frontends (#57875)
Signed-off-by: czhu <conway.zhu@cohere.com> Signed-off-by: Conway Zhu <conway.zhu@cohere.com> Co-authored-by: aoshen02 <aoshen@inferact.ai>
This commit is contained in:
@@ -122,8 +122,6 @@ def _validate_api_url(
|
||||
if isinstance(expected_suffixes, str):
|
||||
expected_suffixes = {expected_suffixes}
|
||||
|
||||
expected_suffixes = {*expected_suffixes, "profile"}
|
||||
|
||||
if not api_url.endswith(tuple(expected_suffixes)):
|
||||
raise ValueError(f"{api_name} URL must end with one of: {expected_suffixes}.")
|
||||
|
||||
@@ -158,6 +156,34 @@ def _get_headers(content_type: str | None = None) -> dict[str, str]:
|
||||
return headers
|
||||
|
||||
|
||||
async def async_request_profile(
|
||||
api_url: str,
|
||||
session: aiohttp.ClientSession,
|
||||
extra_headers: dict | None = None,
|
||||
) -> RequestFuncOutput:
|
||||
_validate_api_url(
|
||||
api_url,
|
||||
"Profiling API",
|
||||
{"start_profile", "stop_profile"},
|
||||
)
|
||||
|
||||
headers = _get_headers()
|
||||
if extra_headers:
|
||||
headers |= extra_headers
|
||||
|
||||
output = RequestFuncOutput()
|
||||
try:
|
||||
async with session.post(url=api_url, headers=headers) as response:
|
||||
output.success = response.status == 200
|
||||
if not output.success:
|
||||
output.error = response.reason or ""
|
||||
except Exception:
|
||||
exc_info = sys.exc_info()
|
||||
output.error = "".join(traceback.format_exception(*exc_info))
|
||||
|
||||
return output
|
||||
|
||||
|
||||
async def async_request_openai_completions(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
|
||||
Reference in New Issue
Block a user