generated from teamhide/fastapi-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfiddlecube.py
76 lines (71 loc) · 2.42 KB
/
fiddlecube.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import requests
import json
class FiddleCube:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://api.fiddlecube.ai/api"
def generate(self, context_str: list[str], num_rows: int):
url = self.base_url + "/generate/sync"
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"X-Api-Key": self.api_key,
}
dataset = [{"contexts": [ctx]} for ctx in context_str]
data = {
"dataset": dataset,
"question_types": [
"SIMPLE",
"REASONING",
"NEGATIVE",
"CONDITIONAL",
"UNSAFE",
"MCQ",
],
"num_rows": num_rows,
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print("Data generation successful.")
return response.json()
else:
print("Failed to generate data.")
print("==response==", response)
return None
def diagnose(self, logs: list[dict]):
"""
Run diagnostics on a log of LLM interactions.
Step-by-step analysis of how the LLM output was achieved
based on the query, prompt, answer and context.
"""
url = self.base_url + "/debug/"
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"X-Api-Key": self.api_key,
}
data = {"dataset": logs}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print("Debugging successful.")
return response.json()
else:
print("Failed to debug.")
print("==response==", response)
return None
def test(
self, prompt: str, ground_truth_dataset: list[dict], model: str = "gpt=4o"
):
url = self.base_url + "/eval/test"
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"X-Api-Key": self.api_key,
}
data = {
"prompt": prompt,
"ground_truth_dataset": ground_truth_dataset,
"model": model,
}
response = requests.post(url, headers=headers, data=json.dumps(data))
return response.json()