Skip to content

Commit

Permalink
feat(client): add timeout parameters to log_evaluations, get_evaluati…
Browse files Browse the repository at this point in the history
…ons (#5646)

* feat(client): add timeouts

* more timeout code

* kwargs only
  • Loading branch information
mikeldking authored Dec 9, 2024
1 parent 5f51386 commit c388a9b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/phoenix/session/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def query_spans(
root_spans_only (bool, optional): If True, only root spans are returned. Default None.
project_name (str, optional): The project name to query spans for. This can be set
using environment variables. If not provided, falls back to the default project.
timeout (int, optional): The number of seconds to wait for the server to respond.
Returns:
Union[pd.DataFrame, list[pd.DataFrame]]:
Expand Down Expand Up @@ -216,6 +217,8 @@ def query_spans(
def get_evaluations(
self,
project_name: Optional[str] = None,
*, # Only support kwargs from now on
timeout: Optional[int] = DEFAULT_TIMEOUT_IN_SECONDS,
) -> list[Evaluations]:
"""
Retrieves evaluations for a given project from the Phoenix server or active session.
Expand All @@ -224,6 +227,7 @@ def get_evaluations(
project_name (str, optional): The name of the project to retrieve evaluations for.
This can be set using environment variables. If not provided, falls back to the
default project.
timeout (int, optional): The number of seconds to wait for the server to respond.
Returns:
list[Evaluations]:
Expand All @@ -237,6 +241,7 @@ def get_evaluations(
"project_name": project_name,
"project-name": project_name, # for backward-compatibility
},
timeout=timeout,
)
if response.status_code == 404:
logger.info("No evaluations found.")
Expand All @@ -263,15 +268,18 @@ def _warn_if_phoenix_is_not_running(self) -> None:
f"with `import phoenix as px; px.launch_app()`"
)

def log_evaluations(self, *evals: Evaluations, **kwargs: Any) -> None:
def log_evaluations(
self,
*evals: Evaluations,
timeout: Optional[int] = DEFAULT_TIMEOUT_IN_SECONDS,
**kwargs: Any,
) -> None:
"""
Logs evaluation data to the Phoenix server.
Args:
evals (Evaluations): One or more Evaluations objects containing the data to log.
project_name (str, optional): The project name under which to log the evaluations.
This can be set using environment variables. If not provided, falls back to the
default project.
timeout (int, optional): The number of seconds to wait for the server to respond.
Returns:
None
Expand All @@ -290,6 +298,7 @@ def log_evaluations(self, *evals: Evaluations, **kwargs: Any) -> None:
url=urljoin(self._base_url, "v1/evaluations"),
content=cast(bytes, sink.getvalue().to_pybytes()),
headers=headers,
timeout=timeout,
).raise_for_status()

def log_traces(self, trace_dataset: TraceDataset, project_name: Optional[str] = None) -> None:
Expand Down

0 comments on commit c388a9b

Please sign in to comment.