the node named "is_need_search_nrcc" is going to return a dict cntained with below field.
class isNeedSearchNrccModel(BaseModel):
is_need: bool = Field(description="")
rationale: str = Field(description="")
chems: list[str] = Field(description="")
I followed the official document cited at:
https://docs.copilotkit.ai/langgraph/shared-state/state-inputs-outputs
This is my implementation.
import operator
from typing import Annotated, TypedDict
from copilotkit import CopilotKitState
from langgraph.graph import add_messages
from pydantic import BaseModel, Field
class InputState(CopilotKitState):
query: Annotated[str, add_messages]
class OutputState(CopilotKitState):
messages: Annotated[list, add_messages]
class msdsOverallState(InputState, OutputState):
# messages: Annotated[list, add_messages]
chem_infos: Annotated[list, operator.add]
class isNeedSearchNrccModel(BaseModel):
is_need: bool = Field(description="")
rationale: str = Field(description="")
chems: list[str] = Field(description="")
class chemsNrcc(TypedDict):
is_need: bool
chems: list
class chemNrcc(TypedDict):
chem: str
def is_need_query_nrcc(state: msdsOverallState, config: RunnableConfig) -> chemsNrcc:
llm = chat_model.with_structured_output(isNeedSearchNrccModel)
formatted_prompt = isNeedQueryMsds.format(query=state["messages"][-1].content)
result = llm.invoke(formatted_prompt)
return {"is_need": result.is_need, "chems": result.chems}
Decide which state properties are received and returned to the frontend