Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Get helicone costs #220

Merged
merged 4 commits into from
Jul 31, 2023
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
53 changes: 53 additions & 0 deletions agbenchmark/get_data_from_helicone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
from typing import Optional

import requests

from agbenchmark.start_benchmark import BENCHMARK_START_TIME


def get_data_from_helicone(challenge: str) -> Optional[float]:
# Define the endpoint of your GraphQL server
url = "https://www.helicone.ai/api/graphql"

# Set the headers, usually you'd need to set the content type and possibly an authorization token
headers = {"authorization": "Bearer {os.environ.get('HELICONE_API_KEY')}"}

# Define the query, variables, and operation name
query = """
query ExampleQuery {
aggregatedHeliconeRequest {
cost
}
}
"""

variables = {
"filters": [
{
"property": {
"value": {"equals": os.environ.get("AGENT_NAME")},
"name": "agent",
}
},
{
"property": {
"value": {"equals": BENCHMARK_START_TIME},
"name": "benchmark_start_time",
}
},
{"property": {"value": {"equals": challenge}, "name": "challenge"}},
]
}

operation_name = "ExampleQuery"

# Make the request
response = requests.post(
url,
headers=headers,
json={"query": query, "variables": variables, "operationName": operation_name},
)
data = response.json()

return data.get("data", {}).get("aggregatedHeliconeRequest", {}).get("cost", None)
8 changes: 8 additions & 0 deletions agbenchmark/reports/reports.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json
import os
import sys
from pathlib import Path
from typing import Any, Callable

import pytest

from agbenchmark.agent_interface import MOCK_FLAG
from agbenchmark.get_data_from_helicone import get_data_from_helicone
from agbenchmark.reports.ReportManager import ReportManager
from agbenchmark.start_benchmark import CONFIG_PATH, REGRESSION_TESTS_PATH, REPORTS_PATH
from agbenchmark.utils.data_types import DIFFICULTY_MAP, DifficultyLevel, SuiteConfig
Expand Down Expand Up @@ -234,6 +237,11 @@ def finalize_reports(item: Any, challenge_data: dict[str, Any]) -> None:

if info_details and test_name:
if run_time:
cost = None
if not MOCK_FLAG and os.environ.get("HELICONE_API_KEY"):
cost = get_data_from_helicone(test_name)

info_details["metrics"]["cost"] = cost
info_details["metrics"]["run_time"] = f"{str(round(run_time, 3))} seconds"

info_details["reached_cutoff"] = float(run_time) > challenge_data["cutoff"]
Expand Down
Loading