Skip to content

Commit

Permalink
Make not accumulating the requests the default behavior for the OpenA…
Browse files Browse the repository at this point in the history
…I monitor
  • Loading branch information
gustavocidornelas committed Nov 26, 2023
1 parent b5abae4 commit 67712b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
18 changes: 0 additions & 18 deletions examples/monitoring/quickstart/llms/openai_llm_monitor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,6 @@
"# )"
]
},
{
"cell_type": "markdown",
"id": "f7c3dfbc",
"metadata": {},
"source": [
"You can also access all the data accumulated (and in this case, published to Openlayer) with the `data` attribute:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "27bb2bdc",
"metadata": {},
"outputs": [],
"source": [
"openai_monitor.data"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
11 changes: 10 additions & 1 deletion openlayer/llm_monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class OpenAIMonitor:
Whether to publish the data to Openlayer as soon as it is available. If True,
the Openlayer credentials must be provided (either as keyword arguments or as
environment variables).
accumulate_data : bool, False
Whether to accumulate the data in a dataframe. If False (default), only the
latest request is stored. If True, all the requests are stored in a dataframe,
accessed through the `data` attribute.
client : openai.api_client.Client, optional
The OpenAI client. It is required if you are using openai>=1.0.0.
openlayer_api_key : str, optional
Expand Down Expand Up @@ -101,6 +105,7 @@ def __init__(
self,
publish: bool = False,
client=None,
accumulate_data: bool = False,
openlayer_api_key: Optional[str] = None,
openlayer_project_name: Optional[str] = None,
openlayer_inference_pipeline_name: Optional[str] = None,
Expand Down Expand Up @@ -134,6 +139,7 @@ def __init__(

self.df = pd.DataFrame(columns=["input", "output", "tokens", "latency"])
self.publish = publish
self.accumulate_data = accumulate_data
self.monitoring_on = False

def _initialize_openlayer(
Expand Down Expand Up @@ -311,7 +317,10 @@ def _append_row_to_df(
}
]
)
self.df = pd.concat([self.df, row], ignore_index=True)
if self.accumulate_data:
self.df = pd.concat([self.df, row], ignore_index=True)
else:
self.df = row
self.df = self.df.astype(
{"input": object, "output": object, "tokens": int, "latency": float}
)
Expand Down

0 comments on commit 67712b9

Please sign in to comment.