Tonic commited on
Commit
c3375be
·
1 Parent(s): ce4129b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -69,11 +69,35 @@ Article = {
69
  # "vectorizer": "text2vec-contextionary"
70
  }
71
 
72
-
 
 
 
 
 
 
 
 
73
  schema = {
74
  "classes": [Article]
75
  }
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  # Initialize vectorstore
78
  vectorstore = Weaviate(client, index_name="HereChat", text_key="text")
79
  client.schema.create(schema)
 
69
  # "vectorizer": "text2vec-contextionary"
70
  }
71
 
72
+ # Function to check if a class exists in the schema
73
+ def class_exists(class_name):
74
+ try:
75
+ return client.schema.contains_class(class_name)
76
+ except Exception as e:
77
+ print(f"Error checking if class exists: {e}")
78
+ return False
79
+
80
+ # Initialize the schema
81
  schema = {
82
  "classes": [Article]
83
  }
84
 
85
+ # Check if 'Article' class already exists
86
+ if not class_exists("Article"):
87
+ # Create the schema if 'Article' class does not exist
88
+ try:
89
+ client.schema.create(schema)
90
+ except Exception as e:
91
+ print(f"Error creating schema: {e}")
92
+ else:
93
+ # Retrieve the existing schema if 'Article' class exists
94
+ try:
95
+ existing_schema = client.schema.get()
96
+ print("Existing schema retrieved:", existing_schema)
97
+ except Exception as e:
98
+ print(f"Error retrieving existing schema: {e}")
99
+
100
+
101
  # Initialize vectorstore
102
  vectorstore = Weaviate(client, index_name="HereChat", text_key="text")
103
  client.schema.create(schema)