From 796012f71646b80ac7e14d4bf4a5cd0e19dc19eb Mon Sep 17 00:00:00 2001 From: LUIS NOVO Date: Fri, 1 Nov 2024 13:08:18 -0300 Subject: [PATCH] rename to patterns --- open_notebook/graphs/multipattern.py | 10 +++++----- open_notebook/graphs/recursive_toc.py | 2 +- stream_app/note.py | 6 ++---- stream_app/source.py | 10 ++++------ transformations.yaml | 12 ++++++------ 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/open_notebook/graphs/multipattern.py b/open_notebook/graphs/multipattern.py index f3b530b..b8fe6db 100644 --- a/open_notebook/graphs/multipattern.py +++ b/open_notebook/graphs/multipattern.py @@ -13,7 +13,7 @@ from open_notebook.graphs.utils import run_pattern class PatternChainState(TypedDict): content_stack: Annotated[Sequence[str], operator.add] - transformations: List[str] + patterns: List[str] output: str @@ -21,8 +21,8 @@ def call_model(state: dict, config: RunnableConfig) -> dict: model_id = config.get("configurable", {}).get( "model_id", DEFAULT_MODELS.default_transformation_model ) - transformations = state["transformations"] - current_transformation = transformations.pop(0) + patterns = state["patterns"] + current_transformation = patterns.pop(0) if current_transformation.startswith("patterns/"): input_args = {"input_text": state["content_stack"][-1]} else: @@ -40,7 +40,7 @@ def call_model(state: dict, config: RunnableConfig) -> dict: return { "content_stack": [transformation_result.content], "output": transformation_result.content, - "transformations": state["transformations"], + "patterns": state["patterns"], } @@ -48,7 +48,7 @@ def transform_condition(state: PatternChainState) -> Literal["agent", END]: # t """ Checks whether there are more chunks to process. """ - if len(state["transformations"]) > 0: + if len(state["patterns"]) > 0: return "agent" return END diff --git a/open_notebook/graphs/recursive_toc.py b/open_notebook/graphs/recursive_toc.py index 14a29b8..f52ceae 100644 --- a/open_notebook/graphs/recursive_toc.py +++ b/open_notebook/graphs/recursive_toc.py @@ -54,7 +54,7 @@ def call_model(state: TocState, config: RunnableConfig) -> dict: ) return { "toc": run_pattern( - pattern_name="default/recursive_toc", + pattern_name="recursive_toc", model_id=model_id, state=state, ).content diff --git a/stream_app/note.py b/stream_app/note.py index 50c35cc..2cf063e 100644 --- a/stream_app/note.py +++ b/stream_app/note.py @@ -52,12 +52,10 @@ def note_panel(session_id=None, note_id=None): def make_note_from_chat(content, notebook_id=None): # todo: make this more efficient - transformations = [ + patterns = [ "Based on the Note below, please provide a Title for this content, with max 15 words" ] - output = pattern_graph.invoke( - dict(content_stack=[content], transformations=transformations) - ) + output = pattern_graph.invoke(dict(content_stack=[content], patterns=patterns)) title = surreal_clean(output["output"]) note = Note( diff --git a/stream_app/source.py b/stream_app/source.py index 96109bb..798197d 100644 --- a/stream_app/source.py +++ b/stream_app/source.py @@ -17,10 +17,8 @@ from open_notebook.utils import surreal_clean from .consts import context_icons -def run_transformations(input_text, transformations): - output = transform_graph.invoke( - dict(content_stack=[input_text], transformations=transformations) - ) +def run_patterns(input_text, patterns): + output = transform_graph.invoke(dict(content_stack=[input_text], patterns=patterns)) return output["output"] @@ -66,8 +64,8 @@ def source_panel(source_id): if st.button( transformation["name"], help=transformation["description"] ): - result = run_transformations( - source.full_text, transformation["transformations"] + result = run_patterns( + source.full_text, transformation["patterns"] ) source.add_insight( transformation["insight_type"], surreal_clean(result) diff --git a/transformations.yaml b/transformations.yaml index 8b684e8..531ad4c 100644 --- a/transformations.yaml +++ b/transformations.yaml @@ -3,33 +3,33 @@ source_insights: - name: "Summarize" insight_type: "Content Summary" description: "Summarize the content" - transformations: + patterns: - patterns/default/makeitdense - patterns/default/summarize - name: "Key Insights" insight_type: "Key Insights" description: "Extracts a list of the Key Insights of the content" - transformations: + patterns: - patterns/default/keyinsights - name: "Make it Dense" insight_type: "Dense Representation" description: "Create a dense representation of the content" - transformations: + patterns: - patterns/default/makeitdense - name: "Analyze Paper" insight_type: "Paper Analysis" description: "Analyze the paper and provide a quick summary" - transformations: + patterns: - patterns/default/analyze_paper - name: "Reflection" insight_type: "Reflection Questions" description: "Generates a list of insightful questions to provoke reflection" - transformations: + patterns: - patterns/default/reflection_questions # - name: "Reflection [PT]" # insight_type: "Reflection Questions [PT]" # description: "Generates a list of insightful questions to provoke reflection" - # transformations: + # patterns: # - patterns/default/reflection_questions # - patterns/default/translate