sunholo 0.89.1__py3-none-any.whl → 0.89.2__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.
@@ -20,6 +20,12 @@ from .langserve import prepare_request_data
20
20
 
21
21
  from .route import route_endpoint
22
22
 
23
+ try:
24
+ from langfuse import Langfuse
25
+ langfuse = Langfuse()
26
+ except ImportError:
27
+ langfuse = None
28
+
23
29
  def prep_request_payload(user_input, chat_history, vector_name, stream, **kwargs):
24
30
  """
25
31
  Prepares the request payload for sending a query to the QA system.
@@ -79,9 +85,21 @@ def prep_request_payload(user_input, chat_history, vector_name, stream, **kwargs
79
85
 
80
86
  if 'vector_name' not in qna_data:
81
87
  qna_data['vector_name'] = vector_name
88
+
89
+ qna_data['trace_id'] = add_langfuse_trace(qna_endpoint)
82
90
 
83
91
  return qna_endpoint, qna_data
84
92
 
93
+ def add_langfuse_trace(qna_endpoint):
94
+ if not langfuse:
95
+ return None
96
+
97
+ trace = langfuse.trace(name = f'auto/{qna_endpoint}')
98
+
99
+ log.info('Adding langfuse trace {trace.id}')
100
+
101
+ return trace.id
102
+
85
103
  def send_to_qa(user_input, vector_name, chat_history, stream=False, **kwargs):
86
104
  """
87
105
  Sends a query to the QA system synchronously.
@@ -161,7 +161,7 @@ if __name__ == "__main__":
161
161
 
162
162
 
163
163
  def handle_stream_vac(self, vector_name):
164
- observed_stream_interpreter = observe()(self.stream_interpreter)
164
+ observed_stream_interpreter = self.stream_interpreter
165
165
  prep = self.prep_vac(request, vector_name)
166
166
  log.info(f"Processing prep: {prep}")
167
167
  trace = prep["trace"]
@@ -225,7 +225,7 @@ if __name__ == "__main__":
225
225
  return response
226
226
 
227
227
  def handle_process_vac(self, vector_name):
228
- observed_vac_interpreter = observe()(self.vac_interpreter)
228
+ observed_vac_interpreter = self.vac_interpreter
229
229
  prep = self.prep_vac(request, vector_name)
230
230
  log.debug(f"Processing prep: {prep}")
231
231
  trace = prep["trace"]
@@ -365,7 +365,7 @@ if __name__ == "__main__":
365
365
  "kwargs": data
366
366
  }
367
367
 
368
- observed_stream_interpreter = observe()(self.stream_interpreter)
368
+ observed_stream_interpreter = self.stream_interpreter
369
369
 
370
370
  response_id = str(uuid.uuid4())
371
371
 
@@ -416,7 +416,7 @@ if __name__ == "__main__":
416
416
  return Response(generate_response_content(), content_type='text/plain; charset=utf-8')
417
417
 
418
418
  try:
419
- observed_vac_interpreter = observe()(self.vac_interpreter)
419
+ observed_vac_interpreter = self.vac_interpreter
420
420
  bot_output = observed_vac_interpreter(
421
421
  question=user_message,
422
422
  vector_name=vector_name,
@@ -437,7 +437,7 @@ if __name__ == "__main__":
437
437
  return self.make_openai_response(user_message, vector_name, f'ERROR: {str(err)}')
438
438
 
439
439
 
440
- def create_langfuse_trace(self, request, vector_name):
440
+ def create_langfuse_trace(self, request, vector_name, trace_id):
441
441
  try:
442
442
  from langfuse import Langfuse
443
443
  langfuse = Langfuse()
@@ -451,11 +451,12 @@ if __name__ == "__main__":
451
451
  message_source = request.headers.get("X-Message-Source")
452
452
 
453
453
  package_version = sunholo_version()
454
- tags = [package_version]
454
+ tags = [package_version, "autogenerated"]
455
455
  if message_source:
456
456
  tags.append(message_source)
457
457
 
458
458
  return langfuse.trace(
459
+ id=trace_id,
459
460
  name = f"/vac/{vector_name}",
460
461
  user_id = user_id,
461
462
  session_id = session_id,
@@ -464,8 +465,6 @@ if __name__ == "__main__":
464
465
  )
465
466
 
466
467
  def prep_vac(self, request, vector_name):
467
- trace = self.create_langfuse_trace(request, vector_name)
468
- span = None
469
468
 
470
469
  if request.content_type.startswith('application/json'):
471
470
  data = request.get_json()
@@ -490,6 +489,10 @@ if __name__ == "__main__":
490
489
 
491
490
  log.info(f"vac/{vector_name} got data: {data}")
492
491
 
492
+ trace_id = data.get('trace_id')
493
+ trace = self.create_langfuse_trace(request, vector_name, trace_id)
494
+ span = None
495
+
493
496
  config, _ = load_config("config/llm_config.yaml")
494
497
  vac_configs = config.get("vac")
495
498
  if vac_configs:
sunholo/langfuse/evals.py CHANGED
@@ -29,15 +29,26 @@ def pubsub_to_evals(data: dict, eval_funcs: list=[eval_length]) -> dict:
29
29
 
30
30
  if 'trace_id' not in message_data:
31
31
  raise ValueError('No trace_id found in message data')
32
+
33
+ trace_id = message_data.pop('trace_id', None)
34
+
35
+ return do_evals(trace_id, eval_funcs, **message_data)
36
+
37
+
38
+ def direct_langfuse_evals(data, eval_funcs: list=[eval_length]):
39
+ if 'trace_id' not in data:
40
+ raise ValueError('No trace_id found in data')
32
41
 
42
+ return do_evals(data['trace_id'], eval_funcs, **data)
43
+
44
+
45
+ def do_evals(trace_id, eval_funcs: list=[eval_length], **kwargs) -> dict:
33
46
  # Initialize Langfuse with environment variables
34
47
  langfuse = Langfuse(
35
48
  secret_key=os.environ["LANGFUSE_SECRET_KEY"],
36
49
  public_key=os.environ["LANGFUSE_PUBLIC_KEY"],
37
50
  host=os.environ["LANGFUSE_HOST"]
38
51
  )
39
-
40
- trace_id = message_data.pop('trace_id', None)
41
52
 
42
53
  # Fetch the latest trace (or modify as needed to fetch a specific trace)
43
54
  trace = langfuse.fetch_trace(id=trace_id)
@@ -64,7 +75,7 @@ def pubsub_to_evals(data: dict, eval_funcs: list=[eval_length]) -> dict:
64
75
  name=eval_name, # Use the function name as the evaluation name
65
76
  value=eval_result["score"],
66
77
  comment=eval_result["reason"],
67
- **message_data
78
+ **kwargs
68
79
  )
69
80
 
70
81
  return {"trace_id": trace.id, "eval_results": eval_results}
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sunholo
3
- Version: 0.89.1
3
+ Version: 0.89.2
4
4
  Summary: Large Language Model DevOps - a package to help deploy LLMs to the Cloud.
5
5
  Home-page: https://github.com/sunholo-data/sunholo-py
6
- Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.89.1.tar.gz
6
+ Download-URL: https://github.com/sunholo-data/sunholo-py/archive/refs/tags/v0.89.2.tar.gz
7
7
  Author: Holosun ApS
8
8
  Author-email: multivac@sunholo.com
9
9
  License: Apache License, Version 2.0
@@ -2,7 +2,7 @@ sunholo/__init__.py,sha256=lLuVyilzmDbTaiAptR8SZzpbUNsgwHFsp4Ejbr5EApI,1136
2
2
  sunholo/custom_logging.py,sha256=YfIN1oP3dOEkkYkyRBU8BGS3uJFGwUDsFCl8mIVbwvE,12225
3
3
  sunholo/agents/__init__.py,sha256=X2I3pPkGeKWjc3d0QgSpkTyqD8J8JtrEWqwrumf1MMc,391
4
4
  sunholo/agents/chat_history.py,sha256=Gph_CdlP2otYnNdR1q1Umyyyvcad2F6K3LxU5yBQ9l0,5387
5
- sunholo/agents/dispatch_to_qa.py,sha256=49-10UGxwcqA65Lm-S2ofTBaDHZLRZgSWy-Jj8OwKHs,8381
5
+ sunholo/agents/dispatch_to_qa.py,sha256=Z2q0ygYxfgBr-EGydq_H5y4Y-bKlY4ZCBCwkGpYwjFY,8766
6
6
  sunholo/agents/langserve.py,sha256=C46ph2mnygr6bdHijYWYyfQDI9ylAF0_9Kx2PfcCJpU,4414
7
7
  sunholo/agents/pubsub.py,sha256=TscZN_6am6DfaQkC-Yl18ZIBOoLE-0nDSiil6GpQEh4,1344
8
8
  sunholo/agents/route.py,sha256=Mo-YOHDsHOiQXfb6VmCH0BPThAD-0jZGIkIKAHxSDdc,2986
@@ -14,7 +14,7 @@ sunholo/agents/fastapi/qna_routes.py,sha256=lKHkXPmwltu9EH3RMwmD153-J6pE7kWQ4BhB
14
14
  sunholo/agents/flask/__init__.py,sha256=poJDKMr2qj8qMb99JqCvCPSiEt1tj2tLQ3hKW3f2aVw,107
15
15
  sunholo/agents/flask/base.py,sha256=FgSaCODyoTtlstJtsqlLPScdgRUtv9_plxftdzHdVFo,809
16
16
  sunholo/agents/flask/qna_routes.py,sha256=uwUD1yrzOPH27m2AXpiQrPk_2VfJOQOM6dAynOWQtoQ,22532
17
- sunholo/agents/flask/vac_routes.py,sha256=aZ69r4V5s5EHzJ8Tht0KTuEiHrSPHFiwF8XYPOA_7Q0,21034
17
+ sunholo/agents/flask/vac_routes.py,sha256=e8miEz997ELiMJlOdTZesi40E0E2sNA_lz3cEU77e2M,21094
18
18
  sunholo/archive/__init__.py,sha256=qNHWm5rGPVOlxZBZCpA1wTYPbalizRT7f8X4rs2t290,31
19
19
  sunholo/archive/archive.py,sha256=PxVfDtO2_2ZEEbnhXSCbXLdeoHoQVImo4y3Jr2XkCFY,1204
20
20
  sunholo/auth/__init__.py,sha256=TeP-OY0XGxYV_8AQcVGoh35bvyWhNUcMRfhuD5l44Sk,91
@@ -94,7 +94,7 @@ sunholo/invoke/direct_vac_func.py,sha256=fuTJlH5PsqWhN_yVMaWisHCTZU1JEUz8I8yVbWs
94
94
  sunholo/invoke/invoke_vac_utils.py,sha256=sJc1edHTHMzMGXjji1N67c3iUaP7BmAL5nj82Qof63M,2053
95
95
  sunholo/langfuse/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
96
  sunholo/langfuse/callback.py,sha256=jl0SZsFS53uMW9DGeM9SOL_EsRZsba0wwFGLqKzu9_U,1684
97
- sunholo/langfuse/evals.py,sha256=wtaiv3WftElmg5_6U1eEGbjXXWxypG7D4MbJR_RHMCk,2541
97
+ sunholo/langfuse/evals.py,sha256=jGST6yNrgiH8hbXTGWNpu0dopcWHkYPMf1HLhB40gE4,2880
98
98
  sunholo/langfuse/prompts.py,sha256=27BsVfihM6-h1jscbkGSO4HsATl-d4ZN6tcNCVztWoY,1300
99
99
  sunholo/llamaindex/__init__.py,sha256=DlY_cHWCsVEV1C5WBgDdHRgOMlJc8pDoCRukUJ8PT9w,88
100
100
  sunholo/llamaindex/get_files.py,sha256=6rhXCDqQ_lrIapISQ_OYQDjiSATXvS_9m3qq53-oIl0,781
@@ -144,9 +144,9 @@ sunholo/vertex/init.py,sha256=1OQwcPBKZYBTDPdyU7IM4X4OmiXLdsNV30C-fee2scQ,2875
144
144
  sunholo/vertex/memory_tools.py,sha256=q_phxgGX2TG2j2MXNULF2xGzQnQPENwjPN9nZ_A9Gh0,7526
145
145
  sunholo/vertex/safety.py,sha256=S9PgQT1O_BQAkcqauWncRJaydiP8Q_Jzmu9gxYfy1VA,2482
146
146
  sunholo/vertex/type_dict_to_json.py,sha256=uTzL4o9tJRao4u-gJOFcACgWGkBOtqACmb6ihvCErL8,4694
147
- sunholo-0.89.1.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
148
- sunholo-0.89.1.dist-info/METADATA,sha256=NwC2gl87pDNb54mwk-5c-5g6X4ip9NN9q-Ca6yZXxZA,7706
149
- sunholo-0.89.1.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
150
- sunholo-0.89.1.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
151
- sunholo-0.89.1.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
152
- sunholo-0.89.1.dist-info/RECORD,,
147
+ sunholo-0.89.2.dist-info/LICENSE.txt,sha256=SdE3QjnD3GEmqqg9EX3TM9f7WmtOzqS1KJve8rhbYmU,11345
148
+ sunholo-0.89.2.dist-info/METADATA,sha256=aXFfl6kKHO1A9B6-PtLMl7TKme8xRT5S57ZJQ4Euac4,7706
149
+ sunholo-0.89.2.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
150
+ sunholo-0.89.2.dist-info/entry_points.txt,sha256=bZuN5AIHingMPt4Ro1b_T-FnQvZ3teBes-3OyO0asl4,49
151
+ sunholo-0.89.2.dist-info/top_level.txt,sha256=wt5tadn5--5JrZsjJz2LceoUvcrIvxjHJe-RxuudxAk,8
152
+ sunholo-0.89.2.dist-info/RECORD,,