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

Log runtime and sdk version in telemetry #133

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ Tonic Validate collects minimal telemetry to help us figure out what users want

* What metrics were used for a run
* Number of questions in a run
* Time taken for a run to be evaluated
* Number of questions in a benchmark
* SDK Version being used

We do **NOT** track things such as the contents of the questions / answers, your scores, or any other sensitive information. For detecting CI/CD, we only check for common environment variables in different CI/CD environments. We do not log the values of these environment variables.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tonic-validate"
version = "4.0.4"
version = "4.0.5"
description = "RAG evaluation metrics."
authors = ["Joe Ferrara <joeferrara@tonic.ai>", "Ethan Philpott <ephilpott@tonic.ai>", "Adam Kamor <adam@tonic.ai>"]
readme = "README.md"
Expand Down
12 changes: 11 additions & 1 deletion tonic_validate/utils/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __is_ci(self):
return True
return False

def log_run(self, num_of_questions: int, metrics: List[str]):
def log_run(self, num_of_questions: int, metrics: List[str], run_time: float):
"""
Logs a run to the Tonic Validate server
Expand All @@ -76,16 +76,26 @@ def log_run(self, num_of_questions: int, metrics: List[str]):
The number of questions asked
metrics: List[str]
The metrics that were used to evaluate the run
run_time: float
The time taken to evaluate the run
"""
if self.config.TONIC_VALIDATE_DO_NOT_TRACK:
return
try:
from importlib.metadata import version
sdk_version = version('tonic-validate')
except Exception:
sdk_version = "unknown"

user_id = self.get_user()["user_id"]
self.http_client.http_post(
"/runs",
data={
"user_id": user_id,
"num_of_questions": num_of_questions,
"metrics": metrics,
"run_time": run_time,
"sdk_version": sdk_version,
"is_ci": self.__is_ci(),
"validate_gh_action": self.config.TONIC_VALIDATE_GITHUB_ACTION,
},
Expand Down
20 changes: 15 additions & 5 deletions tonic_validate/validate_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ async def a_score_responses(
The Run object containing the scores and other data.
"""
try:
self.telemetry.log_run(
len(responses), [metric.name for metric in self.metrics]
)
start_time = time.time()
except Exception as _:
pass

start_time = -1
semaphore = Semaphore(parallelism)
tasks = [
self._score_item_rundata(response, semaphore) for response in responses
Expand All @@ -196,6 +194,18 @@ async def a_score_responses(
overall_scores: Dict[str, float] = {
metric: total / num_scores[metric] for metric, total in total_scores.items()
}
try:
end_time = time.time()
run_time = end_time - start_time
except Exception as _:
run_time = -1

try:
self.telemetry.log_run(
len(responses), [metric.name for metric in self.metrics], run_time
)
except Exception as _:
pass

return Run(overall_scores=overall_scores, run_data=run_data, llm_evaluator=self.model_evaluator, id=None)

Expand Down
Loading