forked from Significant-Gravitas/Auto-GPT-Benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_data_from_helicone.py
45 lines (35 loc) · 1.09 KB
/
get_data_from_helicone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import requests
# 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 sk-"}
# Define the query, variables, and operation name
query = """
query ExampleQuery($limit: Int, $filters: [HeliconeRequestFilter!]) {
user {
id
}
heliconeRequest(limit: $limit,filters: $filters) {
responseBody
}
}
"""
variables = {
"limit": 100,
"filters": [{"property": {"value": {"equals": "beebot"}, "name": "agent"}}],
}
operation_name = "ExampleQuery"
# Make the request
response = requests.post(
url,
headers=headers,
json={"query": query, "variables": variables, "operationName": operation_name},
)
data = response.json()
total_tokens_sum = 0
for item in data["data"]["heliconeRequest"]:
total_tokens_sum += item["responseBody"]["usage"]["total_tokens"]
# Extract the data from the response (consider adding error checks)
print(json.dumps(data, indent=4, ensure_ascii=False))
print(total_tokens_sum)