Skip to content

Commit 198eabc

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Add monitor_output_only param to the OpenAI LLM monitor
1 parent cfb8155 commit 198eabc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
## Unreleased
99

1010
### Added
11+
* Added `monitor_output_only` as an argument to the OpenAI `llm_monitor`. If set to `True`, the monitor will only record the output of the model, and not the input.
1112
* Added `costColumnName` as an optional field in the config for LLM data.
1213

1314
### Changed

openlayer/llm_monitors.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class OpenAIMonitor:
2929
accessed through the `data` attribute.
3030
client : openai.api_client.Client, optional
3131
The OpenAI client. It is required if you are using openai>=1.0.0.
32+
monitor_output_only : bool, False
33+
Whether to monitor only the output of the model. If True, only the output of
34+
the model is logged.
3235
openlayer_api_key : str, optional
3336
The Openlayer API key. If not provided, it is read from the environment
3437
variable ``OPENLAYER_API_KEY``. This is required if `publish` is set to True.
@@ -150,6 +153,7 @@ def __init__(
150153
self,
151154
publish: bool = False,
152155
client=None,
156+
monitor_output_only: bool = False,
153157
accumulate_data: bool = False,
154158
openlayer_api_key: Optional[str] = None,
155159
openlayer_project_name: Optional[str] = None,
@@ -184,6 +188,7 @@ def __init__(
184188

185189
self.df = pd.DataFrame(columns=["input", "output", "tokens", "latency"])
186190
self.publish = publish
191+
self.monitor_output_only = monitor_output_only
187192
self.accumulate_data = accumulate_data
188193
self.monitoring_on = False
189194

@@ -274,9 +279,10 @@ def modified_create_chat_completion(*args, **kwargs) -> str:
274279
)
275280

276281
config = self.data_config.copy()
277-
config["prompt"] = prompt
278-
config.update({"inputVariableNames": list(input_data.keys())})
279282
config["costColumnName"] = "cost"
283+
config["prompt"] = prompt
284+
if not self.monitor_output_only:
285+
config.update({"inputVariableNames": list(input_data.keys())})
280286

281287
self._append_row_to_df(
282288
input_data=input_data,
@@ -327,6 +333,9 @@ def modified_create_completion(*args, **kwargs):
327333

328334
config = self.data_config.copy()
329335
config["costColumnName"] = "cost"
336+
if not self.monitor_output_only:
337+
config["prompt"] = [{"role": "user", "content": input_data}]
338+
config["inputVariableNames"] = ["message"]
330339

331340
self._handle_data_publishing(config=config)
332341
# pylint: disable=broad-except
@@ -422,6 +431,9 @@ def _append_row_to_df(
422431
) -> None:
423432
"""Appends a row with input/output, number of tokens, and latency to the
424433
df."""
434+
if self.monitor_output_only:
435+
input_data = {}
436+
425437
row = pd.DataFrame(
426438
[
427439
{
@@ -549,7 +561,7 @@ def publish_batch_data(self):
549561
def data_config(self) -> Dict[str, any]:
550562
"""Data config for the df. Used for publishing data to Openlayer."""
551563
return {
552-
"inputVariableNames": ["message"],
564+
"inputVariableNames": [],
553565
"label": "production",
554566
"outputColumnName": "output",
555567
"numOfTokenColumnName": "tokens",

0 commit comments

Comments
 (0)