File size: 901 Bytes
24dcddf
 
 
 
 
 
 
 
34cd91e
 
24dcddf
 
 
 
 
 
34cd91e
 
 
 
 
 
 
24dcddf
 
 
 
34cd91e
24dcddf
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import TypedDict, AnyStr

from .prompt import highlight_explain_chain


class State(TypedDict):
    domain: AnyStr
    highlight_terms: AnyStr
    before_highlight_paragraph: AnyStr
    after_highlight_paragraph: AnyStr
    question: AnyStr
    explanation: AnyStr
    language: AnyStr


async def highlight_explain(state: State):
    adjacent_paragraphs = (
        state["before_highlight_paragraph"]
        + "**"
        + state["highlight_terms"]
        + "**"
        + state["after_highlight_paragraph"]
    )
    response = await highlight_explain_chain.ainvoke(
        {
            "domain": state["domain"],
            "highlight_terms": state["highlight_terms"],
            "adjacent_paragraphs": adjacent_paragraphs,
            "question": state["question"],
            "language": state["language"],
        }
    )
    return {"explanation": response["explanation"]}