olca 0.2.38__py3-none-any.whl → 0.2.40__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
olca/olcacli.py CHANGED
@@ -5,7 +5,7 @@ import dotenv
5
5
  from langchain import hub
6
6
  import argparse
7
7
  import yaml
8
- import fusewill_utils as fu
8
+ from olca.utils import load_environment, initialize_langfuse
9
9
 
10
10
  #jgwill/olca1
11
11
  #olca1_prompt = hub.pull("jgwill/olca1") #Future use
@@ -137,6 +137,10 @@ def extract_extra_directories_from_olca_config_system_and_user_input(system_inst
137
137
  def print_stream(stream):
138
138
  for s in stream:
139
139
  try:
140
+ # Skip Langfuse internal state messages
141
+ if isinstance(s, dict) and 'keep_alive' in s and 'states' in s:
142
+ continue
143
+
140
144
  # Handle different response formats
141
145
  if isinstance(s, dict) and "messages" in s:
142
146
  message = s["messages"][-1]
@@ -145,10 +149,16 @@ def print_stream(stream):
145
149
 
146
150
  if isinstance(message, tuple):
147
151
  print(message)
148
- else:
152
+ elif hasattr(message, 'content'):
149
153
  print(message.content)
154
+ else:
155
+ # Only print if it's not a system message
156
+ if not (isinstance(s, dict) and any(k in s for k in ['keep_alive', 'states'])):
157
+ print(s)
150
158
  except Exception as e:
151
- print(s)
159
+ # Only print if it's not a system message
160
+ if not (isinstance(s, dict) and any(k in s for k in ['keep_alive', 'states'])):
161
+ print(s)
152
162
 
153
163
  def prepare_input(user_input, system_instructions,append_prompt=True, human=False):
154
164
  appended_prompt = system_instructions + SYSTEM_PROMPT_APPEND if append_prompt else system_instructions
@@ -177,15 +187,6 @@ def _parse_args():
177
187
 
178
188
  from olca.tracing import TracingManager
179
189
 
180
- def load_environment():
181
- # Load .env from current directory
182
- dotenv.load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
183
-
184
- # Try loading from home directory if keys are missing
185
- if not all([os.getenv(key) for key in ["LANGFUSE_PUBLIC_KEY", "LANGFUSE_SECRET_KEY", "LANGFUSE_HOST",
186
- "LANGCHAIN_API_KEY", "OPENAI_API_KEY"]]):
187
- dotenv.load_dotenv(dotenv_path=os.path.expanduser("~/.env"))
188
-
189
190
  def main():
190
191
  args = _parse_args()
191
192
  olca_config_file = 'olca.yml'
@@ -193,6 +194,9 @@ def main():
193
194
  # Load environment variables first
194
195
  load_environment()
195
196
 
197
+ # Initialize Langfuse if needed
198
+ langfuse = initialize_langfuse()
199
+
196
200
  if args.init:
197
201
  if os.path.exists(olca_config_file):
198
202
  print("Error: Configuration file already exists. Cannot run 'olca init'.")
olca/tracing.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  from langfuse.callback import CallbackHandler as LangfuseCallbackHandler
3
3
  from langfuse import Langfuse
4
+ from olca.utils import initialize_langfuse
4
5
 
5
6
  class TracingManager:
6
7
  def __init__(self, config):
@@ -29,16 +30,11 @@ class TracingManager:
29
30
  os.environ["LANGCHAIN_TRACING_V2"] = "true"
30
31
 
31
32
  def _setup_langfuse(self):
32
- required_vars = ["LANGFUSE_PUBLIC_KEY", "LANGFUSE_SECRET_KEY", "LANGFUSE_HOST"]
33
- if not all(os.getenv(var) for var in required_vars):
33
+ langfuse = initialize_langfuse()
34
+ if not langfuse:
34
35
  print("Warning: Missing Langfuse environment variables")
35
36
  return None
36
37
 
37
- Langfuse(
38
- public_key=os.getenv("LANGFUSE_PUBLIC_KEY"),
39
- secret_key=os.getenv("LANGFUSE_SECRET_KEY"),
40
- host=os.getenv("LANGFUSE_HOST")
41
- )
42
38
  return LangfuseCallbackHandler()
43
39
 
44
40
  def get_callbacks(self):
olca/utils.py ADDED
@@ -0,0 +1,24 @@
1
+ import os
2
+ import sys
3
+ import dotenv
4
+ import webbrowser
5
+ from langfuse import Langfuse
6
+
7
+ def load_environment():
8
+ dotenv.load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env"))
9
+
10
+ # Try loading from home directory if variables are still not set
11
+ if not all([os.getenv(key) for key in ["LANGFUSE_PUBLIC_KEY", "LANGFUSE_SECRET_KEY", "LANGFUSE_HOST",
12
+ "LANGCHAIN_API_KEY", "OPENAI_API_KEY"]]):
13
+ dotenv.load_dotenv(dotenv_path=os.path.expanduser("~/.env"))
14
+
15
+ def initialize_langfuse():
16
+ required_vars = ["LANGFUSE_PUBLIC_KEY", "LANGFUSE_SECRET_KEY", "LANGFUSE_HOST"]
17
+ if not all(os.getenv(var) for var in required_vars):
18
+ return None
19
+
20
+ return Langfuse(
21
+ public_key=os.getenv("LANGFUSE_PUBLIC_KEY"),
22
+ secret_key=os.getenv("LANGFUSE_SECRET_KEY"),
23
+ host=os.getenv("LANGFUSE_HOST")
24
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: olca
3
- Version: 0.2.38
3
+ Version: 0.2.40
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,12 @@
1
+ olca/__init__.py,sha256=3QyLLAys_KiiDIe-cfO_7QyY7di_qCaCS-sVziW2BOw,23
2
+ olca/fusewill_cli.py,sha256=Gf8CaYs7Uo4NH8QfgRNYalpmSUo047p9rzdkvIABHi8,7872
3
+ olca/fusewill_utils.py,sha256=IOIElqWCIsNzePlS1FZa5_35vySYLwbMUGW6UhNefIc,6065
4
+ olca/olcacli.py,sha256=whzbvrhJkiIoHkTPL_mRH0ZzZvmUKwZ2LiL65s32Vzw,15980
5
+ olca/tracing.py,sha256=FnToJVhD7XxP0lBe_Ca7bQJYDHEs9bSaFqZx7rpbSaU,1269
6
+ olca/utils.py,sha256=l01DkaDw5ENl8tzN8X4Ftgntz321AEAY1gpRX8_5q6Q,879
7
+ olca-0.2.40.dist-info/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
8
+ olca-0.2.40.dist-info/METADATA,sha256=C7JU43sZtW1oLo_0OGjScVspSsNKkdB5STHVfFegGd8,25311
9
+ olca-0.2.40.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
10
+ olca-0.2.40.dist-info/entry_points.txt,sha256=AhP5FMv6vnOq9C76V_vxRVIO50smnZXG4RIY47oD2_U,103
11
+ olca-0.2.40.dist-info/top_level.txt,sha256=bGDtAReS-xlS0F6MM-DyD0IQUqjNdWmgemnM3vNtrpI,5
12
+ olca-0.2.40.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- olca/__init__.py,sha256=3QyLLAys_KiiDIe-cfO_7QyY7di_qCaCS-sVziW2BOw,23
2
- olca/fusewill_cli.py,sha256=Gf8CaYs7Uo4NH8QfgRNYalpmSUo047p9rzdkvIABHi8,7872
3
- olca/fusewill_utils.py,sha256=IOIElqWCIsNzePlS1FZa5_35vySYLwbMUGW6UhNefIc,6065
4
- olca/olcacli.py,sha256=VXXGfUAxrWTI_EM-TRpDNo2Cop3MRZWgQfN_S0HJwNc,15777
5
- olca/tracing.py,sha256=OexV2i7d7-tLN9XYTL9D9gGh0y0uYcfQK7_eIDNX2Iw,1495
6
- olca-0.2.38.dist-info/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
7
- olca-0.2.38.dist-info/METADATA,sha256=YHvmI1c0vXi6yjFquHAWj1ZKBSuOMcHTJOBZiUQz100,25311
8
- olca-0.2.38.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
9
- olca-0.2.38.dist-info/entry_points.txt,sha256=AhP5FMv6vnOq9C76V_vxRVIO50smnZXG4RIY47oD2_U,103
10
- olca-0.2.38.dist-info/top_level.txt,sha256=bGDtAReS-xlS0F6MM-DyD0IQUqjNdWmgemnM3vNtrpI,5
11
- olca-0.2.38.dist-info/RECORD,,
File without changes
File without changes