Skip to content

Commit

Permalink
Add project name to client.log_evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
anticorrelator committed Mar 14, 2024
1 parent dc57160 commit 151b3f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/phoenix/server/api/routers/evaluation_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EvaluationHandler(HTTPEndpoint):

async def post(self, request: Request) -> Response:
content_type = request.headers.get("content-type")
project_name = request.headers.get("project-name", DEFAULT_PROJECT_NAME)
if content_type == "application/x-pandas-arrow":
return await self._process_pyarrow(request)
if content_type != "application/x-protobuf":
Expand All @@ -51,7 +52,7 @@ async def post(self, request: Request) -> Response:
content="Request body is invalid",
status_code=HTTP_422_UNPROCESSABLE_ENTITY,
)
self.traces.put(evaluation)
self.traces.put(evaluation, project_name=project_name)
return Response()

async def get(self, request: Request) -> Response:
Expand Down
7 changes: 5 additions & 2 deletions src/phoenix/session/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,19 @@ def _warn_if_phoenix_is_not_running(self) -> None:
f"with `import phoenix as px; px.launch_app()`"
)

def log_evaluations(self, *evals: Evaluations) -> None:
def log_evaluations(self, *evals: Evaluations, project_name: Optional[str] = None) -> None:
for evaluation in evals:
table = evaluation.to_pyarrow_table()
sink = pa.BufferOutputStream()
headers = {"content-type": "application/x-pandas-arrow"}
if project_name:
headers["project-name"] = project_name
with pa.ipc.new_stream(sink, table.schema) as writer:
writer.write_table(table)
self._session.post(
urljoin(self._base_url, "/v1/evaluations"),
data=cast(bytes, sink.getvalue().to_pybytes()),
headers={"content-type": "application/x-pandas-arrow"},
headers=headers,
).raise_for_status()


Expand Down

0 comments on commit 151b3f2

Please sign in to comment.