rename to patterns
This commit is contained in:
parent
3e11d9ba68
commit
796012f716
5 changed files with 18 additions and 22 deletions
|
|
@ -13,7 +13,7 @@ from open_notebook.graphs.utils import run_pattern
|
||||||
|
|
||||||
class PatternChainState(TypedDict):
|
class PatternChainState(TypedDict):
|
||||||
content_stack: Annotated[Sequence[str], operator.add]
|
content_stack: Annotated[Sequence[str], operator.add]
|
||||||
transformations: List[str]
|
patterns: List[str]
|
||||||
output: str
|
output: str
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,8 +21,8 @@ def call_model(state: dict, config: RunnableConfig) -> dict:
|
||||||
model_id = config.get("configurable", {}).get(
|
model_id = config.get("configurable", {}).get(
|
||||||
"model_id", DEFAULT_MODELS.default_transformation_model
|
"model_id", DEFAULT_MODELS.default_transformation_model
|
||||||
)
|
)
|
||||||
transformations = state["transformations"]
|
patterns = state["patterns"]
|
||||||
current_transformation = transformations.pop(0)
|
current_transformation = patterns.pop(0)
|
||||||
if current_transformation.startswith("patterns/"):
|
if current_transformation.startswith("patterns/"):
|
||||||
input_args = {"input_text": state["content_stack"][-1]}
|
input_args = {"input_text": state["content_stack"][-1]}
|
||||||
else:
|
else:
|
||||||
|
|
@ -40,7 +40,7 @@ def call_model(state: dict, config: RunnableConfig) -> dict:
|
||||||
return {
|
return {
|
||||||
"content_stack": [transformation_result.content],
|
"content_stack": [transformation_result.content],
|
||||||
"output": 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.
|
Checks whether there are more chunks to process.
|
||||||
"""
|
"""
|
||||||
if len(state["transformations"]) > 0:
|
if len(state["patterns"]) > 0:
|
||||||
return "agent"
|
return "agent"
|
||||||
return END
|
return END
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ def call_model(state: TocState, config: RunnableConfig) -> dict:
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"toc": run_pattern(
|
"toc": run_pattern(
|
||||||
pattern_name="default/recursive_toc",
|
pattern_name="recursive_toc",
|
||||||
model_id=model_id,
|
model_id=model_id,
|
||||||
state=state,
|
state=state,
|
||||||
).content
|
).content
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,10 @@ def note_panel(session_id=None, note_id=None):
|
||||||
|
|
||||||
def make_note_from_chat(content, notebook_id=None):
|
def make_note_from_chat(content, notebook_id=None):
|
||||||
# todo: make this more efficient
|
# todo: make this more efficient
|
||||||
transformations = [
|
patterns = [
|
||||||
"Based on the Note below, please provide a Title for this content, with max 15 words"
|
"Based on the Note below, please provide a Title for this content, with max 15 words"
|
||||||
]
|
]
|
||||||
output = pattern_graph.invoke(
|
output = pattern_graph.invoke(dict(content_stack=[content], patterns=patterns))
|
||||||
dict(content_stack=[content], transformations=transformations)
|
|
||||||
)
|
|
||||||
title = surreal_clean(output["output"])
|
title = surreal_clean(output["output"])
|
||||||
|
|
||||||
note = Note(
|
note = Note(
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,8 @@ from open_notebook.utils import surreal_clean
|
||||||
from .consts import context_icons
|
from .consts import context_icons
|
||||||
|
|
||||||
|
|
||||||
def run_transformations(input_text, transformations):
|
def run_patterns(input_text, patterns):
|
||||||
output = transform_graph.invoke(
|
output = transform_graph.invoke(dict(content_stack=[input_text], patterns=patterns))
|
||||||
dict(content_stack=[input_text], transformations=transformations)
|
|
||||||
)
|
|
||||||
return output["output"]
|
return output["output"]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,8 +64,8 @@ def source_panel(source_id):
|
||||||
if st.button(
|
if st.button(
|
||||||
transformation["name"], help=transformation["description"]
|
transformation["name"], help=transformation["description"]
|
||||||
):
|
):
|
||||||
result = run_transformations(
|
result = run_patterns(
|
||||||
source.full_text, transformation["transformations"]
|
source.full_text, transformation["patterns"]
|
||||||
)
|
)
|
||||||
source.add_insight(
|
source.add_insight(
|
||||||
transformation["insight_type"], surreal_clean(result)
|
transformation["insight_type"], surreal_clean(result)
|
||||||
|
|
|
||||||
|
|
@ -3,33 +3,33 @@ source_insights:
|
||||||
- name: "Summarize"
|
- name: "Summarize"
|
||||||
insight_type: "Content Summary"
|
insight_type: "Content Summary"
|
||||||
description: "Summarize the content"
|
description: "Summarize the content"
|
||||||
transformations:
|
patterns:
|
||||||
- patterns/default/makeitdense
|
- patterns/default/makeitdense
|
||||||
- patterns/default/summarize
|
- patterns/default/summarize
|
||||||
- name: "Key Insights"
|
- name: "Key Insights"
|
||||||
insight_type: "Key Insights"
|
insight_type: "Key Insights"
|
||||||
description: "Extracts a list of the Key Insights of the content"
|
description: "Extracts a list of the Key Insights of the content"
|
||||||
transformations:
|
patterns:
|
||||||
- patterns/default/keyinsights
|
- patterns/default/keyinsights
|
||||||
- name: "Make it Dense"
|
- name: "Make it Dense"
|
||||||
insight_type: "Dense Representation"
|
insight_type: "Dense Representation"
|
||||||
description: "Create a dense representation of the content"
|
description: "Create a dense representation of the content"
|
||||||
transformations:
|
patterns:
|
||||||
- patterns/default/makeitdense
|
- patterns/default/makeitdense
|
||||||
- name: "Analyze Paper"
|
- name: "Analyze Paper"
|
||||||
insight_type: "Paper Analysis"
|
insight_type: "Paper Analysis"
|
||||||
description: "Analyze the paper and provide a quick summary"
|
description: "Analyze the paper and provide a quick summary"
|
||||||
transformations:
|
patterns:
|
||||||
- patterns/default/analyze_paper
|
- patterns/default/analyze_paper
|
||||||
- name: "Reflection"
|
- name: "Reflection"
|
||||||
insight_type: "Reflection Questions"
|
insight_type: "Reflection Questions"
|
||||||
description: "Generates a list of insightful questions to provoke reflection"
|
description: "Generates a list of insightful questions to provoke reflection"
|
||||||
transformations:
|
patterns:
|
||||||
- patterns/default/reflection_questions
|
- patterns/default/reflection_questions
|
||||||
# - name: "Reflection [PT]"
|
# - name: "Reflection [PT]"
|
||||||
# insight_type: "Reflection Questions [PT]"
|
# insight_type: "Reflection Questions [PT]"
|
||||||
# description: "Generates a list of insightful questions to provoke reflection"
|
# description: "Generates a list of insightful questions to provoke reflection"
|
||||||
# transformations:
|
# patterns:
|
||||||
# - patterns/default/reflection_questions
|
# - patterns/default/reflection_questions
|
||||||
# - patterns/default/translate
|
# - patterns/default/translate
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue