From c34a45ac147fcb98eea1204088e2a524f15b2261 Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Sun, 11 Feb 2024 22:08:04 +0100 Subject: [PATCH 1/3] added a few updates for easier running in local --- api.py | 49 +++++++++++------- .../database/graph_database/graph.py | 2 +- .../crud_test.cpython-311-pytest-7.4.0.pyc | Bin 4301 -> 0 bytes ...emantic_tests.cpython-311-pytest-7.4.0.pyc | Bin 2291 -> 0 bytes main.py | 4 +- 5 files changed, 34 insertions(+), 21 deletions(-) delete mode 100644 level_2/tests/__pycache__/crud_test.cpython-311-pytest-7.4.0.pyc delete mode 100644 level_2/tests/__pycache__/semantic_tests.cpython-311-pytest-7.4.0.pyc diff --git a/api.py b/api.py index c4e24e13b..90273c39e 100644 --- a/api.py +++ b/api.py @@ -24,7 +24,6 @@ logger = logging.getLogger(__name__) - load_dotenv() OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "") app = FastAPI(debug=True) @@ -36,10 +35,10 @@ from fastapi import Depends - config = Config() config.load() + class ImageResponse(BaseModel): success: bool message: str @@ -66,10 +65,11 @@ def health_check(): class Payload(BaseModel): payload: Dict[str, Any] + @app.post("/add-memory", response_model=dict) async def add_memory( - payload: Payload, - # files: List[UploadFile] = File(...), + payload: Payload, + # files: List[UploadFile] = File(...), ): try: logging.info(" Adding to Memory ") @@ -87,7 +87,8 @@ async def add_memory( else: content = None - output = await load_documents_to_vectorstore(session, decoded_payload['user_id'], content=content, loader_settings=settings_for_loader) + output = await load_documents_to_vectorstore(session, decoded_payload['user_id'], content=content, + loader_settings=settings_for_loader) return JSONResponse(content={"response": output}, status_code=200) except Exception as e: @@ -95,10 +96,11 @@ async def add_memory( content={"response": {"error": str(e)}}, status_code=503 ) + @app.post("/add-architecture-public-memory", response_model=dict) async def add_memory( - payload: Payload, - # files: List[UploadFile] = File(...), + payload: Payload, + # files: List[UploadFile] = File(...), ): try: logging.info(" Adding to Memory ") @@ -117,7 +119,8 @@ async def add_memory( "path": [".data"] } - output = await load_documents_to_vectorstore(session, user_id=user_id, content=content, loader_settings=loader_settings) + output = await load_documents_to_vectorstore(session, user_id=user_id, content=content, + loader_settings=loader_settings) return JSONResponse(content={"response": output}, status_code=200) except Exception as e: @@ -125,6 +128,7 @@ async def add_memory( content={"response": {"error": str(e)}}, status_code=503 ) + @app.post("/user-query-to-graph") async def user_query_to_graph(payload: Payload): try: @@ -133,7 +137,8 @@ async def user_query_to_graph(payload: Payload): # Execute the query - replace this with the actual execution method async with session_scope(session=AsyncSessionLocal()) as session: # Assuming you have a method in Neo4jGraphDB to execute the query - result = await user_query_to_graph_db(session= session, user_id= decoded_payload['user_id'],query_input =decoded_payload['query']) + result = await user_query_to_graph_db(session=session, user_id=decoded_payload['user_id'], + query_input=decoded_payload['query']) return result @@ -155,18 +160,23 @@ async def document_to_graph_db(payload: Payload): else: memory_type = None async with session_scope(session=AsyncSessionLocal()) as session: - result = await add_documents_to_graph_db(session =session, user_id = decoded_payload['user_id'], document_memory_types =memory_type) + result = await add_documents_to_graph_db(session=session, user_id=decoded_payload['user_id'], + document_memory_types=memory_type) return result except Exception as e: raise HTTPException(status_code=500, detail=str(e)) + @app.post("/cognitive-context-enrichment") async def cognitive_context_enrichment(payload: Payload): try: decoded_payload = payload.payload async with session_scope(session=AsyncSessionLocal()) as session: - result = await user_context_enrichment(session, user_id = decoded_payload['user_id'], query= decoded_payload['query'], generative_response=decoded_payload['generative_response'], memory_type= decoded_payload['memory_type']) + result = await user_context_enrichment(session, user_id=decoded_payload['user_id'], + query=decoded_payload['query'], + generative_response=decoded_payload['generative_response'], + memory_type=decoded_payload['memory_type']) return JSONResponse(content={"response": result}, status_code=200) except Exception as e: @@ -179,7 +189,8 @@ async def classify_user_query(payload: Payload): decoded_payload = payload.payload async with session_scope(session=AsyncSessionLocal()) as session: from main import relevance_feedback - result = await relevance_feedback( query= decoded_payload['query'], input_type=decoded_payload['knowledge_type']) + result = await relevance_feedback(query=decoded_payload['query'], + input_type=decoded_payload['knowledge_type']) return JSONResponse(content={"response": result}, status_code=200) except Exception as e: @@ -202,7 +213,6 @@ async def user_query_classfier(payload: Payload): raise HTTPException(status_code=500, detail=str(e)) - @app.post("/drop-db") async def drop_db(payload: Payload): try: @@ -210,7 +220,7 @@ async def drop_db(payload: Payload): if decoded_payload['operation'] == 'drop': - if os.environ.get('AWS_ENV') == 'dev': + if os.environ.get('AWS_ENV') == 'dev': host = os.environ.get('POSTGRES_HOST') username = os.environ.get('POSTGRES_USER') password = os.environ.get('POSTGRES_PASSWORD') @@ -237,7 +247,7 @@ async def drop_db(payload: Payload): engine = create_admin_engine(username, password, host, database_name) create_database(engine) - return JSONResponse(content={"response": " DB created"}, status_code=200) + return JSONResponse(content={"response": " DB drop"}, status_code=200) @@ -268,7 +278,7 @@ async def create_public_memory(payload: Payload): # Execute the query - replace this with the actual execution method # async with session_scope(session=AsyncSessionLocal()) as session: # from main import create_public_memory - # Assuming you have a method in Neo4jGraphDB to execute the query + # Assuming you have a method in Neo4jGraphDB to execute the query result = await create_public_memory(user_id=user_id, labels=labels, topic=topic) return JSONResponse(content={"response": result}, status_code=200) @@ -295,12 +305,13 @@ async def attach_user_to_public_memory(payload: Payload): from main import attach_user_to_memory, create_public_memory # Assuming you have a method in Neo4jGraphDB to execute the query await create_public_memory(user_id=decoded_payload['user_id'], topic=topic, labels=labels) - result = await attach_user_to_memory( user_id = decoded_payload['user_id'], topic=topic, labels=labels) + result = await attach_user_to_memory(user_id=decoded_payload['user_id'], topic=topic, labels=labels) return JSONResponse(content={"response": result}, status_code=200) except Exception as e: raise HTTPException(status_code=500, detail=str(e)) + @app.post("/unlink-user-from-public-memory") async def unlink_user_from_public_memory(payload: Payload): try: @@ -315,12 +326,14 @@ async def unlink_user_from_public_memory(payload: Payload): async with session_scope(session=AsyncSessionLocal()) as session: from main import unlink_user_from_memory # Assuming you have a method in Neo4jGraphDB to execute the query - result = await unlink_user_from_memory( user_id = decoded_payload['user_id'], topic=topic, labels=decoded_payload['labels']) + result = await unlink_user_from_memory(user_id=decoded_payload['user_id'], topic=topic, + labels=decoded_payload['labels']) return JSONResponse(content={"response": result}, status_code=200) except Exception as e: raise HTTPException(status_code=500, detail=str(e)) + def start_api_server(host: str = "0.0.0.0", port: int = 8000): """ Start the API server using uvicorn. diff --git a/cognitive_architecture/database/graph_database/graph.py b/cognitive_architecture/database/graph_database/graph.py index 6ee32d53f..60770484f 100644 --- a/cognitive_architecture/database/graph_database/graph.py +++ b/cognitive_architecture/database/graph_database/graph.py @@ -560,7 +560,7 @@ def create_document_node_cypher(self, document_summary: dict, user_id: str, summary: '{summary}', documentCategory: '{document_category}', d_id: '{d_id}', - created_at: timestamp(), + created_at: timestamp() }}) // Link the Document node to the {memory_node_type} node diff --git a/level_2/tests/__pycache__/crud_test.cpython-311-pytest-7.4.0.pyc b/level_2/tests/__pycache__/crud_test.cpython-311-pytest-7.4.0.pyc deleted file mode 100644 index e540734a9b419ee4bf52515005424c9581ad8bfb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4301 zcmds4O>7%Q6rTODy>T{4<0dY}203XAn6?fLG*F;{5@?Bv)2eNdFok97-B73gV|JaA zkVpn18W0jlfWm=;4^?PY4hSK{vEo!D4(n*8SSwYE#HHMf!U1vO&8&B0I{^YhfS8?q z`{w7pH}huRH#?tpboddZZ_nORyd4OAPYO=*)S30~fLTHcQkV=%GW5%4xfIKwET8l+ zc8fRZr7gaskA8)upbArMj2VI zA-$n(%H^BKIfo=V8xTOck5D@)%x5j$f}TV_O>=0qxQ&YXrJdVvP z12g5uE$+b3{oplUQB$#$R$@NOCu=jgR61{UzO3q!I<4k(DU;6^ES^wI=5Kkk)X7!= z7jsfEr>8SgDxWQ6R9&_FR9;Hw(mE*SH8nG-5$8mHd3!6fPxYrEsg_`!NAimqSDh#X$1LZT9pI?nWvJ!oy5B$-@MRP>&CDZ(1H+y_GCar3q0jhb*izTrZS^Ju`fJ>?Xo-7^ zXHb(4w~sq=V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~e>;iy#SZbkT;ei?g@awH$`29pMd=SuK;H3iqK#iXwBC2V= zbWKZliD;o@T99~5w0u%5Yx`J_RxJAmo2ftJkf|9;R;bB|Xxd*Ak;YmKn0<0hry}G+ z61zp>=%yILgcJ$fuMDITH4T<|&woJuXHBTsh2LRWGzXcwhh+A0t}$wGx8Q~w+@%aU z(KKvv|8LYMBd8u~-3Y3OrYncrfvx0*T1Ckn)LBKH71ZgW z$;#p8C5}8uKJ2L+9scFZokXsh$Ze>b@mjo3g45pz--VFWT|udzNCge;prI-nf=LZN zGNol}^@ZG1k$XHPxiRC{*Gk*Q_08!A$^+#G^`W|>q^e4)(rC2^QjP$55Q%>Q>Mnj; diff --git a/main.py b/main.py index abc59520d..826873cc4 100644 --- a/main.py +++ b/main.py @@ -281,7 +281,7 @@ async def add_documents_to_graph_db(session: AsyncSession, user_id: str= None, d logging.info("Retrieval chunks are", retrieval_chunks) classification = await classify_documents(doc_name, document_id =doc_id, content=concatenated_retrievals) - logging.info("Classification is", str(classification)) + logging.info("Classification is %s", str(classification)) neo4j_graph_db = Neo4jGraphDB(url=config.graph_database_url, username=config.graph_database_username, password=config.graph_database_password) if document_memory_types == ['PUBLIC']: @@ -305,7 +305,7 @@ async def add_documents_to_graph_db(session: AsyncSession, user_id: str= None, d else: rs = neo4j_graph_db.create_document_node_cypher(classification, user_id, memory_type='SemanticMemory') neo4j_graph_db.close() - logging.info("Cypher query is", rs) + logging.info("Cypher query is %s", rs) neo4j_graph_db = Neo4jGraphDB(url=config.graph_database_url, username=config.graph_database_username, password=config.graph_database_password) neo4j_graph_db.query(rs) From 98a7d91380b27aaf17e8be5d4eec49390cb33560 Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Sun, 11 Feb 2024 22:11:27 +0100 Subject: [PATCH 2/3] Update main.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 826873cc4..b10220674 100644 --- a/main.py +++ b/main.py @@ -305,7 +305,7 @@ async def add_documents_to_graph_db(session: AsyncSession, user_id: str= None, d else: rs = neo4j_graph_db.create_document_node_cypher(classification, user_id, memory_type='SemanticMemory') neo4j_graph_db.close() - logging.info("Cypher query is %s", rs) + logging.info("Cypher query is %s", str(rs)) neo4j_graph_db = Neo4jGraphDB(url=config.graph_database_url, username=config.graph_database_username, password=config.graph_database_password) neo4j_graph_db.query(rs) From 40468236f275e6af09e092cc609796bb783406de Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Sun, 11 Feb 2024 22:12:00 +0100 Subject: [PATCH 3/3] Update api.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- api.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 90273c39e..48a7f6c21 100644 --- a/api.py +++ b/api.py @@ -38,7 +38,13 @@ config = Config() config.load() - +@app.get( + "/", +) +""" +Root endpoint that returns a welcome message. +""" +async def root(): class ImageResponse(BaseModel): success: bool message: str