Skip to content

Commit

Permalink
log inference time of api call
Browse files Browse the repository at this point in the history
  • Loading branch information
tabergma committed Oct 12, 2023
1 parent 503c901 commit 30a8f62
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions rasa/dialogue_understanding/generator/llm_command_generator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import importlib.resources
import re
import time
from typing import Dict, Any, Optional, List, Union

from jinja2 import Template
import structlog

from rasa.dialogue_understanding.stack.utils import top_flow_frame
from rasa.dialogue_understanding.generator import CommandGenerator
from rasa.dialogue_understanding.commands import (
Expand Down Expand Up @@ -129,13 +131,27 @@ def _generate_action_list_using_llm(self, prompt: str) -> Optional[str]:
"""
llm = llm_factory(self.config.get(LLM_CONFIG_KEY), DEFAULT_LLM_CONFIG)

result = None
duration = 0
try:
return llm(prompt)
start = time.time()
result = llm(prompt)
end = time.time()
duration = end - start
except Exception as e:
# unfortunately, langchain does not wrap LLM exceptions which means
# we have to catch all exceptions here
structlogger.error("llm_command_generator.llm.error", error=e)
return None

structlogger.info(
"llm_command_generator.predict_commands.inference_time_api_call",
duration=duration,
)
structlogger.info(
"llm_command_generator.predict_commands.prompt_length",
prompt_length=len(prompt),
)
return result

def predict_commands(
self,
Expand Down

0 comments on commit 30a8f62

Please sign in to comment.