olca 0.2.20__tar.gz → 0.2.22__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: olca
3
- Version: 0.2.20
3
+ Version: 0.2.22
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
@@ -52,6 +52,28 @@ def main():
52
52
  parser_get_trace = subparsers.add_parser('get_trace_by_id', help='Get a trace by ID')
53
53
  parser_get_trace.add_argument('trace_id', help='Trace ID')
54
54
 
55
+ # new_score command
56
+ parser_new_score = subparsers.add_parser('new_score', help='Create a new score')
57
+ parser_new_score.add_argument('name', help='Score name')
58
+ parser_new_score.add_argument('data_type', help='Data type of the score')
59
+ parser_new_score.add_argument('--description', default='', help='Description of the score')
60
+
61
+ # add_score_to_trace command
62
+ parser_add_score = subparsers.add_parser('add_score_to_trace', help='Add a score to a trace', aliases=['s2t'])
63
+ parser_add_score.add_argument('trace_id', help='Trace ID')
64
+ parser_add_score.add_argument('generation_id', help='Generation ID')
65
+ parser_add_score.add_argument('name', help='Score name')
66
+ parser_add_score.add_argument('value', help='Score value')
67
+ parser_add_score.add_argument('--data_type', default='NUMERIC', help='Data type of the score')
68
+ parser_add_score.add_argument('--comment', default='', help='Comment for the score')
69
+
70
+ # list_traces_by_score command
71
+ parser_list_by_score = subparsers.add_parser('list_traces_by_score', help='List traces by score')
72
+ parser_list_by_score.add_argument('score_name', help='Score name')
73
+ parser_list_by_score.add_argument('--min_value', type=float, help='Minimum score value')
74
+ parser_list_by_score.add_argument('--max_value', type=float, help='Maximum score value')
75
+ parser_list_by_score.add_argument('--limit', type=int, default=100, help='Number of traces to fetch')
76
+
55
77
  args = parser.parse_args()
56
78
 
57
79
  if args.command == 'list_traces':
@@ -75,6 +97,28 @@ def main():
75
97
  elif args.command == 'get_trace_by_id':
76
98
  trace = get_trace_by_id(trace_id=args.trace_id)
77
99
  print(trace)
100
+ elif args.command == 'new_score':
101
+ fu.create_score(name=args.name, data_type=args.data_type, description=args.description)
102
+ elif args.command == 'add_score_to_trace':
103
+ if not fu.score_exists(name=args.name):
104
+ fu.create_score(name=args.name, data_type=args.data_type)
105
+ fu.add_score_to_a_trace(
106
+ trace_id=args.trace_id,
107
+ generation_id=args.generation_id,
108
+ name=args.name,
109
+ value=args.value,
110
+ data_type=args.data_type,
111
+ comment=args.comment
112
+ )
113
+ elif args.command == 'list_traces_by_score':
114
+ traces = fu.list_traces_by_score(
115
+ score_name=args.score_name,
116
+ min_value=args.min_value,
117
+ max_value=args.max_value,
118
+ limit=args.limit
119
+ )
120
+ for trace in traces:
121
+ print(f"Trace ID: {trace.id}, Name: {trace.name}")
78
122
  else:
79
123
  parser.print_help()
80
124
 
@@ -1,26 +1,34 @@
1
- from langfuse import Langfuse
2
1
  import os
3
2
  import sys
4
- sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
5
3
  import json
6
-
7
4
  import dotenv
8
5
 
9
- # Check if the variables are already set in the environment
6
+ # Load .env from the current working directory
7
+ dotenv.load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
8
+
9
+ # Try loading from home directory if variables are still not set
10
10
  if not os.environ.get("LANGFUSE_PUBLIC_KEY") or not os.environ.get("LANGFUSE_SECRET_KEY"):
11
- # Load from .env in current directory
12
- dotenv.load_dotenv()
11
+ dotenv.load_dotenv(dotenv_path=os.path.expanduser("~/.env"))
13
12
 
14
- # Check again
15
- if not os.environ.get("LANGFUSE_PUBLIC_KEY") or not os.environ.get("LANGFUSE_SECRET_KEY"):
16
- # Load from .env in home directory
17
- dotenv.load_dotenv(dotenv_path=os.path.expanduser("~/.env"))
13
+ # Final check before exiting
14
+ missing_vars = []
15
+ if not os.environ.get("LANGFUSE_PUBLIC_KEY"):
16
+ missing_vars.append("LANGFUSE_PUBLIC_KEY")
17
+ if not os.environ.get("LANGFUSE_SECRET_KEY"):
18
+ missing_vars.append("LANGFUSE_SECRET_KEY")
18
19
 
19
- # Final check
20
- if not os.environ.get("LANGFUSE_PUBLIC_KEY") or not os.environ.get("LANGFUSE_SECRET_KEY"):
21
- print("Error: LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY not found.")
20
+ if missing_vars:
21
+ print(f"Error: {', '.join(missing_vars)} not found.")
22
22
  sys.exit(1)
23
23
 
24
+ from langfuse import Langfuse
25
+ import os
26
+ import sys
27
+ sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
28
+ import json
29
+
30
+ import dotenv
31
+
24
32
  langfuse = Langfuse()
25
33
 
26
34
  def list_traces(limit=100, output_dir="../output/traces"):
@@ -33,6 +41,17 @@ def list_traces(limit=100, output_dir="../output/traces"):
33
41
  print("---")
34
42
  return traces
35
43
 
44
+ def list_traces_by_score(score_name, min_value=None, max_value=None, limit=100):
45
+ traces = langfuse.get_traces(limit=limit)
46
+ filtered_traces = []
47
+ for trace in traces.data:
48
+ for score in trace.scores:
49
+ if score.name == score_name:
50
+ if (min_value is None or score.value >= min_value) and (max_value is None or score.value <= max_value):
51
+ filtered_traces.append(trace)
52
+ break
53
+ return filtered_traces
54
+
36
55
  def add_score_to_a_trace(trace_id, generation_id, name, value, data_type="NUMERIC", comment=""):
37
56
  langfuse.score(
38
57
  trace_id=trace_id,
@@ -43,6 +62,20 @@ def add_score_to_a_trace(trace_id, generation_id, name, value, data_type="NUMERI
43
62
  comment=comment
44
63
  )
45
64
 
65
+ def create_score(name, data_type, description=""):
66
+ langfuse.create_score(
67
+ name=name,
68
+ data_type=data_type,
69
+ description=description
70
+ )
71
+
72
+ def score_exists(name):
73
+ scores = langfuse.get_scores()
74
+ for score in scores.data:
75
+ if score.name == name:
76
+ return True
77
+ return False
78
+
46
79
  def create_dataset(name, description="", metadata=None):
47
80
  langfuse.create_dataset(
48
81
  name=name,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: olca
3
- Version: 0.2.20
3
+ Version: 0.2.22
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
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "olca"
10
- version = "0.2.20"
10
+ version = "0.2.22"
11
11
 
12
12
  description = "A Python package for experimental usage of Langchain and Human-in-the-Loop"
13
13
  readme = "README.md"
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='olca',
5
- version = "0.2.20",
5
+ version = "0.2.22",
6
6
  author='Jean GUillaume ISabelle',
7
7
  author_email='jgi@jgwill.com',
8
8
  description='A Python package for experimenting with Langchain agent and interactivity in Terminal modalities.',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes