File size: 747 Bytes
0b677b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from data.schemaClass import State
from langchain.prompts import PromptTemplate
from langchain.schema import HumanMessage
from api_client.api import llm


def summarization_node_usecase(state: State):
    """

    Summarize the text in one short sentence

    """
    prompt = PromptTemplate(
        input_variables=["text"],
        template="Summarize the following text in one short sentence.\n\nText:{text}\n\nSummary:"
    )
    message = HumanMessage(content=prompt.format(text=state.text))  # Access state.text instead of state["text"]
    summary = llm.invoke([message]).content.strip()

    # Update the state with the summary
    state.summary = summary

    return state  # Return the updated state with the summary