Skip to content

Commit

Permalink
freezing working again
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcowD committed Aug 7, 2024
1 parent b3faf30 commit 4eea974
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/output_freezing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions examples/quick_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -52,13 +56,17 @@ 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:
parts = personality.split("\n")
names.append(parts[0].split(": ")[1])
backstories.append(parts[1].split(": ")[1])
print(names)


whos_turn = 0
for _ in range(10):

Expand Down
14 changes: 7 additions & 7 deletions src/ell/decorators/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ell/util/closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4eea974

Please sign in to comment.