-
POST Request: The client sends a POST request to
/querywith a JSON payload that includes:session_idtext
Example Payload:
{"session_id": "user123", "text": "My laptop won’t turn on"} -
Validation: The
Querymodel inmodels.pyvalidates the input.
- Session Handling:
persistence.pyeither loads the current session state or initializes a new one. - History Update: The submitted query is appended to the session’s history.
The workflow.py module executes the LangGraph graph through the following steps:
- Query Ingestion: Adds the query to the state.
- NLP Processing: Invokes
groq_client.pyto extract structured information (e.g., issue, priority). - Decision Making: Determines whether to auto-respond or escalate the query based on its priority/urgency.
- Response Generation: Constructs a response based on the decision made.
- State Saving: The updated state is saved.
- Client Response: The final response is returned to the client as a
Responseobject.
Run the following command in your terminal:
pip install fastapi uvicorn groq langgraph pydantic- Open
config.py - Replace
"your_groq_api_key"with your actual Groq API key.
Start the app by executing:
python app.pySend a test POST request using curl:
curl -X POST "http://localhost:8000/query" \
-H "Content-Type: application/json" \
-d '{"session_id": "user123", "text": "My laptop won’t turn on after I updated it yesterday."}'The expected JSON response should appear as follows:
{
"response": "We have identified your issue as 'won’t turn on'. Please try this solution: [Solution Placeholder]"
}