llumo 0.2.39__py3-none-any.whl → 0.2.41__py3-none-any.whl
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/callback.py +38 -11
- llumo/client.py +121 -8
- llumo/helpingFuntions.py +72 -1
- llumo/llumoLogger.py +1 -0
- llumo/llumoSessionContext.py +21 -10
- {llumo-0.2.39.dist-info → llumo-0.2.41.dist-info}/METADATA +1 -1
- {llumo-0.2.39.dist-info → llumo-0.2.41.dist-info}/RECORD +10 -10
- {llumo-0.2.39.dist-info → llumo-0.2.41.dist-info}/WHEEL +0 -0
- {llumo-0.2.39.dist-info → llumo-0.2.41.dist-info}/licenses/LICENSE +0 -0
- {llumo-0.2.39.dist-info → llumo-0.2.41.dist-info}/top_level.txt +0 -0
llumo/callback.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from logging import lastResort
|
|
1
2
|
from typing import Any, Dict, List
|
|
2
3
|
from langchain_core.callbacks.base import BaseCallbackHandler
|
|
3
4
|
from langchain_core.messages import BaseMessage
|
|
@@ -17,7 +18,7 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
17
18
|
raise ValueError("LlumoSessionContext is required")
|
|
18
19
|
|
|
19
20
|
self.sessionLogger = session
|
|
20
|
-
self.sessionLogger.isLangchain = True
|
|
21
|
+
self.sessionLogger.logger.isLangchain = True
|
|
21
22
|
self.agentType = agentType
|
|
22
23
|
|
|
23
24
|
# Initialize timing and state variables
|
|
@@ -30,6 +31,7 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
30
31
|
# Initialize tracking variables
|
|
31
32
|
self.prompt = ""
|
|
32
33
|
self.searchQuery = ""
|
|
34
|
+
self.currentInputTokens = 0
|
|
33
35
|
self.currentToolName = None
|
|
34
36
|
self.currentToolInput = None
|
|
35
37
|
self.currentAgentName = None
|
|
@@ -48,8 +50,7 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
48
50
|
self.currentAction = ""
|
|
49
51
|
self.currentObservation = ""
|
|
50
52
|
self.isAgentExecution = False
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
self.availableTools = None
|
|
53
54
|
|
|
54
55
|
def on_chain_start(self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any) -> None:
|
|
55
56
|
"""Called when a chain starts - this includes agent execution"""
|
|
@@ -86,8 +87,9 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
86
87
|
elif "id" in serialized and isinstance(serialized["id"], list):
|
|
87
88
|
self.currentAgentName = serialized["id"][-1] if serialized["id"] else "unknown"
|
|
88
89
|
else:
|
|
89
|
-
self.currentAgentName = "unknown"
|
|
90
|
-
|
|
90
|
+
self.currentAgentName = kwargs.get("name","unknown")
|
|
91
|
+
else:
|
|
92
|
+
self.currentAgentName = kwargs.get("name", "unknown")
|
|
91
93
|
# Check if this is agent execution
|
|
92
94
|
if ("agent" in str(self.currentAgentName).lower() or
|
|
93
95
|
(serialized and serialized.get("_type") == "agent_executor") or
|
|
@@ -124,6 +126,9 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
124
126
|
|
|
125
127
|
def on_chain_end(self, outputs: Dict[str, Any], **kwargs: Any) -> None:
|
|
126
128
|
"""Called when a chain ends"""
|
|
129
|
+
# print("ON CHAIN END: ",outputs)
|
|
130
|
+
# print("ON CHAIN END: ",kwargs)
|
|
131
|
+
|
|
127
132
|
try:
|
|
128
133
|
if self.isAgentExecution and isinstance(outputs, dict) and "output" in outputs:
|
|
129
134
|
# Use logAgentStep for final completion
|
|
@@ -147,16 +152,27 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
147
152
|
|
|
148
153
|
def on_llm_start(self, serialized: Dict[str, Any], prompts: List[Any], **kwargs: Any) -> None:
|
|
149
154
|
"""Called when LLM starts"""
|
|
155
|
+
# print("ON LLM START: ",serialized)
|
|
156
|
+
# print("ON LLM START: ", prompts)
|
|
157
|
+
# print("ON LLM START: ", kwargs)
|
|
158
|
+
try:
|
|
159
|
+
self.availableTools = kwargs["invocation_params"]["functions"]
|
|
160
|
+
except:
|
|
161
|
+
self.availableTools = []
|
|
162
|
+
|
|
163
|
+
|
|
150
164
|
self.llmStartTime = time.time()
|
|
151
165
|
self.stepTime = time.time()
|
|
152
|
-
|
|
166
|
+
# print(prompts)
|
|
153
167
|
if self.prompt == "":
|
|
154
168
|
match = re.search(r"Human:\s*(.*)",prompts[0], re.DOTALL)
|
|
169
|
+
# allPromptInstructions = " ".join(prompts)
|
|
155
170
|
if match:
|
|
156
171
|
user_question = match.group(1).strip()
|
|
157
172
|
self.prompt = user_question # 👉 What is LangChain?
|
|
158
173
|
else:
|
|
159
174
|
self.prompt = ""
|
|
175
|
+
# self.allPrompt = allPromptInstructions
|
|
160
176
|
|
|
161
177
|
# Dynamically get model info
|
|
162
178
|
model = "unknown"
|
|
@@ -244,9 +260,11 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
244
260
|
# Ensure we have string values
|
|
245
261
|
output = str(output) if output is not None else ""
|
|
246
262
|
model_name = str(model_name) if model_name is not None else "unknown"
|
|
263
|
+
self.currentInputTokens = input_tokens
|
|
247
264
|
|
|
248
265
|
# Parse ReAct reasoning from LLM output if we're in agent execution
|
|
249
266
|
if self.isAgentExecution and output:
|
|
267
|
+
# print("[AGENT EXECUTOR OUTPUT]")
|
|
250
268
|
self._parse_react_reasoning(output)
|
|
251
269
|
try:
|
|
252
270
|
self.sessionLogger.logLlmStep(
|
|
@@ -286,7 +304,7 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
286
304
|
retrieverSource = str(source),
|
|
287
305
|
topK = len(documents),
|
|
288
306
|
chunkSize = chunkSize,
|
|
289
|
-
context = [doc.page_content for doc in documents],
|
|
307
|
+
context = " ".join([doc.page_content for doc in documents]),
|
|
290
308
|
searchQuery = self.prompt if self.prompt != "" else self.searchQuery,
|
|
291
309
|
latencyMs = 120, # mock latency, replace with real timing if needed
|
|
292
310
|
status = "SUCCESS"
|
|
@@ -385,6 +403,9 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
385
403
|
# print(f"[DEBUG] Tool started: {self.currentToolName} with input: {input_str}")
|
|
386
404
|
|
|
387
405
|
def on_tool_end(self, output: Any, **kwargs: Any) -> None:
|
|
406
|
+
# print("ON TOOL END: ",output)
|
|
407
|
+
# print("ON TOOL END: ",kwargs)
|
|
408
|
+
|
|
388
409
|
"""Called when a tool completes execution"""
|
|
389
410
|
duration_ms = int((time.time() - self.toolStartTime) * 1000) if self.toolStartTime else 0
|
|
390
411
|
|
|
@@ -423,7 +444,9 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
423
444
|
def on_agent_action(self, action: AgentAction, **kwargs: Any) -> None:
|
|
424
445
|
"""Called when an agent takes an action"""
|
|
425
446
|
self.agentsSteps += 1
|
|
447
|
+
|
|
426
448
|
# print("ON AGENT ACTION: ", action)
|
|
449
|
+
# print("ON AGENT ACTION: ", kwargs)
|
|
427
450
|
|
|
428
451
|
try:
|
|
429
452
|
# Dynamically extract information from action
|
|
@@ -452,7 +475,7 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
452
475
|
agentType=self.agentType,
|
|
453
476
|
agentName=self.currentAgentName or "unknown",
|
|
454
477
|
numStepsTaken=self.agentsSteps,
|
|
455
|
-
tools=
|
|
478
|
+
tools=self.availableTools,
|
|
456
479
|
query=self.prompt,
|
|
457
480
|
status=current_status,
|
|
458
481
|
# message=f"Executing {tool_name} with input: {tool_input}. Reasoning: {reasoning_text}",
|
|
@@ -471,7 +494,7 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
471
494
|
|
|
472
495
|
def on_agent_error(self, error: Exception, **kwargs: Any) -> None:
|
|
473
496
|
"""Called when an agent encounters an error"""
|
|
474
|
-
# print("
|
|
497
|
+
# print("ON AGENT ERROR:", error)
|
|
475
498
|
self.hasErrors = True
|
|
476
499
|
self.lastError = str(error)
|
|
477
500
|
|
|
@@ -491,6 +514,8 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
491
514
|
|
|
492
515
|
def on_tool_error(self, error: Exception, **kwargs: Any) -> None:
|
|
493
516
|
"""Called when a tool encounters an error"""
|
|
517
|
+
# print("ON TOOL ERROR: ",error)
|
|
518
|
+
# print("ON TOOL ERROR: ", kwargs)
|
|
494
519
|
|
|
495
520
|
self.hasErrors = True
|
|
496
521
|
self.lastError = str(error)
|
|
@@ -517,6 +542,8 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
517
542
|
def on_chain_error(self, error: Exception, **kwargs: Any) -> None:
|
|
518
543
|
"""Called when a chain encounters an error"""
|
|
519
544
|
# print("ITS A CHAIN ERROR:", error)
|
|
545
|
+
# print("ITS A CHAIN ERROR:", kwargs)
|
|
546
|
+
|
|
520
547
|
self.hasErrors = True
|
|
521
548
|
self.lastError = str(error)
|
|
522
549
|
|
|
@@ -542,13 +569,13 @@ class LlumoCallbackHandler(BaseCallbackHandler):
|
|
|
542
569
|
stepName="Chain Execution Error",
|
|
543
570
|
model="unknown",
|
|
544
571
|
provider=self.llmProvider,
|
|
545
|
-
inputTokens=
|
|
572
|
+
inputTokens=self.currentInputTokens,
|
|
546
573
|
outputTokens=0,
|
|
547
574
|
# temperature=0.0,
|
|
548
575
|
# promptTruncated=False,
|
|
549
576
|
latencyMs=0,
|
|
550
577
|
prompt=self.prompt,
|
|
551
|
-
output=
|
|
578
|
+
output=self.lastError,
|
|
552
579
|
status="FAILURE",
|
|
553
580
|
# message=str(error),
|
|
554
581
|
)
|
llumo/client.py
CHANGED
|
@@ -43,9 +43,9 @@ createEvalUrl = "https://backend-api.llumo.ai/api/v1/create-debug-log-for-sdk"
|
|
|
43
43
|
|
|
44
44
|
class LlumoClient:
|
|
45
45
|
|
|
46
|
-
def __init__(self, api_key,
|
|
46
|
+
def __init__(self, api_key, playgroundID=None):
|
|
47
47
|
self.apiKey = api_key
|
|
48
|
-
self.playgroundID =
|
|
48
|
+
self.playgroundID = playgroundID
|
|
49
49
|
self.evalData = []
|
|
50
50
|
self.evals = []
|
|
51
51
|
self.processMapping = {}
|
|
@@ -779,7 +779,8 @@ class LlumoClient:
|
|
|
779
779
|
def debugLogs(
|
|
780
780
|
self,
|
|
781
781
|
data,
|
|
782
|
-
|
|
782
|
+
promptTemplate="",
|
|
783
|
+
systemInstructions = ""
|
|
783
784
|
|
|
784
785
|
):
|
|
785
786
|
if isinstance(data, dict):
|
|
@@ -830,15 +831,15 @@ class LlumoClient:
|
|
|
830
831
|
context = ""
|
|
831
832
|
|
|
832
833
|
# Process prompt template if provided
|
|
833
|
-
if
|
|
834
|
+
if promptTemplate:
|
|
834
835
|
# Extract template variables
|
|
835
|
-
keys = re.findall(r"{{(.*?)}}",
|
|
836
|
+
keys = re.findall(r"{{(.*?)}}", promptTemplate)
|
|
836
837
|
|
|
837
838
|
if not all([key in dataframe.columns for key in keys]):
|
|
838
839
|
raise LlumoAIError.InvalidPromptTemplate()
|
|
839
840
|
|
|
840
841
|
# Populate template and separate query/context
|
|
841
|
-
populated_template =
|
|
842
|
+
populated_template = promptTemplate
|
|
842
843
|
for key in keys:
|
|
843
844
|
value = row.get(key, "")
|
|
844
845
|
if isinstance(value, str):
|
|
@@ -908,7 +909,10 @@ class LlumoClient:
|
|
|
908
909
|
"createdAt":createdAt,
|
|
909
910
|
"columnID":rowID,
|
|
910
911
|
"rowID":columnID,
|
|
911
|
-
"latency": random.randint(1000, 1500)
|
|
912
|
+
"latency": random.randint(1000, 1500),
|
|
913
|
+
"promptTemplate":promptTemplate,
|
|
914
|
+
"systemInstructions":systemInstructions
|
|
915
|
+
|
|
912
916
|
}
|
|
913
917
|
|
|
914
918
|
allBatches.append(batch)
|
|
@@ -918,7 +922,7 @@ class LlumoClient:
|
|
|
918
922
|
|
|
919
923
|
try:
|
|
920
924
|
# print(batch)
|
|
921
|
-
response =
|
|
925
|
+
response = postForDebugLogs(record=batch,workspaceID=workspaceID)
|
|
922
926
|
|
|
923
927
|
# failure case inside response
|
|
924
928
|
if isinstance(response, dict) and str(response.get("status", "")).lower() == "false":
|
|
@@ -2078,6 +2082,115 @@ class LlumoClient:
|
|
|
2078
2082
|
definationMapping=self.definationMapping,
|
|
2079
2083
|
)
|
|
2080
2084
|
|
|
2085
|
+
def get_evaluate_multiple(
|
|
2086
|
+
self,
|
|
2087
|
+
data,
|
|
2088
|
+
evals
|
|
2089
|
+
) -> List:
|
|
2090
|
+
|
|
2091
|
+
print("Evaluating multiple data with evals:", data, evals)
|
|
2092
|
+
|
|
2093
|
+
dataID = uuid.uuid4().hex[:36]
|
|
2094
|
+
|
|
2095
|
+
self.validateApiKey()
|
|
2096
|
+
|
|
2097
|
+
if not self.workspaceID:
|
|
2098
|
+
raise LlumoAIError("Workspace ID not found after validation.")
|
|
2099
|
+
|
|
2100
|
+
payload = {
|
|
2101
|
+
"dataID": dataID,
|
|
2102
|
+
"data": data,
|
|
2103
|
+
"evals": evals,
|
|
2104
|
+
"workspaceID": self.workspaceID,
|
|
2105
|
+
"playgroundID": self.playgroundID,
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
print("payload", payload)
|
|
2109
|
+
|
|
2110
|
+
# Create evaluation
|
|
2111
|
+
requests.post(
|
|
2112
|
+
"https://backend-api.llumo.ai/api/v1/sdk/create-evaluation-Multiple",
|
|
2113
|
+
json=payload,
|
|
2114
|
+
headers={
|
|
2115
|
+
"Content-Type": "application/json",
|
|
2116
|
+
"Authorization": f"Bearer {self.apiKey}",
|
|
2117
|
+
},
|
|
2118
|
+
)
|
|
2119
|
+
|
|
2120
|
+
final_result_data = []
|
|
2121
|
+
|
|
2122
|
+
cursor = "0-0"
|
|
2123
|
+
limit = 10
|
|
2124
|
+
all_data_fetched = False
|
|
2125
|
+
|
|
2126
|
+
while not all_data_fetched:
|
|
2127
|
+
try:
|
|
2128
|
+
response = requests.get(
|
|
2129
|
+
"https://backend-api.llumo.ai/api/v1/sdk/poll",
|
|
2130
|
+
params={
|
|
2131
|
+
"cursor": cursor,
|
|
2132
|
+
"dataID": dataID,
|
|
2133
|
+
"limit": limit,
|
|
2134
|
+
},
|
|
2135
|
+
)
|
|
2136
|
+
|
|
2137
|
+
response_data = response.json()
|
|
2138
|
+
result_data = response_data.get("debugLog", {})
|
|
2139
|
+
print("resultData", result_data)
|
|
2140
|
+
|
|
2141
|
+
results = result_data.get("results", [])
|
|
2142
|
+
final_result_data.extend(results)
|
|
2143
|
+
|
|
2144
|
+
cursor = result_data.get("nextCursor")
|
|
2145
|
+
|
|
2146
|
+
if len(final_result_data) == len(data):
|
|
2147
|
+
all_data_fetched = True
|
|
2148
|
+
|
|
2149
|
+
time.sleep(10)
|
|
2150
|
+
|
|
2151
|
+
except Exception as error:
|
|
2152
|
+
print("error", error)
|
|
2153
|
+
all_data_fetched = True
|
|
2154
|
+
|
|
2155
|
+
# Shape results
|
|
2156
|
+
formatted_results = []
|
|
2157
|
+
|
|
2158
|
+
for row in final_result_data:
|
|
2159
|
+
score: Dict[str, float | None] = {}
|
|
2160
|
+
reasoning: Dict[str, str] = {}
|
|
2161
|
+
|
|
2162
|
+
for eval_name in evals:
|
|
2163
|
+
details = row.get(eval_name)
|
|
2164
|
+
|
|
2165
|
+
if isinstance(details, dict):
|
|
2166
|
+
if isinstance(details.get("value"), (int, float)):
|
|
2167
|
+
score[eval_name] = details.get("value")
|
|
2168
|
+
else:
|
|
2169
|
+
score[eval_name] = details.get("score")
|
|
2170
|
+
reasoning[eval_name] = details.get("reasoning", "")
|
|
2171
|
+
|
|
2172
|
+
elif "score" in row:
|
|
2173
|
+
score[eval_name] = (
|
|
2174
|
+
row["score"] if isinstance(row["score"], (int, float)) else None
|
|
2175
|
+
)
|
|
2176
|
+
reasoning[eval_name] = row.get("reasoning", "")
|
|
2177
|
+
else:
|
|
2178
|
+
score[eval_name] = None
|
|
2179
|
+
reasoning[eval_name] = ""
|
|
2180
|
+
|
|
2181
|
+
formatted_row = {
|
|
2182
|
+
"context": row.get("context", ""),
|
|
2183
|
+
"query": row.get("query", ""),
|
|
2184
|
+
"output": row.get("output", ""),
|
|
2185
|
+
"score": score,
|
|
2186
|
+
"reasoning": reasoning,
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
print(formatted_row)
|
|
2190
|
+
formatted_results.append(formatted_row)
|
|
2191
|
+
|
|
2192
|
+
return formatted_results
|
|
2193
|
+
|
|
2081
2194
|
|
|
2082
2195
|
class SafeDict(dict):
|
|
2083
2196
|
def __missing__(self, key):
|
llumo/helpingFuntions.py
CHANGED
|
@@ -740,7 +740,7 @@ def getCustomAnalytics(workspaceID):
|
|
|
740
740
|
|
|
741
741
|
|
|
742
742
|
|
|
743
|
-
def
|
|
743
|
+
def postForDebugLogs(record: {},workspaceID):
|
|
744
744
|
url = "https://backend-api.llumo.ai/api/v1/get-debug-log-for-upload"
|
|
745
745
|
payload = record
|
|
746
746
|
workspaceID = workspaceID
|
|
@@ -763,3 +763,74 @@ def postForListOfSteps(record: {},workspaceID):
|
|
|
763
763
|
|
|
764
764
|
except Exception as e:
|
|
765
765
|
return {"status":"False","exception": str(e)}
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
def removeLLmStep(run: dict) -> dict:
|
|
769
|
+
"""
|
|
770
|
+
Remove LLM steps that appear immediately before an AGENT step.
|
|
771
|
+
|
|
772
|
+
"""
|
|
773
|
+
|
|
774
|
+
if not run or "steps" not in run:
|
|
775
|
+
return run
|
|
776
|
+
|
|
777
|
+
steps = run["steps"]
|
|
778
|
+
indices_to_remove = set()
|
|
779
|
+
llm_stack = [] # stack of indices where stepType == "LLM"
|
|
780
|
+
|
|
781
|
+
for idx, step in enumerate(steps):
|
|
782
|
+
step_type = step.get("stepType")
|
|
783
|
+
|
|
784
|
+
if step_type == "LLM":
|
|
785
|
+
llm_stack.append(idx)
|
|
786
|
+
|
|
787
|
+
elif step_type == "AGENT":
|
|
788
|
+
if llm_stack:
|
|
789
|
+
last_llm_idx = llm_stack[-1]
|
|
790
|
+
|
|
791
|
+
# ✅ Only remove if LLM is immediately before AGENT
|
|
792
|
+
if last_llm_idx == idx - 1:
|
|
793
|
+
indices_to_remove.add(last_llm_idx)
|
|
794
|
+
llm_stack.pop() # matched, so pop
|
|
795
|
+
|
|
796
|
+
# Rebuild steps excluding removed indices
|
|
797
|
+
cleaned_steps = [
|
|
798
|
+
step for i, step in enumerate(steps)
|
|
799
|
+
if i not in indices_to_remove
|
|
800
|
+
]
|
|
801
|
+
|
|
802
|
+
run["steps"] = cleaned_steps
|
|
803
|
+
return run
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
def addSelectedTools(run: dict) -> dict:
|
|
807
|
+
"""
|
|
808
|
+
Populate metadata.toolSelected in AGENT steps based on TOOL executions.
|
|
809
|
+
"""
|
|
810
|
+
|
|
811
|
+
if not run or "steps" not in run:
|
|
812
|
+
return run
|
|
813
|
+
|
|
814
|
+
steps = run["steps"]
|
|
815
|
+
current_agent_step = None
|
|
816
|
+
|
|
817
|
+
for step in steps:
|
|
818
|
+
step_type = step.get("stepType")
|
|
819
|
+
|
|
820
|
+
# Track the most recent AGENT step
|
|
821
|
+
if step_type == "AGENT":
|
|
822
|
+
current_agent_step = step
|
|
823
|
+
|
|
824
|
+
# Ensure toolSelected exists
|
|
825
|
+
metadata = current_agent_step.get("metadata", {})
|
|
826
|
+
metadata.setdefault("toolSelected", [])
|
|
827
|
+
current_agent_step["metadata"] = metadata
|
|
828
|
+
|
|
829
|
+
# When TOOL is executed, attach it to last AGENT
|
|
830
|
+
elif step_type == "TOOL" and current_agent_step:
|
|
831
|
+
tool_name = step.get("metadata", {}).get("toolName")
|
|
832
|
+
|
|
833
|
+
if tool_name:
|
|
834
|
+
current_agent_step["metadata"]["toolSelected"].append(tool_name)
|
|
835
|
+
|
|
836
|
+
return run
|
llumo/llumoLogger.py
CHANGED
llumo/llumoSessionContext.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import contextvars
|
|
2
3
|
import uuid
|
|
3
4
|
from typing import Optional, List, Dict, Any
|
|
@@ -6,7 +7,8 @@ import requests
|
|
|
6
7
|
from .client import LlumoClient
|
|
7
8
|
import math
|
|
8
9
|
import base64
|
|
9
|
-
|
|
10
|
+
from .helpingFuntions import removeLLmStep
|
|
11
|
+
from .helpingFuntions import addSelectedTools
|
|
10
12
|
import random
|
|
11
13
|
|
|
12
14
|
_ctxLogger = contextvars.ContextVar("ctxLogger")
|
|
@@ -28,14 +30,14 @@ def getLlumoRun():
|
|
|
28
30
|
|
|
29
31
|
class LlumoSessionContext(LlumoClient):
|
|
30
32
|
def __init__(self, logger, sessionID: Optional[str] = None):
|
|
31
|
-
super().__init__(api_key=logger.apiKey,
|
|
33
|
+
super().__init__(api_key=logger.apiKey, playgroundID=logger.getPlaygroundID())
|
|
32
34
|
self.sessionID = sessionID or str(uuid.uuid4().hex[:14])
|
|
33
35
|
self.logger = logger
|
|
34
36
|
self.apiKey = logger.apiKey
|
|
35
37
|
self.threadLogger = None
|
|
36
38
|
self.threadSessionID = None
|
|
37
39
|
self.threadLlumoRun = None
|
|
38
|
-
|
|
40
|
+
|
|
39
41
|
|
|
40
42
|
def start(self):
|
|
41
43
|
self.threadLogger = _ctxLogger.set(self.logger)
|
|
@@ -57,9 +59,9 @@ class LlumoSessionContext(LlumoClient):
|
|
|
57
59
|
self.end()
|
|
58
60
|
|
|
59
61
|
|
|
60
|
-
def startLlumoRun(self, runName: str, rowID: str = "", columnID: str = "", runID: str = None):
|
|
62
|
+
def startLlumoRun(self, runName: str,promptTemplate:str = "",systemInstructions:str = "", rowID: str = "", columnID: str = "", runID: str = None):
|
|
61
63
|
|
|
62
|
-
if runID ==
|
|
64
|
+
if runID == None:
|
|
63
65
|
LlumoRunID = str(uuid.uuid4().hex[:16])
|
|
64
66
|
else:
|
|
65
67
|
LlumoRunID = runID
|
|
@@ -82,7 +84,7 @@ class LlumoSessionContext(LlumoClient):
|
|
|
82
84
|
"sessionID": self.sessionID,
|
|
83
85
|
"playgroundID": self.logger.getPlaygroundID(),
|
|
84
86
|
"workspaceID": self.logger.getWorkspaceID(),
|
|
85
|
-
"source": "SDK_LANGCHAIN" if self.isLangchain else "SDK_OTHERS",
|
|
87
|
+
"source": "SDK_LANGCHAIN" if self.logger.isLangchain else "SDK_OTHERS",
|
|
86
88
|
"rowID": rowID,
|
|
87
89
|
"columnID": columnID,
|
|
88
90
|
"email": self.logger.getUserEmailID(),
|
|
@@ -100,8 +102,9 @@ class LlumoSessionContext(LlumoClient):
|
|
|
100
102
|
"totalTokens": "",
|
|
101
103
|
"cost": "",
|
|
102
104
|
"modelsUsed": "gpt-4o",
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
},
|
|
106
|
+
"promptTemplate":promptTemplate,
|
|
107
|
+
"systemInstructions":systemInstructions
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
self.threadLlumoRun = _ctxLlumoRun.set(llumoRun)
|
|
@@ -169,8 +172,15 @@ class LlumoSessionContext(LlumoClient):
|
|
|
169
172
|
|
|
170
173
|
try:
|
|
171
174
|
# print("[PAYLOAD]: ",run)
|
|
172
|
-
|
|
175
|
+
|
|
176
|
+
payload = removeLLmStep(run)
|
|
177
|
+
# print("*******PAYLOAD AFTER removeLLmStep*******: ", payload)
|
|
178
|
+
|
|
179
|
+
payload = addSelectedTools(payload)
|
|
180
|
+
# print("********PAYLOAD AFTER addSelectedTools*********: ", payload)
|
|
181
|
+
|
|
173
182
|
response = requests.post(url, headers=headers, json=payload, timeout=20)
|
|
183
|
+
|
|
174
184
|
response.raise_for_status()
|
|
175
185
|
# print("[PAYLOAD]: ",response.json())
|
|
176
186
|
|
|
@@ -293,7 +303,7 @@ class LlumoSessionContext(LlumoClient):
|
|
|
293
303
|
"retrieverSource": retrieverSource,
|
|
294
304
|
"topK": topK,
|
|
295
305
|
"chunkSize":chunkSize,
|
|
296
|
-
"context": context,
|
|
306
|
+
"context": " ".join(context),
|
|
297
307
|
"searchQuery": searchQuery,
|
|
298
308
|
"latencyMs": latencyMs,
|
|
299
309
|
"status": status,
|
|
@@ -318,6 +328,7 @@ class LlumoSessionContext(LlumoClient):
|
|
|
318
328
|
"agentName": agentName,
|
|
319
329
|
"numStepsTaken": numStepsTaken,
|
|
320
330
|
"tools": tools,
|
|
331
|
+
"toolSelected":[],
|
|
321
332
|
"query": query,
|
|
322
333
|
"status": status,
|
|
323
334
|
# "message": message,
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
llumo/__init__.py,sha256=kkuppu7ZPiVZFdnYzJ9BM3syMbYHOSZLpwKwAvGHsnY,311
|
|
2
|
-
llumo/callback.py,sha256=
|
|
2
|
+
llumo/callback.py,sha256=XQbImLnd64_B2Iir-FCaJcL5Kmpm3RlXJH2zDRXk_yk,25135
|
|
3
3
|
llumo/callbacks-0.py,sha256=TEIOCWRvk2UYsTmBMBsnlgpqWvr-2y3a6d0w_e96NRM,8958
|
|
4
4
|
llumo/chains.py,sha256=6lCgLseh04RUgc6SahhmvQj82quay2Mi1j8gPUlx8Es,2923
|
|
5
|
-
llumo/client.py,sha256=
|
|
5
|
+
llumo/client.py,sha256=YTNdvtv03BVDNHeLypHQadDN2PpXsyOk0dM8hc7P-Ts,83205
|
|
6
6
|
llumo/exceptions.py,sha256=1OyhN9YL9LcyUPUsqYHq6Rret0udATZAwMVJaio2_Ec,2123
|
|
7
7
|
llumo/execution.py,sha256=nWbJ7AvWuUPcOb6i-JzKRna_PvF-ewZTiK8skS-5n3w,1380
|
|
8
8
|
llumo/functionCalling.py,sha256=D5jYapu1rIvdIJNUYPYMTyhQ1H-6nkwoOLMi6eekfUE,7241
|
|
9
9
|
llumo/google.py,sha256=6y9YnDFDRHv6-sQNT5LIsV9p31BCN0B9eow5KTRBWfM,2185
|
|
10
|
-
llumo/helpingFuntions.py,sha256=
|
|
11
|
-
llumo/llumoLogger.py,sha256=
|
|
12
|
-
llumo/llumoSessionContext.py,sha256=
|
|
10
|
+
llumo/helpingFuntions.py,sha256=eMR2Rq8vw4X5sIESOvjOBrEvyYE00Eq7XlQjV66eVcg,29977
|
|
11
|
+
llumo/llumoLogger.py,sha256=ALM4461jItWcvYL9HzTGmB-X-M77YF_9PTeTPxtmP_E,2223
|
|
12
|
+
llumo/llumoSessionContext.py,sha256=XA2SIXKh62NRz1qxkvhpo7ziOhushG2CkJgjUWlmvFw,14880
|
|
13
13
|
llumo/models.py,sha256=aVEZsOOoQx5LeNtwSyBxqvrINq0izH3QWu_YjsMPE6o,2910
|
|
14
14
|
llumo/openai.py,sha256=VstBzaORe8Tq0feUIIEszzcN1oq6TJfkPviaCr5d3Bw,8950
|
|
15
15
|
llumo/sockets.py,sha256=pfWz1zTEiwqJhdbSy3i3_Y4WlIdJ3cuac11wMePeBS0,6130
|
|
16
|
-
llumo-0.2.
|
|
17
|
-
llumo-0.2.
|
|
18
|
-
llumo-0.2.
|
|
19
|
-
llumo-0.2.
|
|
20
|
-
llumo-0.2.
|
|
16
|
+
llumo-0.2.41.dist-info/licenses/LICENSE,sha256=tF9yAcfPV9xGT3ViWmC8hPvOo8BEk4ZICbUfcEo8Dlk,182
|
|
17
|
+
llumo-0.2.41.dist-info/METADATA,sha256=pamF6aPT4DF9NO1361IN4dcJ63O2YUCxdeMPPut2bd0,1662
|
|
18
|
+
llumo-0.2.41.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
llumo-0.2.41.dist-info/top_level.txt,sha256=d5zUTMI99llPtLRB8rtSrqELm_bOqX-bNC5IcwlDk88,6
|
|
20
|
+
llumo-0.2.41.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|