olca 0.2.58__py3-none-any.whl → 0.2.60__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
olca/fusewill_cli.py CHANGED
@@ -14,7 +14,9 @@ from fusewill_utils import (
14
14
  open_trace_in_browser,
15
15
  print_traces,
16
16
  print_trace,
17
- list_traces_by_score # Ensure the updated function is imported
17
+ list_traces_by_score, # Ensure the updated function is imported
18
+ export_traces,
19
+ import_traces
18
20
  )
19
21
  import dotenv
20
22
  import json
@@ -106,6 +108,18 @@ def main():
106
108
  parser_search.add_argument('-L', '--limit', type=int, default=100, help='Number of traces to fetch')
107
109
  parser_search.add_argument('-o', '--output', type=str, help='Output JSON file path')
108
110
 
111
+ # export_traces command
112
+ parser_export = subparsers.add_parser('export_traces', help='Export traces', aliases=['et'])
113
+ parser_export.add_argument('--format', choices=['json','csv'], default='json', help='Export format')
114
+ parser_export.add_argument('-o','--output', type=str, help='Output file path')
115
+ parser_export.add_argument('--start_date', type=str, help='Start date in ISO format (e.g., 2024-01-01)')
116
+ parser_export.add_argument('--end_date', type=str, help='End date in ISO format (e.g., 2024-12-31)')
117
+
118
+ # import_traces command
119
+ parser_import = subparsers.add_parser('import_traces', help='Import traces', aliases=['it'])
120
+ parser_import.add_argument('--format', choices=['json','csv'], default='json', help='Import format')
121
+ parser_import.add_argument('--input', type=str, required=True, help='Input file path to read from')
122
+
109
123
  args = parser.parse_args()
110
124
 
111
125
  if args.command == 'list_traces' or args.command == 'lt':
@@ -210,7 +224,7 @@ def main():
210
224
  if args.output:
211
225
  try:
212
226
  with open(args.output, 'w') as f:
213
- json.dump([trace.__dict__ for trace in traces], f, indent=2)
227
+ json.dump([trace.__dict__ for trace in traces], f, indent=2, default=str)
214
228
  print(f"Traces written to {os.path.realpath(args.output)}")
215
229
  except Exception as e:
216
230
  print(f"Error writing to file {args.output}: {e}")
@@ -219,6 +233,14 @@ def main():
219
233
  fu.print_trace(trace)
220
234
  else:
221
235
  print("No traces found matching the criteria.")
236
+ elif args.command == 'export_traces' or args.command == 'et':
237
+ output_path = args.output
238
+ if output_path:
239
+ if not output_path.endswith(f".{args.format}"):
240
+ output_path += f".{args.format}"
241
+ fu.export_traces(format=args.format, output_path=output_path, start_date=args.start_date, end_date=args.end_date)
242
+ elif args.command == 'import_traces' or args.command == 'it':
243
+ fu.import_traces(format=args.format, input_path=args.input)
222
244
  else:
223
245
  parser.print_help()
224
246
  exit(1)
olca/fusewill_utils.py CHANGED
@@ -8,11 +8,11 @@ import datetime # Add this import
8
8
  import pytz # Add this import
9
9
 
10
10
  # Load .env from the current working directory
11
- dotenv.load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
11
+ dotenv.load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"), override=True)
12
12
 
13
13
  # Try loading from home directory if variables are still not set
14
14
  if not os.environ.get("LANGFUSE_PUBLIC_KEY") or not os.environ.get("LANGFUSE_SECRET_KEY") or not os.environ.get("LANGFUSE_HOST"):
15
- dotenv.load_dotenv(dotenv_path=os.path.expanduser("~/.env"))
15
+ dotenv.load_dotenv(dotenv_path=os.path.expanduser("~/.env"), override=True)
16
16
 
17
17
  # Final check before exiting
18
18
  missing_vars = []
@@ -33,7 +33,6 @@ import sys
33
33
  sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
34
34
  import json
35
35
 
36
- import dotenv
37
36
  _DEBUG_=False
38
37
  if _DEBUG_:
39
38
  print(os.environ.get("LANGFUSE_PUBLIC_KEY"))
@@ -43,7 +42,8 @@ if _DEBUG_:
43
42
  langfuse = Langfuse(
44
43
  public_key=os.environ.get("LANGFUSE_PUBLIC_KEY"),
45
44
  secret_key=os.environ.get("LANGFUSE_SECRET_KEY"),
46
- host=os.environ.get("LANGFUSE_HOST")
45
+ host=os.environ.get("LANGFUSE_HOST"),
46
+ release=os.environ.get("LANGFUSE_RELEASE", None)
47
47
  )
48
48
 
49
49
  def open_trace_in_browser(trace_id):
@@ -241,4 +241,100 @@ def search_traces(
241
241
  return filtered_traces
242
242
  except Exception as e:
243
243
  print(f"Error searching traces: {e}")
244
- return []
244
+ return []
245
+
246
+ def fetch_all_traces(start_date=None, end_date=None):
247
+ all_traces = []
248
+ page = 1
249
+ chunk_size = 100
250
+ params = {}
251
+ if start_date:
252
+ params['from_timestamp'] = datetime.datetime.fromisoformat(start_date).replace(tzinfo=pytz.UTC)
253
+ if end_date:
254
+ params['to_timestamp'] = datetime.datetime.fromisoformat(end_date).replace(tzinfo=pytz.UTC)
255
+
256
+ while True:
257
+ partial = langfuse.get_traces(limit=chunk_size, page=page, **params)
258
+ if not partial or not partial.data:
259
+ break
260
+ all_traces.extend(partial.data)
261
+ if len(partial.data) < chunk_size:
262
+ break
263
+ page += 1
264
+ return all_traces
265
+
266
+ def export_traces(format='json', output_path=None, start_date=None, end_date=None):
267
+ """
268
+ Export traces to a given format (json or csv).
269
+ """
270
+ try:
271
+ all_traces = fetch_all_traces(start_date=start_date, end_date=end_date)
272
+ if not output_path:
273
+ output_path = f"./traces_export.{format}"
274
+
275
+ # Ensure the output directory exists
276
+ output_dir = os.path.dirname(output_path)
277
+ if output_dir and not os.path.exists(output_dir):
278
+ os.makedirs(output_dir)
279
+
280
+ if format == 'json':
281
+ with open(output_path, 'w') as f:
282
+ json.dump([t.__dict__ for t in all_traces], f, indent=2, default=str)
283
+ elif format == 'csv':
284
+ import csv
285
+ fieldnames = ['id', 'name', 'input', 'output', 'createdAt']
286
+ with open(output_path, 'w', newline='') as f:
287
+ writer = csv.DictWriter(f, fieldnames=fieldnames)
288
+ writer.writeheader()
289
+ for t in all_traces:
290
+ writer.writerow({
291
+ 'id': t.id,
292
+ 'name': t.name,
293
+ 'input': t.input,
294
+ 'output': t.output,
295
+ 'createdAt': str(t.createdAt)
296
+ })
297
+
298
+ if all_traces:
299
+ # Sort traces by createdAt to ensure the oldest date is first
300
+ all_traces.sort(key=lambda x: x.createdAt)
301
+ first_trace_date = datetime.datetime.fromisoformat(all_traces[0].createdAt.replace('Z', '+00:00')).strftime('%Y-%m-%d %H:%M:%S')
302
+ last_trace_date = datetime.datetime.fromisoformat(all_traces[-1].createdAt.replace('Z', '+00:00')).strftime('%Y-%m-%d %H:%M:%S')
303
+ print(f"Traces exported to {output_path}. Total traces exported: {len(all_traces)}")
304
+ print(f"Date range: {first_trace_date} to {last_trace_date}")
305
+ else:
306
+ print(f"Traces exported to {output_path}. Total traces exported: {len(all_traces)}")
307
+ except Exception as e:
308
+ print(f"Error exporting traces: {e}")
309
+
310
+ def import_traces(format='json', input_path=None):
311
+ """
312
+ Import traces from a given file (json or csv) into Langfuse.
313
+ """
314
+ if not input_path:
315
+ print("No input file provided for importing traces.")
316
+ return
317
+
318
+ try:
319
+ if format == 'json':
320
+ with open(input_path, 'r') as f:
321
+ data = json.load(f)
322
+ elif format == 'csv':
323
+ import csv
324
+ data = []
325
+ with open(input_path, 'r', newline='') as f:
326
+ reader = csv.DictReader(f)
327
+ for row in reader:
328
+ data.append(row)
329
+
330
+ # Create new traces in Langfuse from data
331
+ for item in data:
332
+ langfuse.create_trace(
333
+ name=item.get('name', 'Imported Trace'),
334
+ input=item.get('input', ''),
335
+ output=item.get('output', '')
336
+ # pass other fields as needed
337
+ )
338
+ print(f"Imported {len(data)} traces from {input_path}")
339
+ except Exception as e:
340
+ print(f"Error importing traces: {e}")
olca/prompts.py CHANGED
@@ -1,5 +1,8 @@
1
1
  # Create a new file "prompts.py" to store the prompt-related constants.
2
2
 
3
+
4
+ #@STCGoal https://smith.langchain.com/hub/jgwill/olca_system_append
5
+ SYSTEM_PROMPT_APPEND_hub_tag_name="jgwill/olca_system_append"
3
6
  SYSTEM_PROMPT_APPEND = """
4
7
  You do what is above and consider the following when doing the task:
5
8
  ---
@@ -22,6 +25,8 @@ You do what is above and consider the following when doing the task:
22
25
  REMEMBER: Dont introduce nor conclude, just output results. No comments. you present in a coherent format without preambles or fluff. Never use the word "determination" and we never brainstorm (we conceptualize the result we want in the germination phase then transform it into vision by choice and work as assimilating the vision to until the last phase which is completing our work).
23
26
  """
24
27
 
28
+ #@STCGoal https://smith.langchain.com/hub/jgwill/olca_human_append
29
+ HUMAN_APPEND_PROMPT_hub_tag_name="jgwill/olca_human_append"
25
30
  HUMAN_APPEND_PROMPT = """
26
31
  * Utilize the 'human' tool for interactions as directed.
27
32
  * Communicate clearly and simply, avoiding exaggeration.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: olca
3
- Version: 0.2.58
3
+ Version: 0.2.60
4
4
  Summary: A Python package for experimental usage of Langchain and Human-in-the-Loop
5
5
  Home-page: https://github.com/jgwill/olca
6
6
  Author: Jean GUillaume ISabelle
@@ -0,0 +1,14 @@
1
+ olca/__init__.py,sha256=3QyLLAys_KiiDIe-cfO_7QyY7di_qCaCS-sVziW2BOw,23
2
+ olca/fusewill_cli.py,sha256=muFBmWm1HPWrcpEGLEH4YMInEw9fIrWxb1aO5yr07n8,12156
3
+ olca/fusewill_utils.py,sha256=BnNovYOzfNodhO-CoJYTX2uNonFeV1e88YwZYO1B-UM,12487
4
+ olca/olcacli.py,sha256=NGYxZw_kYI9y9DmXu5dk02S_UOqVw05FWlzQ2gjXv00,10214
5
+ olca/olcahelper.py,sha256=WdN6-K-N7-HnB9L_px6TsDKWiTXIusZM2I1d0GNQnFs,3322
6
+ olca/prompts.py,sha256=q7lvDZ8n_K6ea2nu3K5R2fgBgQYrCIEjh0cA9fUlMFI,3697
7
+ olca/tracing.py,sha256=GSuXIKmIMQ9V2gLkKcin142Z2QpyS6obsnj8Tf-1zHc,1621
8
+ olca/utils.py,sha256=zM94HDMDYF95Yd9ubeOK6vuepbQN4kDFh0rTvaVFagI,912
9
+ olca-0.2.60.dist-info/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
10
+ olca-0.2.60.dist-info/METADATA,sha256=lBFrltW-p-YUMASGo12IOTjPJ1XLD2ulRRG_NNx2vH0,25331
11
+ olca-0.2.60.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
12
+ olca-0.2.60.dist-info/entry_points.txt,sha256=AhP5FMv6vnOq9C76V_vxRVIO50smnZXG4RIY47oD2_U,103
13
+ olca-0.2.60.dist-info/top_level.txt,sha256=bGDtAReS-xlS0F6MM-DyD0IQUqjNdWmgemnM3vNtrpI,5
14
+ olca-0.2.60.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- olca/__init__.py,sha256=3QyLLAys_KiiDIe-cfO_7QyY7di_qCaCS-sVziW2BOw,23
2
- olca/fusewill_cli.py,sha256=MjX9MDKDPCxJGDBzNhTjYahJSsAm3dGAuQXUdqJPF0I,10753
3
- olca/fusewill_utils.py,sha256=dPcc-EZDw6Ynst5ph0aIPfZhxUAXbn7w1JpDKvfpejM,8629
4
- olca/olcacli.py,sha256=NGYxZw_kYI9y9DmXu5dk02S_UOqVw05FWlzQ2gjXv00,10214
5
- olca/olcahelper.py,sha256=WdN6-K-N7-HnB9L_px6TsDKWiTXIusZM2I1d0GNQnFs,3322
6
- olca/prompts.py,sha256=7HaPbWtiLqieRZvIYO7aCuxRJMmtwA0l6Bpna-l6nkk,3439
7
- olca/tracing.py,sha256=GSuXIKmIMQ9V2gLkKcin142Z2QpyS6obsnj8Tf-1zHc,1621
8
- olca/utils.py,sha256=zM94HDMDYF95Yd9ubeOK6vuepbQN4kDFh0rTvaVFagI,912
9
- olca-0.2.58.dist-info/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
10
- olca-0.2.58.dist-info/METADATA,sha256=ttXSFlmkoIoLd6O6jw4NF4BJ0LHEJO64SkODna-VWCY,25331
11
- olca-0.2.58.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
12
- olca-0.2.58.dist-info/entry_points.txt,sha256=AhP5FMv6vnOq9C76V_vxRVIO50smnZXG4RIY47oD2_U,103
13
- olca-0.2.58.dist-info/top_level.txt,sha256=bGDtAReS-xlS0F6MM-DyD0IQUqjNdWmgemnM3vNtrpI,5
14
- olca-0.2.58.dist-info/RECORD,,
File without changes
File without changes