I need some help with my feedback node! #1765
Unanswered
RedouanAssakali
asked this question in
Q&A
Replies: 1 comment
-
It's strange for |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am working on building a graph using LangGraph Studio Engineer.
I have modified the code and am trying to understand how to send information in a state, but I still need some support.
The goal is to create a visually appealing price quote based on simple notes sent by the user. When the content is generated, it should ask for feedback and make modifications until the user is satisfied. Once approved, we will generate a .docx file containing the price quote. My challenge lies in handling the feedback node.
I hope someone can assist me with my graph.
The logic behind this:
`from langgraph.graph import StateGraph, MessagesState, END
from langchain_core.tools import tool
from langchain_core.messages import HumanMessage, AIMessage, SystemMessage
from langchain_openai import AzureChatOpenAI
from pydantic import BaseModel, Field
from typing import List
from IPython.display import Image, display
from dotenv import load_dotenv
import os
load_dotenv()
os.environ["AZURE_OPENAI_ENDPOINT"] = os.environ.get("OPENAI_ENDPOINT")
os.environ["AZURE_OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY")
model = AzureChatOpenAI(
api_version="2024-05-01-preview",
model="gpt-35-turbo",
)
Define the Operation and Quote classes
class Operation(BaseModel):
activity: str = Field(description="The main activity or task to be performed")
details: str = Field(description="Detailed description of the activity")
class Quote(BaseModel):
receiver_information: str = Field(dzescription="Receiver Information, company name, address, etc.")
subject: str = Field(description="Subject of the quote")
message_introduction: str = Field(description="Introduction message")
operations_table: List[Operation] = Field(description="Operations table with activities and details")
explanation_operations: str = Field(description="Explanation of operations")
deliverables: List[str] = Field(description="Deliverables")
total_price: str = Field(description="Total price")
conditions: str = Field(description="Conditions")
conclusion: str = Field(description="Conclusion")
closing: str = Field(description="Closing")
@tool()
def fill_in_content_tool(tag_name: str, content: str) -> None:
""" Fills in the content of a tag in the document """
print(f"Filling content for {tag_name} with {content}")
@tool()
def create_table_tool(tag_name: str, data: list) -> None:
""" Creates a table in the document """
print(f"Creating table for {tag_name} with data {data}")
Define the state with a messages key
class DocumentState(MessagesState):
quote: str
docx_content: dict
is_done: bool
Define the functions for each node
def start_node(state: DocumentState) -> DocumentState:
return {"messages": state["messages"]}
quote_llm_instructions = """
Create a quote for a client. Include the following sections:
receiver_information:
subject:
message_introduction:
operations_table:
explanation_operations:
deliverables:
total_price:
conditions:
conclusion:
closing:
if you can not provide the information fill in no information
"""
def fill_quote_node(state: DocumentState) -> DocumentState:
quote_llm = model.with_structured_output(Quote)
def preview_node(state: DocumentState) -> DocumentState:
"""Preview of the document"""
def ask_feedback_node(state: DocumentState) -> str:
feedback = input("Do you want to modify the content? (yes/no): ")
if "it's ok" in feedback.lower():
return "generate_document_node"
else:
# InvalidUpdateError: Must write to at least one of ['messages', 'quote', 'docx_content', 'is_done']
feedback: str = input("Please provide feedback: ")
return { "modify_content_node": feedback}
def modify_content_node(state: DocumentState) -> DocumentState:
feedback = state["messages"][-1].content
fill_in_content_tool("tag_name", f"Modified content based on feedback: {feedback}")
return {"docx_content": f"Modified content based on feedback: {feedback}"}
def generate_document_node(state: DocumentState) -> DocumentState:
return {"docx_content": "Final document", "download_url": "http://example.com/download"}
Create the graph
graph = StateGraph(DocumentState)
graph.add_node("start_node", start_node)
graph.add_node("fill_quote_node", fill_quote_node)
graph.add_node("preview_node", preview_node)
graph.add_node("ask_feedback_node", ask_feedback_node)
graph.add_node("modify_content_node", modify_content_node)
graph.add_node("generate_document_node", generate_document_node)
Define the edges
graph.set_entry_point("start_node")
graph.add_edge("start_node", "fill_quote_node")
graph.add_edge("fill_quote_node", "preview_node")
graph.add_edge("preview_node", "ask_feedback_node")
graph.add_conditional_edges("ask_feedback_node", ask_feedback_node, {"generate_document_node": "generate_document_node", "modify_content_node": "modify_content_node"})
graph.add_edge("modify_content_node", "preview_node")
graph.add_edge("generate_document_node", END)
Compile the graph
app = graph.compile()
display(Image(app.get_graph().draw_mermaid_png()))
input_message = HumanMessage(
content="""Client: John Doe
XYZ Corporation
123 Main Street
12345 City
Assignment: Conducting a pilot project to develop a model for liquidity forecasting for XYZ Treasury. For this pilot, we will use ABC Company as the test case. The modeling will be based on liquidity forecast data provided in PDF format, with a monthly frequency.
Deliverable: An oral report of our findings regarding the feasibility and quality of liquidity forecasting using Machine Learning models.
Tasks:
Process data from PDFs
Develop a forecasting model
Fine-tune and optimize the model
Write and present the report
Price: 5500
""")
for event in app.stream({"messages": [input_message]}, stream_mode="values"):
print(event)
`
Beta Was this translation helpful? Give feedback.
All reactions