Skip to content

Commit

Permalink
Tree edit - None conditions treated as else statements if there are m…
Browse files Browse the repository at this point in the history
…ultiple possible transitions
  • Loading branch information
grantbuster committed Sep 15, 2023
1 parent 715cdde commit 581578a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions elm/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, text, model=None, n_words=500, **chunk_kwargs):
assert isinstance(self.text, str)

self.text_chunks = Chunker(self.text, **chunk_kwargs)
self.summary_chunks = []

def combine(self, text_summary):
"""Combine separate chunk summaries into one more comprehensive
Expand Down Expand Up @@ -106,6 +107,7 @@ def run(self, temperature=0, fancy_combine=True):
msg = f'"""{chunk}"""\n\n{instruction}'
response = self.generic_query(msg, model_role=self.MODEL_ROLE,
temperature=temperature)
self.summary_chunks.append(response)
summary += f'\n\n{response}'

if fancy_combine:
Expand Down Expand Up @@ -155,6 +157,7 @@ async def run_async(self, temperature=0, rate_limit=40e3,
temperature=temperature,
rate_limit=rate_limit)

self.summary_chunks = summaries
summary = '\n\n'.join(summaries)

if fancy_combine:
Expand Down
19 changes: 11 additions & 8 deletions elm/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def __init__(self, graph):
have attribute "prompt" which can have {format} named arguments
that will be filled from the high-level graph attributes. Edges can
have attribute "condition" that is a callable to be executed on the
LLM response text. No edge condition will signify a preferred
transition.
LLM response text. An edge from a node without a condition acts as
an "else" statement if no other edge conditions are satisfied. A
single edge from node to node does not need a condition.
"""
self._g = graph
self._history = []
Expand Down Expand Up @@ -145,21 +146,23 @@ def call_node(self, node0):
return out

if len(successors) > 1 and all(c is None for c in conditions):
msg = (f'None of the edges from "{node0}" have '
msg = (f'At least one of the edges from "{node0}" should have '
f'a "condition": {edges}')
logger.error(msg)
raise AttributeError(msg)

# prioritize callable conditions
for i, condition in enumerate(conditions):

if condition is None:
if callable(condition) and condition(out):
logger.info(f'Node transition: "{node0}" -> "{successors[i]}" '
'(satisfied by None condition)')
'(satisfied by callable condition)')
return successors[i]

elif callable(condition) and condition(out):
# None condition is basically "else" statement
for i, condition in enumerate(conditions):
if condition is None:
logger.info(f'Node transition: "{node0}" -> "{successors[i]}" '
'(satisfied by callable condition)')
'(satisfied by None condition)')
return successors[i]

msg = (f'None of the edge conditions from "{node0}" '
Expand Down

0 comments on commit 581578a

Please sign in to comment.