Omkar008 commited on
Commit
e9e4739
·
verified ·
1 Parent(s): 02f2517

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -6
main.py CHANGED
@@ -51,6 +51,9 @@ class QueryInput(BaseModel):
51
  query: str
52
  index_name: str
53
 
 
 
 
54
  @app.get("/")
55
  async def test():
56
  return {"Message":"Application is working !!"}
@@ -114,15 +117,13 @@ async def query_index(query_input: QueryInput):
114
  return {"response": response.response}
115
 
116
  @app.delete("/delete_index/")
117
- async def delete_index():
118
- if not state["index_created"]:
119
- raise HTTPException(status_code=400, detail="Index not created")
 
120
 
121
  pc = Pinecone(api_key=pinecone_api_key)
122
- index_name = "demo-index-2"
123
  pc.delete_index(index_name)
124
- state["index_created"] = False
125
- state["vector_store"] = None
126
 
127
  return {"message": "Index deleted successfully"}
128
 
 
51
  query: str
52
  index_name: str
53
 
54
+ class delete_index(BaseModel):
55
+ index_name:str
56
+
57
  @app.get("/")
58
  async def test():
59
  return {"Message":"Application is working !!"}
 
117
  return {"response": response.response}
118
 
119
  @app.delete("/delete_index/")
120
+ async def delete_index(delete_input:delete_index):
121
+ index_name = delete_input.index_name
122
+ if index_name not in pc.list_indexes().names():
123
+ return {"message":"Index is not already present to delete it !"}
124
 
125
  pc = Pinecone(api_key=pinecone_api_key)
 
126
  pc.delete_index(index_name)
 
 
127
 
128
  return {"message": "Index deleted successfully"}
129