llumo 0.2.27__tar.gz → 0.2.29__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {llumo-0.2.27/llumo.egg-info → llumo-0.2.29}/PKG-INFO +1 -1
- {llumo-0.2.27 → llumo-0.2.29}/llumo/google.py +16 -16
- {llumo-0.2.27 → llumo-0.2.29}/llumo/llumoSessionContext.py +3 -3
- llumo-0.2.29/llumo/openai.py +231 -0
- {llumo-0.2.27 → llumo-0.2.29/llumo.egg-info}/PKG-INFO +1 -1
- llumo-0.2.27/llumo/openai.py +0 -224
- {llumo-0.2.27 → llumo-0.2.29}/LICENSE +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/MANIFEST.in +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/README.md +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/__init__.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/callback.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/callbacks-0.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/chains.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/client.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/exceptions.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/execution.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/functionCalling.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/helpingFuntions.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/llumoLogger.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/models.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo/sockets.py +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo.egg-info/SOURCES.txt +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo.egg-info/dependency_links.txt +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo.egg-info/requires.txt +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/llumo.egg-info/top_level.txt +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/setup.cfg +0 -0
- {llumo-0.2.27 → llumo-0.2.29}/setup.py +0 -0
|
@@ -15,9 +15,9 @@ def evaluate_multiple(data, api_key=None, evals=["Response Correctness"]):
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class ChatCompletionWithEval:
|
|
18
|
-
def __init__(self, response, evaluation):
|
|
18
|
+
def __init__(self, response, evaluation=None):
|
|
19
19
|
self._response = response
|
|
20
|
-
self.evaluation = evaluation
|
|
20
|
+
# self.evaluation = evaluation
|
|
21
21
|
|
|
22
22
|
def __getattr__(self, name):
|
|
23
23
|
return getattr(self._response, name)
|
|
@@ -46,21 +46,21 @@ class genai:
|
|
|
46
46
|
response = self._model_instance.generate_content(contents=contents, **kwargs)
|
|
47
47
|
output = response.text
|
|
48
48
|
|
|
49
|
-
eval_input = [{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}]
|
|
49
|
+
# eval_input = [{
|
|
50
|
+
# "query": contents,
|
|
51
|
+
# "context": context or contents,
|
|
52
|
+
# "output": output,
|
|
53
|
+
# }]
|
|
54
54
|
|
|
55
|
-
evaluation = None
|
|
56
|
-
try:
|
|
57
|
-
|
|
58
|
-
except Exception as e:
|
|
59
|
-
|
|
55
|
+
# evaluation = None
|
|
56
|
+
# try:
|
|
57
|
+
# evaluation = evaluate_multiple(data=eval_input, evals=evals, api_key=llumo_key)
|
|
58
|
+
# except Exception as e:
|
|
59
|
+
# evaluation = None
|
|
60
60
|
|
|
61
|
-
if evaluation is None:
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
# if evaluation is None:
|
|
62
|
+
# print("Cannot process your request for evaluation, please check your api and try again later.")
|
|
63
|
+
# return response
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
return ChatCompletionWithEval(response, evaluation)
|
|
66
|
+
return ChatCompletionWithEval(response, evaluation=None)
|
|
@@ -91,7 +91,7 @@ class LlumoSessionContext(LlumoClient):
|
|
|
91
91
|
]
|
|
92
92
|
run["steps"] = clean_steps
|
|
93
93
|
|
|
94
|
-
print(run["runName"]) # optional debug log
|
|
94
|
+
# print(run["runName"]) # optional debug log
|
|
95
95
|
|
|
96
96
|
# STEP 3: Send the payload
|
|
97
97
|
url = "https://app.llumo.ai/api/create-debug-log"
|
|
@@ -107,7 +107,7 @@ class LlumoSessionContext(LlumoClient):
|
|
|
107
107
|
except requests.exceptions.Timeout:
|
|
108
108
|
print("Request timed out.")
|
|
109
109
|
except requests.exceptions.RequestException as e:
|
|
110
|
-
|
|
110
|
+
pass
|
|
111
111
|
|
|
112
112
|
# Cleanup
|
|
113
113
|
if self.threadLlumoRun:
|
|
@@ -120,7 +120,7 @@ class LlumoSessionContext(LlumoClient):
|
|
|
120
120
|
stepName: str,
|
|
121
121
|
metadata: Optional[dict] = None,
|
|
122
122
|
):
|
|
123
|
-
print(f"logged: {stepType}")
|
|
123
|
+
# print(f"logged: {stepType}")
|
|
124
124
|
run = getLlumoRun()
|
|
125
125
|
if run is None:
|
|
126
126
|
raise RuntimeError("No active run to log steps.")
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from openai import OpenAI as OpenAIClient
|
|
3
|
+
from .client import LlumoClient
|
|
4
|
+
from .llumoSessionContext import LlumoSessionContext
|
|
5
|
+
from .llumoLogger import LlumoLogger
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# evaluation function that uses LlumoClient
|
|
9
|
+
def performEvaluation(data, api_key=None, evals=["Response Correctness"], **kwargs):
|
|
10
|
+
try:
|
|
11
|
+
client = LlumoClient(api_key=api_key)
|
|
12
|
+
results = client.evaluateMultiple(
|
|
13
|
+
data,
|
|
14
|
+
evals=evals,
|
|
15
|
+
createExperiment=kwargs.get("createExperiment", False),
|
|
16
|
+
playgroundID=kwargs.get("playgroundID"),
|
|
17
|
+
prompt_template="Give answer to the query: {{query}}, using context: {{context}}",
|
|
18
|
+
getDataFrame=False,
|
|
19
|
+
)
|
|
20
|
+
return results
|
|
21
|
+
except Exception as e:
|
|
22
|
+
print(f"Error in perform_evaluation: {e}")
|
|
23
|
+
raise
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Wrapper around ChatCompletion to allow custom fields like `.evaluation`
|
|
27
|
+
class ChatCompletionWithEval:
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
response,
|
|
31
|
+
# , evaluation
|
|
32
|
+
):
|
|
33
|
+
self._response = response
|
|
34
|
+
# self.evaluation = evaluation
|
|
35
|
+
|
|
36
|
+
def __getattr__(self, name):
|
|
37
|
+
return getattr(self._response, name)
|
|
38
|
+
|
|
39
|
+
def __getitem__(self, key):
|
|
40
|
+
return self._response[key]
|
|
41
|
+
|
|
42
|
+
def __repr__(self):
|
|
43
|
+
return repr(self._response)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class OpenAI(OpenAIClient):
|
|
47
|
+
def __init__(self, api_key: str, session):
|
|
48
|
+
super().__init__(api_key=api_key)
|
|
49
|
+
self.session = session
|
|
50
|
+
self.llumo_key = session.apiKey
|
|
51
|
+
|
|
52
|
+
original_create = self.chat.completions.create
|
|
53
|
+
|
|
54
|
+
def create_wrapper(*args, **kwargs):
|
|
55
|
+
context = kwargs.pop("context", None)
|
|
56
|
+
model = kwargs["model"]
|
|
57
|
+
create_experiment = kwargs.pop("createExperiment", False)
|
|
58
|
+
|
|
59
|
+
messages = kwargs.get("messages", [])
|
|
60
|
+
user_message = next(
|
|
61
|
+
(
|
|
62
|
+
m.get("content")
|
|
63
|
+
for m in reversed(messages)
|
|
64
|
+
if m.get("role") == "user"
|
|
65
|
+
),
|
|
66
|
+
"",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
if not context or context.strip() == "":
|
|
70
|
+
context = user_message
|
|
71
|
+
|
|
72
|
+
# Get IDs from the session logger
|
|
73
|
+
playground_id = self.session.logger.getPlaygroundID()
|
|
74
|
+
workspace_id = self.session.logger.getWorkspaceID()
|
|
75
|
+
|
|
76
|
+
# Input Bias Evaluation
|
|
77
|
+
# eval_input_bias = [
|
|
78
|
+
# {
|
|
79
|
+
# "query": user_message,
|
|
80
|
+
# "context": context,
|
|
81
|
+
# "output": "", # No output yet
|
|
82
|
+
# }
|
|
83
|
+
# ]
|
|
84
|
+
# try:
|
|
85
|
+
# start_time = time.time()
|
|
86
|
+
# bias_evaluation_result = performEvaluation(
|
|
87
|
+
# eval_input_bias,
|
|
88
|
+
# api_key=self.llumo_key,
|
|
89
|
+
# evals=["Input Bias"],
|
|
90
|
+
# playgroundID=playground_id,
|
|
91
|
+
# workspaceID=workspace_id,
|
|
92
|
+
# createExperiment=create_experiment,
|
|
93
|
+
# )
|
|
94
|
+
# latency = int((time.time() - start_time) * 1000)
|
|
95
|
+
# # Access the first result object
|
|
96
|
+
# bias_evaluation = bias_evaluation_result[0]
|
|
97
|
+
# message = "-".join(
|
|
98
|
+
# getattr(bias_evaluation, "edgeCases", {}).get("value", [])
|
|
99
|
+
# )
|
|
100
|
+
# self.session.logEvalStep(
|
|
101
|
+
# stepName=f"EVAL-Input Bias",
|
|
102
|
+
# output="",
|
|
103
|
+
# context=context,
|
|
104
|
+
# query=user_message,
|
|
105
|
+
# messageHistory="",
|
|
106
|
+
# tools="",
|
|
107
|
+
# intermediateSteps="",
|
|
108
|
+
# groundTruth="",
|
|
109
|
+
# analyticsScore=getattr(bias_evaluation, "analyticsScore", {}),
|
|
110
|
+
# reasoning=getattr(bias_evaluation, "reasoning", {}),
|
|
111
|
+
# classification=getattr(bias_evaluation, "classification", {}),
|
|
112
|
+
# evalLabel=getattr(bias_evaluation, "evalLabel", {}),
|
|
113
|
+
# latencyMs=latency,
|
|
114
|
+
# status="SUCCESS",
|
|
115
|
+
# message=message,
|
|
116
|
+
# )
|
|
117
|
+
# except Exception as e:
|
|
118
|
+
# print(f"Input Bias evaluation failed: {e}")
|
|
119
|
+
# self.session.logEvalStep(
|
|
120
|
+
# stepName=f"EVAL-FAILURE",
|
|
121
|
+
# output="",
|
|
122
|
+
# context=context,
|
|
123
|
+
# query=user_message,
|
|
124
|
+
# messageHistory="",
|
|
125
|
+
# tools="",
|
|
126
|
+
# intermediateSteps="",
|
|
127
|
+
# groundTruth="",
|
|
128
|
+
# analyticsScore={},
|
|
129
|
+
# reasoning={},
|
|
130
|
+
# classification={},
|
|
131
|
+
# evalLabel={},
|
|
132
|
+
# latencyMs=0,
|
|
133
|
+
# status="FAILURE",
|
|
134
|
+
# message="EVAL_ERROR",
|
|
135
|
+
# )
|
|
136
|
+
|
|
137
|
+
start_time = time.time()
|
|
138
|
+
response = original_create(*args, **kwargs)
|
|
139
|
+
latency = int((time.time() - start_time) * 1000)
|
|
140
|
+
output_text = response.choices[0].message.content
|
|
141
|
+
|
|
142
|
+
self.session.logLlmStep(
|
|
143
|
+
stepName=f"LLM-{user_message[:30]}",
|
|
144
|
+
model=model,
|
|
145
|
+
provider="openai",
|
|
146
|
+
inputTokens=response.usage.prompt_tokens,
|
|
147
|
+
outputTokens=response.usage.completion_tokens,
|
|
148
|
+
temperature=kwargs.get("temperature", 0.0),
|
|
149
|
+
promptTruncated=False,
|
|
150
|
+
latencyMs=latency,
|
|
151
|
+
query=user_message,
|
|
152
|
+
output=output_text,
|
|
153
|
+
status="SUCCESS",
|
|
154
|
+
message="",
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# Response Correctness Evaluation
|
|
158
|
+
# eval_input_correctness = [
|
|
159
|
+
# {
|
|
160
|
+
# "query": user_message,
|
|
161
|
+
# "context": context,
|
|
162
|
+
# "output": output_text,
|
|
163
|
+
# }
|
|
164
|
+
# ]
|
|
165
|
+
# try:
|
|
166
|
+
# start_time = time.time()
|
|
167
|
+
# correctness_evaluation_result = performEvaluation(
|
|
168
|
+
# eval_input_correctness,
|
|
169
|
+
# api_key=self.llumo_key,
|
|
170
|
+
# evals=["Response Correctness"],
|
|
171
|
+
# playgroundID=playground_id,
|
|
172
|
+
# workspaceID=workspace_id,
|
|
173
|
+
# createExperiment=create_experiment,
|
|
174
|
+
# )
|
|
175
|
+
# latency = int((time.time() - start_time) * 1000)
|
|
176
|
+
# # Access the first result object
|
|
177
|
+
# correctness_evaluation = correctness_evaluation_result[0]
|
|
178
|
+
# message = "-".join(
|
|
179
|
+
# getattr(correctness_evaluation, "edgeCases", {}).get("value", [])
|
|
180
|
+
# )
|
|
181
|
+
# self.session.logEvalStep(
|
|
182
|
+
# stepName=f"EVAL-Response Correctness",
|
|
183
|
+
# output=output_text,
|
|
184
|
+
# context=context,
|
|
185
|
+
# query=user_message,
|
|
186
|
+
# messageHistory="",
|
|
187
|
+
# tools="",
|
|
188
|
+
# intermediateSteps="",
|
|
189
|
+
# groundTruth="",
|
|
190
|
+
# analyticsScore=getattr(
|
|
191
|
+
# correctness_evaluation, "analyticsScore", {}
|
|
192
|
+
# ),
|
|
193
|
+
# reasoning=getattr(correctness_evaluation, "reasoning", {}),
|
|
194
|
+
# classification=getattr(
|
|
195
|
+
# correctness_evaluation, "classification", {}
|
|
196
|
+
# ),
|
|
197
|
+
# evalLabel=getattr(correctness_evaluation, "evalLabel", {}),
|
|
198
|
+
# latencyMs=latency,
|
|
199
|
+
# status="SUCCESS",
|
|
200
|
+
# message=message,
|
|
201
|
+
# )
|
|
202
|
+
# except Exception as e:
|
|
203
|
+
# print(f"Response Correctness evaluation failed: {e}")
|
|
204
|
+
# correctness_evaluation = None
|
|
205
|
+
# self.session.logEvalStep(
|
|
206
|
+
# stepName=f"EVAL-FAILURE",
|
|
207
|
+
# output=output_text,
|
|
208
|
+
# context=context,
|
|
209
|
+
# query=user_message,
|
|
210
|
+
# messageHistory="",
|
|
211
|
+
# tools="",
|
|
212
|
+
# intermediateSteps="",
|
|
213
|
+
# groundTruth="",
|
|
214
|
+
# analyticsScore={},
|
|
215
|
+
# reasoning={},
|
|
216
|
+
# classification={},
|
|
217
|
+
# evalLabel={},
|
|
218
|
+
# latencyMs=0,
|
|
219
|
+
# status="FAILURE",
|
|
220
|
+
# message="EVAL_ERROR",
|
|
221
|
+
# )
|
|
222
|
+
|
|
223
|
+
# if correctness_evaluation is None:
|
|
224
|
+
# return response
|
|
225
|
+
|
|
226
|
+
return ChatCompletionWithEval(
|
|
227
|
+
response
|
|
228
|
+
# , correctness_evaluation
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
self.chat.completions.create = create_wrapper
|
llumo-0.2.27/llumo/openai.py
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
from openai import OpenAI as OpenAIClient
|
|
3
|
-
from .client import LlumoClient
|
|
4
|
-
from .llumoSessionContext import LlumoSessionContext
|
|
5
|
-
from .llumoLogger import LlumoLogger
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# evaluation function that uses LlumoClient
|
|
9
|
-
def performEvaluation(data, api_key=None, evals=["Response Correctness"], **kwargs):
|
|
10
|
-
try:
|
|
11
|
-
client = LlumoClient(api_key=api_key)
|
|
12
|
-
results = client.evaluateMultiple(
|
|
13
|
-
data,
|
|
14
|
-
evals=evals,
|
|
15
|
-
createExperiment=kwargs.get("createExperiment", False),
|
|
16
|
-
playgroundID=kwargs.get("playgroundID"),
|
|
17
|
-
prompt_template="Give answer to the query: {{query}}, using context: {{context}}",
|
|
18
|
-
getDataFrame=False,
|
|
19
|
-
)
|
|
20
|
-
return results
|
|
21
|
-
except Exception as e:
|
|
22
|
-
print(f"Error in perform_evaluation: {e}")
|
|
23
|
-
raise
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
# Wrapper around ChatCompletion to allow custom fields like `.evaluation`
|
|
27
|
-
class ChatCompletionWithEval:
|
|
28
|
-
def __init__(self, response, evaluation):
|
|
29
|
-
self._response = response
|
|
30
|
-
self.evaluation = evaluation
|
|
31
|
-
|
|
32
|
-
def __getattr__(self, name):
|
|
33
|
-
return getattr(self._response, name)
|
|
34
|
-
|
|
35
|
-
def __getitem__(self, key):
|
|
36
|
-
return self._response[key]
|
|
37
|
-
|
|
38
|
-
def __repr__(self):
|
|
39
|
-
return repr(self._response)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class OpenAI(OpenAIClient):
|
|
43
|
-
def __init__(self, api_key: str, session):
|
|
44
|
-
super().__init__(api_key=api_key)
|
|
45
|
-
self.session = session
|
|
46
|
-
self.llumo_key = session.apiKey
|
|
47
|
-
|
|
48
|
-
original_create = self.chat.completions.create
|
|
49
|
-
|
|
50
|
-
def create_wrapper(*args, **kwargs):
|
|
51
|
-
context = kwargs.pop("context", None)
|
|
52
|
-
model = kwargs["model"]
|
|
53
|
-
create_experiment = kwargs.pop("createExperiment", False)
|
|
54
|
-
|
|
55
|
-
messages = kwargs.get("messages", [])
|
|
56
|
-
user_message = next(
|
|
57
|
-
(
|
|
58
|
-
m.get("content")
|
|
59
|
-
for m in reversed(messages)
|
|
60
|
-
if m.get("role") == "user"
|
|
61
|
-
),
|
|
62
|
-
"",
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
if not context or context.strip() == "":
|
|
66
|
-
context = user_message
|
|
67
|
-
|
|
68
|
-
# Get IDs from the session logger
|
|
69
|
-
playground_id = self.session.logger.getPlaygroundID()
|
|
70
|
-
workspace_id = self.session.logger.getWorkspaceID()
|
|
71
|
-
|
|
72
|
-
# Input Bias Evaluation
|
|
73
|
-
eval_input_bias = [
|
|
74
|
-
{
|
|
75
|
-
"query": user_message,
|
|
76
|
-
"context": context,
|
|
77
|
-
"output": "", # No output yet
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
try:
|
|
81
|
-
start_time = time.time()
|
|
82
|
-
bias_evaluation_result = performEvaluation(
|
|
83
|
-
eval_input_bias,
|
|
84
|
-
api_key=self.llumo_key,
|
|
85
|
-
evals=["Input Bias"],
|
|
86
|
-
playgroundID=playground_id,
|
|
87
|
-
workspaceID=workspace_id,
|
|
88
|
-
createExperiment=create_experiment,
|
|
89
|
-
)
|
|
90
|
-
latency = int((time.time() - start_time) * 1000)
|
|
91
|
-
# Access the first result object
|
|
92
|
-
bias_evaluation = bias_evaluation_result[0]
|
|
93
|
-
message = "-".join(
|
|
94
|
-
getattr(bias_evaluation, "edgeCases", {}).get("value", [])
|
|
95
|
-
)
|
|
96
|
-
self.session.logEvalStep(
|
|
97
|
-
stepName=f"EVAL-Input Bias",
|
|
98
|
-
output="",
|
|
99
|
-
context=context,
|
|
100
|
-
query=user_message,
|
|
101
|
-
messageHistory="",
|
|
102
|
-
tools="",
|
|
103
|
-
intermediateSteps="",
|
|
104
|
-
groundTruth="",
|
|
105
|
-
analyticsScore=getattr(bias_evaluation, "analyticsScore", {}),
|
|
106
|
-
reasoning=getattr(bias_evaluation, "reasoning", {}),
|
|
107
|
-
classification=getattr(bias_evaluation, "classification", {}),
|
|
108
|
-
evalLabel=getattr(bias_evaluation, "evalLabel", {}),
|
|
109
|
-
latencyMs=latency,
|
|
110
|
-
status="SUCCESS",
|
|
111
|
-
message=message,
|
|
112
|
-
)
|
|
113
|
-
except Exception as e:
|
|
114
|
-
print(f"Input Bias evaluation failed: {e}")
|
|
115
|
-
self.session.logEvalStep(
|
|
116
|
-
stepName=f"EVAL-FAILURE",
|
|
117
|
-
output="",
|
|
118
|
-
context=context,
|
|
119
|
-
query=user_message,
|
|
120
|
-
messageHistory="",
|
|
121
|
-
tools="",
|
|
122
|
-
intermediateSteps="",
|
|
123
|
-
groundTruth="",
|
|
124
|
-
analyticsScore={},
|
|
125
|
-
reasoning={},
|
|
126
|
-
classification={},
|
|
127
|
-
evalLabel={},
|
|
128
|
-
latencyMs=0,
|
|
129
|
-
status="FAILURE",
|
|
130
|
-
message="EVAL_ERROR",
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
start_time = time.time()
|
|
134
|
-
response = original_create(*args, **kwargs)
|
|
135
|
-
latency = int((time.time() - start_time) * 1000)
|
|
136
|
-
output_text = response.choices[0].message.content
|
|
137
|
-
|
|
138
|
-
self.session.logLlmStep(
|
|
139
|
-
stepName=f"LLM-{user_message[:30]}",
|
|
140
|
-
model=model,
|
|
141
|
-
provider="openai",
|
|
142
|
-
inputTokens=response.usage.prompt_tokens,
|
|
143
|
-
outputTokens=response.usage.completion_tokens,
|
|
144
|
-
temperature=kwargs.get("temperature", 0.0),
|
|
145
|
-
promptTruncated=False,
|
|
146
|
-
latencyMs=latency,
|
|
147
|
-
query=user_message,
|
|
148
|
-
output=output_text,
|
|
149
|
-
status="SUCCESS",
|
|
150
|
-
message="",
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
# Response Correctness Evaluation
|
|
154
|
-
eval_input_correctness = [
|
|
155
|
-
{
|
|
156
|
-
"query": user_message,
|
|
157
|
-
"context": context,
|
|
158
|
-
"output": output_text,
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
try:
|
|
162
|
-
start_time = time.time()
|
|
163
|
-
correctness_evaluation_result = performEvaluation(
|
|
164
|
-
eval_input_correctness,
|
|
165
|
-
api_key=self.llumo_key,
|
|
166
|
-
evals=["Response Correctness"],
|
|
167
|
-
playgroundID=playground_id,
|
|
168
|
-
workspaceID=workspace_id,
|
|
169
|
-
createExperiment=create_experiment,
|
|
170
|
-
)
|
|
171
|
-
latency = int((time.time() - start_time) * 1000)
|
|
172
|
-
# Access the first result object
|
|
173
|
-
correctness_evaluation = correctness_evaluation_result[0]
|
|
174
|
-
message = "-".join(
|
|
175
|
-
getattr(correctness_evaluation, "edgeCases", {}).get("value", [])
|
|
176
|
-
)
|
|
177
|
-
self.session.logEvalStep(
|
|
178
|
-
stepName=f"EVAL-Response Correctness",
|
|
179
|
-
output=output_text,
|
|
180
|
-
context=context,
|
|
181
|
-
query=user_message,
|
|
182
|
-
messageHistory="",
|
|
183
|
-
tools="",
|
|
184
|
-
intermediateSteps="",
|
|
185
|
-
groundTruth="",
|
|
186
|
-
analyticsScore=getattr(
|
|
187
|
-
correctness_evaluation, "analyticsScore", {}
|
|
188
|
-
),
|
|
189
|
-
reasoning=getattr(correctness_evaluation, "reasoning", {}),
|
|
190
|
-
classification=getattr(
|
|
191
|
-
correctness_evaluation, "classification", {}
|
|
192
|
-
),
|
|
193
|
-
evalLabel=getattr(correctness_evaluation, "evalLabel", {}),
|
|
194
|
-
latencyMs=latency,
|
|
195
|
-
status="SUCCESS",
|
|
196
|
-
message=message,
|
|
197
|
-
)
|
|
198
|
-
except Exception as e:
|
|
199
|
-
print(f"Response Correctness evaluation failed: {e}")
|
|
200
|
-
correctness_evaluation = None
|
|
201
|
-
self.session.logEvalStep(
|
|
202
|
-
stepName=f"EVAL-FAILURE",
|
|
203
|
-
output=output_text,
|
|
204
|
-
context=context,
|
|
205
|
-
query=user_message,
|
|
206
|
-
messageHistory="",
|
|
207
|
-
tools="",
|
|
208
|
-
intermediateSteps="",
|
|
209
|
-
groundTruth="",
|
|
210
|
-
analyticsScore={},
|
|
211
|
-
reasoning={},
|
|
212
|
-
classification={},
|
|
213
|
-
evalLabel={},
|
|
214
|
-
latencyMs=0,
|
|
215
|
-
status="FAILURE",
|
|
216
|
-
message="EVAL_ERROR",
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
if correctness_evaluation is None:
|
|
220
|
-
return response
|
|
221
|
-
|
|
222
|
-
return ChatCompletionWithEval(response, correctness_evaluation)
|
|
223
|
-
|
|
224
|
-
self.chat.completions.create = create_wrapper
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|