-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,033 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,15 @@ | ||
from fastapi import FastAPI, HTTPException | ||
from pydantic import BaseModel | ||
from neo4j import GraphDatabase | ||
|
||
app = FastAPI() | ||
|
||
# Neo4j driver initialization | ||
uri = "bolt://localhost:7687" # Change to your Neo4j URI | ||
user = "neo4j" # Change to your Neo4j username | ||
password = "12345678" # Change to your Neo4j password | ||
driver = GraphDatabase.driver(uri, auth=(user, password)) | ||
|
||
class Node(BaseModel): | ||
label: str | ||
properties: dict | ||
|
||
def create_node_in_neo4j(label: str, properties: dict): | ||
query = f"CREATE (n:{label}) set n= $properties RETURN n" | ||
with driver.session() as session: | ||
x={"properties":properties} | ||
result = session.run(query, x) | ||
return result.single() | ||
|
||
@app.post("/nodes/") | ||
async def create_node(node: Node): | ||
try: | ||
result = create_node_in_neo4j(node.label, node.properties) | ||
if result: | ||
return {"message": "Node created successfully", "node": result["n"]} | ||
else: | ||
raise HTTPException(status_code=400, detail="Node creation failed") | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) | ||
|
||
if __name__ == "__main__": | ||
import uvicorn | ||
uvicorn.run(app, host="0.0.0.0", port=8000) | ||
from langchain_community.document_loaders.recursive_url_loader import RecursiveUrlLoader | ||
from bs4 import BeautifulSoup as Soup | ||
import io | ||
|
||
url="https://docs.llamaindex.ai/en/stable/" | ||
loader=RecursiveUrlLoader(url=url, | ||
max_depth=1000, | ||
extractor=lambda x:Soup(x,"html.parser").text | ||
) | ||
docs=loader.load() | ||
print(docs) | ||
with io.open("url.txt","w",encoding="utf-8")as f1: | ||
for doc in docs: | ||
f1.write(doc.metadata["source"]+"\n") | ||
f1.close() |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.