Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default UMAP parameters in launch_app() #1224

Merged
merged 30 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8ea71bd
Reaching till GraphQLWithContext
pbadhe Aug 28, 2023
689b6f5
typing.Dict not dict()
pbadhe Aug 28, 2023
5146c6e
Merge branch 'main' into umap_params
pbadhe Sep 9, 2023
2834175
Dict import
pbadhe Sep 9, 2023
c532d04
Merge branch 'main' into umap_params
pbadhe Sep 15, 2023
5e195e4
Suggested review changes
pbadhe Sep 15, 2023
dc9992b
Merge branch 'main' into umap_params
pbadhe Sep 26, 2023
b71de1a
CamelCase -> SnakeCase
pbadhe Sep 26, 2023
e1f9304
CamelCase -> SnakeCase all suggested changes
pbadhe Sep 26, 2023
a2f525d
Merge branch 'main' into umap_params
pbadhe Sep 27, 2023
91f5f47
Default UMAPparam changes
pbadhe Sep 27, 2023
d4673ba
Merge branch 'main' into umap_params
pbadhe Sep 29, 2023
eb16a0d
typing hints & process_session()
pbadhe Sep 29, 2023
6f2f8e6
Merge branch 'main' into umap_params
pbadhe Sep 29, 2023
0be3164
Prettier check
pbadhe Sep 29, 2023
bc4a8bc
Merge branch 'main' into umap_params
mikeldking Oct 4, 2023
08f3a57
Adjust frontend
mikeldking Oct 4, 2023
4975122
parse string correctly
mikeldking Oct 4, 2023
aa2fb82
fix duplicate lines
mikeldking Oct 4, 2023
6756ee4
Merge branch 'main' into umap_params
mikeldking Oct 4, 2023
7687b3b
Update umap_parameters.py
mikeldking Oct 5, 2023
7aa84a6
Update umap_parameters.py
mikeldking Oct 5, 2023
83f6ea5
Update umap_parameters.py
mikeldking Oct 5, 2023
800f85b
Update src/phoenix/session/session.py
mikeldking Oct 5, 2023
7ff011f
Update src/phoenix/session/session.py
mikeldking Oct 5, 2023
194a1ea
Update src/phoenix/session/session.py
mikeldking Oct 5, 2023
4a30132
use positional arguments
mikeldking Oct 5, 2023
fbf87e4
fix style and imports
mikeldking Oct 5, 2023
5b05baa
Merge branch 'main' into umap_params
mikeldking Oct 5, 2023
4c411be
Merge branch 'main' into umap_params
mikeldking Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/phoenix/core/umap_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from dataclasses import dataclass
from typing import Union, Dict


@dataclass
class UMAPParameters:
default_umap_params: Dict[str, Union[int, float]]
pbadhe marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions src/phoenix/server/api/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from phoenix.core.model_schema import Model
from phoenix.core.traces import Traces
from phoenix.core.umap_parameters import UMAPParameters


@dataclass
Expand All @@ -18,3 +19,4 @@ class Context:
export_path: Path
corpus: Optional[Model] = None
traces: Optional[Traces] = None
config: Optional[UMAPParameters] = None
pbadhe marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions src/phoenix/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
from phoenix.config import SERVER_DIR
from phoenix.core.model_schema import Model
from phoenix.core.traces import Traces
from phoenix.core.umap_parameters import UMAPParameters
from phoenix.server.api.context import Context
from phoenix.server.api.schema import schema
from phoenix.server.span_handler import SpanHandler


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -67,10 +69,12 @@ def __init__(
graphiql: bool = False,
corpus: Optional[Model] = None,
traces: Optional[Traces] = None,
config: Optional[UMAPParameters] = None,
) -> None:
self.model = model
self.corpus = corpus
self.traces = traces
self.config = config
self.export_path = export_path
super().__init__(schema, graphiql=graphiql)

Expand All @@ -85,6 +89,7 @@ async def get_context(
model=self.model,
corpus=self.corpus,
traces=self.traces,
config=self.config,
export_path=self.export_path,
)

Expand All @@ -109,13 +114,15 @@ def create_app(
model: Model,
corpus: Optional[Model] = None,
traces: Optional[Traces] = None,
config: Optional[UMAPParameters] = None,
debug: bool = False,
) -> Starlette:
graphql = GraphQLWithContext(
schema=schema,
model=model,
corpus=corpus,
traces=traces,
config=config,
export_path=export_path,
graphiql=True,
)
Expand Down
26 changes: 23 additions & 3 deletions src/phoenix/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from datetime import datetime
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Iterable, List, Optional, Set
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Set, Union

import pandas as pd
from portpicker import pick_unused_port

from phoenix.config import HOST, PORT, get_exported_files
from phoenix.core.model_schema_adapter import create_model_from_datasets
from phoenix.core.traces import Traces
from phoenix.core.umap_parameters import UMAPParameters
from phoenix.datasets.dataset import EMPTY_DATASET, Dataset
from phoenix.server.app import create_app
from phoenix.server.thread_server import ThreadServer
Expand Down Expand Up @@ -70,13 +71,19 @@ def __init__(
reference_dataset: Optional[Dataset] = None,
corpus_dataset: Optional[Dataset] = None,
trace_dataset: Optional[TraceDataset] = None,
default_umap_parameters: Optional[Dict[str, int]] = None,
host: str = HOST,
port: int = PORT,
):
self.primary_dataset = primary_dataset
self.reference_dataset = reference_dataset
self.corpus_dataset = corpus_dataset
self.trace_dataset = trace_dataset
self.config = (
UMAPParameters(default_umap_parameters)
if default_umap_parameters is not None
else None,
pbadhe marked this conversation as resolved.
Show resolved Hide resolved
)
self.model = create_model_from_datasets(
primary_dataset,
reference_dataset,
Expand Down Expand Up @@ -175,6 +182,7 @@ def __init__(
reference_dataset: Optional[Dataset] = None,
corpus_dataset: Optional[Dataset] = None,
trace_dataset: Optional[TraceDataset] = None,
default_umap_parameters: Optional[Dict[str, int]] = None,
host: str = HOST,
port: int = PORT,
) -> None:
Expand All @@ -183,6 +191,7 @@ def __init__(
reference_dataset=reference_dataset,
corpus_dataset=corpus_dataset,
trace_dataset=trace_dataset,
default_umap_parameters=default_umap_parameters,
host=host,
port=port or PORT,
)
Expand All @@ -203,6 +212,7 @@ def __init__(
corpus_dataset_name=(
self.corpus_dataset.name if self.corpus_dataset is not None else None
),
# TO-DO default_umap_params for ProcessSession
trace_dataset_name=(
self.trace_dataset.name if self.trace_dataset is not None else None
),
Expand All @@ -224,6 +234,7 @@ def __init__(
reference_dataset: Optional[Dataset] = None,
corpus_dataset: Optional[Dataset] = None,
trace_dataset: Optional[TraceDataset] = None,
default_umap_parameters: Optional[Dict[str, int]] = None,
host: str = HOST,
port: int = PORT,
):
Expand All @@ -232,6 +243,7 @@ def __init__(
reference_dataset=reference_dataset,
corpus_dataset=corpus_dataset,
trace_dataset=trace_dataset,
default_umap_parameters=default_umap_parameters,
host=host,
port=port or pick_unused_port(),
)
Expand All @@ -241,6 +253,7 @@ def __init__(
model=self.model,
corpus=self.corpus,
traces=self.traces,
config=self.config,
)
self.server = ThreadServer(
app=self.app,
Expand All @@ -264,6 +277,7 @@ def launch_app(
reference: Optional[Dataset] = None,
corpus: Optional[Dataset] = None,
trace: Optional[TraceDataset] = None,
default_umap_parameters: Optional[Dict[str, Union[int, float]]] = None,
mikeldking marked this conversation as resolved.
Show resolved Hide resolved
host: str = HOST,
port: int = PORT,
run_in_thread: bool = True,
Expand All @@ -288,6 +302,8 @@ def launch_app(
The port on which the server listens.
run_in_thread: bool, optional, default=True
Whether the server should run in a Thread or Process.
default_umap_parameters: Dict[str, Union[int, float]], optional, default=None
User specified default UMAP parameters eg: {nNeighbors: 10, nSamples: 5, minDist: 0.5}
pbadhe marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
Expand Down Expand Up @@ -316,7 +332,9 @@ def launch_app(
"it down and starting a new instance..."
)
_session.end()
_session = ThreadSession(primary, reference, corpus, trace, host=host, port=port)
_session = ThreadSession(
primary, reference, corpus, trace, default_umap_parameters, host=host, port=port
)
# TODO: catch exceptions from thread
if not _session.active:
logger.error(
Expand All @@ -325,7 +343,9 @@ def launch_app(
)
return None
else:
_session = ProcessSession(primary, reference, corpus, trace, host=host, port=port)
_session = ProcessSession(
primary, reference, corpus, trace, default_umap_parameters, host=host, port=port
)

print(f"🌍 To view the Phoenix app in your browser, visit {_session.url}")
print("📺 To view the Phoenix app in a notebook, run `px.active_session().view()`")
Expand Down
Loading