Skip to content

Commit

Permalink
community[patch] : publishes duration as milliseconds to Fiddler (lan…
Browse files Browse the repository at this point in the history
…gchain-ai#19166)

**Description:** Many LLM steps complete in sub-second duration, which
can lead to non-collection of duration field for Fiddler. This PR
updates duration from seconds to milliseconds.
**Issue:** [INTERNAL] FDL-17568
**Dependencies:** NA
**Twitter handle:** behalder

Co-authored-by: Barun Halder <barun@fiddler.ai>
  • Loading branch information
2 people authored and gkorland committed Mar 30, 2024
1 parent 9de9d2c commit e24808a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions libs/community/langchain_community/callbacks/fiddler_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Default values
DEFAULT_MAX_TOKEN = 65536
DEFAULT_MAX_DURATION = 120
DEFAULT_MAX_DURATION = 120000

# Fiddler specific constants
PROMPT = "prompt"
Expand Down Expand Up @@ -154,7 +154,7 @@ def __init__(
dataset_info=dataset_info,
dataset_id="train",
model_task=self.fdl.ModelTask.LLM,
features=[PROMPT, RESPONSE, CONTEXT],
features=[PROMPT, CONTEXT, RESPONSE],
target=FEEDBACK,
metadata_cols=[
RUN_ID,
Expand Down Expand Up @@ -297,12 +297,12 @@ def on_llm_start(
) -> Any:
run_id = kwargs[RUN_ID]
self.run_id_prompts[run_id] = prompts
self.run_id_starttime[run_id] = int(time.time())
self.run_id_starttime[run_id] = int(time.time() * 1000)

def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:
flattened_llmresult = response.flatten()
run_id = kwargs[RUN_ID]
run_duration = self.run_id_starttime[run_id] - int(time.time())
run_duration = int(time.time() * 1000) - self.run_id_starttime[run_id]
model_name = ""
token_usage_dict = {}

Expand All @@ -329,7 +329,7 @@ def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:

def on_llm_error(self, error: BaseException, **kwargs: Any) -> None:
run_id = kwargs[RUN_ID]
duration = int(time.time()) - self.run_id_starttime[run_id]
duration = int(time.time() * 1000) - self.run_id_starttime[run_id]

self._publish_events(
run_id, [""] * len(self.run_id_prompts[run_id]), duration, FAILURE
Expand Down

0 comments on commit e24808a

Please sign in to comment.