diff --git a/examples/output_freezing.py b/examples/output_freezing.py index d6d6967b..848ec4f5 100644 --- a/examples/output_freezing.py +++ b/examples/output_freezing.py @@ -4,7 +4,7 @@ BASE_PROMPT = """You are an adept python programmer. Only answer in python code. Avoid markdown formatting at all costs.""" -@ell.lm(model="gpt-4o", temperature=0.7) +@ell.lm(model="gpt-4o", temperature=0.7, max_tokens=4) def create_a_python_class(user_spec : str): return [ ell.system( diff --git a/examples/quick_chat.py b/examples/quick_chat.py index c3fe0da3..c6a9474a 100644 --- a/examples/quick_chat.py +++ b/examples/quick_chat.py @@ -29,6 +29,10 @@ def create_personality() -> str: return "Come up with a backstory about " + random.choice(names_list) # User prompt + + + + def format_message_history(message_history : List[Tuple[str, str]]) -> str: return "\n".join([f"{name}: {message}" for name, message in message_history]) @@ -52,6 +56,8 @@ def chat(message_history : List[Tuple[str, str]], *, personality : str): messages : List[Tuple[str, str]]= [] personalities = [create_personality(), create_personality()] + + # lstr (str), keeps track of its "orginator" names = [] backstories = [] for personality in personalities: @@ -59,6 +65,8 @@ def chat(message_history : List[Tuple[str, str]], *, personality : str): names.append(parts[0].split(": ")[1]) backstories.append(parts[1].split(": ")[1]) print(names) + + whos_turn = 0 for _ in range(10): diff --git a/src/ell/decorators/track.py b/src/ell/decorators/track.py index f88e9978..c01c4a8e 100644 --- a/src/ell/decorators/track.py +++ b/src/ell/decorators/track.py @@ -89,7 +89,7 @@ def wrapper(*fn_args, **fn_kwargs) -> str: # Todo: add nice logging if verbose for when using a cahced invocaiton. IN a different color with thar args.. if not hasattr(func_to_track, "__ell_hash__") and config.lazy_versioning: fn_closure, _ = ell.util.closure.lexically_closured_source(func_to_track) - + # compute the state cachekey state_cache_key = compute_state_cache_key(ipstr, func_to_track.__ell_closure__) @@ -99,7 +99,7 @@ def wrapper(*fn_args, **fn_kwargs) -> str: if len(cached_invocations) > 0: # TODO THis is bad? - results = [SerializedLStr(**d).deserialize() for d in cached_invocations[0]['results']] + results = [d.deserialize() for d in cached_invocations[0].results] logger.info(f"Using cached result for {func_to_track.__qualname__} with state cache key: {state_cache_key}") if len(results) == 1: @@ -130,7 +130,7 @@ def wrapper(*fn_args, **fn_kwargs) -> str: if not _has_serialized_lmp: if not hasattr(func_to_track, "__ell_hash__") and config.lazy_versioning: fn_closure, _ = ell.util.closure.lexically_closured_source(func_to_track) - + print(fn_closure) _serialize_lmp(func_to_track, _name, fn_closure, lmp, lm_kwargs) _has_serialized_lmp = True @@ -155,16 +155,16 @@ def wrapper(*fn_args, **fn_kwargs) -> str: def _serialize_lmp(func, name, fn_closure, is_lmp, lm_kwargs): lmps = config._store.get_versions_by_fqn(fqn=name) version = 0 - already_in_store = any(lmp['lmp_id'] == func.__ell_hash__ for lmp in lmps) + already_in_store = any(lmp.lmp_id == func.__ell_hash__ for lmp in lmps) if not already_in_store: if lmps: - latest_lmp = max(lmps, key=lambda x: x['created_at']) - version = latest_lmp['version_number'] + 1 + latest_lmp = max(lmps, key=lambda x: x.created_at) + version = latest_lmp.version_number + 1 if config.autocommit: from ell.util.differ import write_commit_message_for_diff commit = str(write_commit_message_for_diff( - f"{latest_lmp['dependencies']}\n\n{latest_lmp['source']}", + f"{latest_lmp.dependencies}\n\n{latest_lmp.source}", f"{fn_closure[1]}\n\n{fn_closure[0]}")[0]) else: commit = None diff --git a/src/ell/util/closure.py b/src/ell/util/closure.py index d13d6eb2..32e75701 100644 --- a/src/ell/util/closure.py +++ b/src/ell/util/closure.py @@ -360,7 +360,7 @@ def lexically_closured_source(func): source, dsrc = fnclosure formatted_source = _format_source(source) formatted_dsrc = _format_source(dsrc) - return (formatted_source, formatted_dsrc), uses + return (formatted_source, formatted_dsrc,) + func.__ell_closure__[2:], uses import ast