Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulrahman305 committed Oct 28, 2024
1 parent 6557a09 commit 7965b8a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,38 @@ To make this repository self-bootable using the PXE server, follow these steps:
5. Once the PXE server is running and your devices are configured to boot from it, you should be able to boot your devices using the PXE server.
For more information on configuring and using the PXE server, refer to the documentation of the `node-js-pxe-server` repository: https://github.com/abdulrahman305/node-js-pxe-server
## Update Functionality
The repository now includes functionality to update data in the Neo4j database. The update functionality is implemented in the `api.py` file and can be accessed via the `/update` endpoint.
### Update Endpoint
The `/update` endpoint allows you to update data in the Neo4j database. The endpoint expects a JSON request body with the following structure:
```json
{
"id": "node_id",
"data": {
"property1": "value1",
"property2": "value2",
...
}
}
```

### Example Usage

To update a node in the Neo4j database, send a `POST` request to the `/update` endpoint with the JSON request body. Here is an example using `curl`:

```bash
curl -X POST http://localhost:8504/update -H "Content-Type: application/json" -d '{
"id": "node_id",
"data": {
"property1": "value1",
"property2": "value2"
}
}'
```

This will update the node with the specified `id` in the Neo4j database with the provided data.
12 changes: 12 additions & 0 deletions api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from utils import (
create_vector_index,
BaseLogger,
update_data
)
from chains import (
load_embedding_model,
Expand Down Expand Up @@ -117,6 +118,11 @@ class BaseTicket(BaseModel):
text: str


class UpdateData(BaseModel):
id: str
data: dict


@app.get("/query-stream")
def qstream(question: Question = Depends()):
output_function = llm_chain
Expand Down Expand Up @@ -159,3 +165,9 @@ async def generate_ticket_api(question: BaseTicket = Depends()):
input_question=question.text,
)
return {"result": {"title": new_title, "text": new_question}, "model": llm_name}


@app.post("/update")
async def update(update_data: UpdateData):
update_data(neo4j_graph, update_data.id, update_data.data)
return {"message": "Data updated successfully"}
8 changes: 8 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ def create_constraints(driver):
driver.query(
"CREATE CONSTRAINT tag_name IF NOT EXISTS FOR (t:Tag) REQUIRE (t.name) IS UNIQUE"
)


def update_data(driver, node_id: str, data: dict) -> None:
update_query = """
MATCH (n {id: $node_id})
SET n += $data
"""
driver.query(update_query, {"node_id": node_id, "data": data})

0 comments on commit 7965b8a

Please sign in to comment.