jonathanjordan21 commited on
Commit
20469f9
·
verified ·
1 Parent(s): 67ae0f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -11,6 +11,12 @@ from uuid import uuid4
11
 
12
  from langchain_core.documents import Document
13
 
 
 
 
 
 
 
14
  document_1 = Document(
15
  page_content="I had chocolate chip pancakes and scrambled eggs for breakfast this morning.",
16
  metadata={"source": "tweet"},
@@ -120,6 +126,18 @@ def get_data(query: str):
120
  }
121
 
122
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  @app.get("/")
124
  def greet_json():
125
  return {"Hello": "World!"}
 
11
 
12
  from langchain_core.documents import Document
13
 
14
+ from typing import Union, List, Dict, Any
15
+ from pydantic import BaseModel, Field
16
+
17
+ class Data(BaseModel):
18
+ items: Union[Dict[str, Any], List[Dict[str, Any]]] = Field(..., description="Either a dictionary or a list of dictionaries.")
19
+
20
  document_1 = Document(
21
  page_content="I had chocolate chip pancakes and scrambled eggs for breakfast this morning.",
22
  metadata={"source": "tweet"},
 
126
  }
127
 
128
 
129
+ @app.post("/add_data")
130
+ def add_data(data: Data):
131
+ global qdrant
132
+ if isinstance(data.items, dict):
133
+ qdrant.add_documents(documents=[Document(**data.items)])
134
+ else:
135
+ qdrant.add_documents(documents=[Document(**x.items) for x in data])
136
+
137
+ return {"message":"Create data successfully!", "status_code":201}
138
+
139
+
140
+
141
  @app.get("/")
142
  def greet_json():
143
  return {"Hello": "World!"}