isayahc commited on
Commit
0616e1d
1 Parent(s): c605fcf

attempt to interface langcnain and weaviate

Browse files
Files changed (2) hide show
  1. chain_weaviate.py +67 -0
  2. weaviate_utils.py +13 -9
chain_weaviate.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # goal: store results from app.py into vector store
2
+
3
+ from structured_apparatus_chain import (
4
+ arxiv_chain as apparatus_arxiv_chain,
5
+ pub_med_chain as apparatus_pub_med_chain,
6
+ wikipedia_chain as apparatus_wikipedia_chain
7
+ )
8
+ from structured_experiment_chain import (
9
+ arxiv_chain as experiment_arxiv_chain,
10
+ pub_med_chain as experiment_pub_med_chain,
11
+ wikipedia_chain as experiment_wikipedia_chain
12
+ )
13
+
14
+ from weaviate_utils import init_client
15
+
16
+ from datetime import datetime, timezone
17
+
18
+
19
+
20
+
21
+ def main():
22
+ exp_qury = "fabricating cellolouse based electronics"
23
+ exp_qury = "fabrication of spider silk"
24
+ # app_query = "microscope"
25
+ # app_data = apparatus_arxiv_chain.invoke(app_query)
26
+ exp_data = experiment_arxiv_chain.invoke(exp_qury)
27
+
28
+ weaviate_client = init_client()
29
+
30
+ component_collection = weaviate_client.collections.get("Component")
31
+ component_image_collection = weaviate_client.collections.get("ComponentImage")
32
+ science_experiment_collection = weaviate_client.collections.get("ScienceEperiment")
33
+
34
+
35
+ exp_uuid = science_experiment_collection.data.insert({
36
+ "DateCreated": datetime.now(timezone.utc),
37
+ "FieldsOfStudy": exp_data['Fields_of_study'],
38
+ "Tags": exp_data['Fields_of_study'],
39
+ "Experiment_Name": exp_data['Experiment_Name'],
40
+ "Material": exp_data['Material'],
41
+ "Sources": exp_data['Sources'],
42
+ "Protocal": exp_data['Protocal'],
43
+ "Purpose_of_Experiments": exp_data['Purpose_of_Experiments'],
44
+ "Safety_Precaution": exp_data['Safety_Precuation'], # Corrected spelling mistake
45
+ "Level_of_Difficulty": exp_data['Level_of_Difficulty'],
46
+ })
47
+
48
+ jj = science_experiment_collection.query.near_text(
49
+ query="biology",
50
+ limit=2
51
+ )
52
+
53
+
54
+
55
+ # uuid = component_collection.data.insert({
56
+ # "DateCreated" : datetime.now(timezone.utc),
57
+ # "UsedInComps" : [query],
58
+ # "ToolName" : shap_e_sample,
59
+ # "Tags" : shap_e_list,
60
+ # "feildsOfStudy" : shap_e_list,
61
+ # # "GlbBlob" : base_64_result,
62
+ # })
63
+
64
+ x = 0
65
+
66
+ if __name__ == '__main__':
67
+ main()
weaviate_utils.py CHANGED
@@ -52,18 +52,22 @@ def main() :
52
  try:
53
  client = init_client()
54
  client.collections.create(
55
- name="ScienceEperiment",
56
  description="Science Experiment with the goal of making something",
57
  vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
58
  properties=[
59
- # wvc.config.Property(name="id", data_type=wvc.config.DataType.UUID),
60
- wvc.config.Property(name="DateCreated", data_type=wvc.config.DataType.DATE),
61
- wvc.config.Property(name="UsedInComps", data_type=wvc.config.DataType.TEXT_ARRAY),
62
- wvc.config.Property(name="FeildsOfStudy", data_type=wvc.config.DataType.TEXT_ARRAY),
63
- wvc.config.Property(name="ToolName", data_type=wvc.config.DataType.TEXT),
64
- wvc.config.Property(name="Tags", data_type=wvc.config.DataType.TEXT_ARRAY),
65
- ]
66
- )
 
 
 
 
67
  finally:
68
  client.close()
69
 
 
52
  try:
53
  client = init_client()
54
  client.collections.create(
55
+ name="ScienceExperiment",
56
  description="Science Experiment with the goal of making something",
57
  vectorizer_config=wvc.config.Configure.Vectorizer.text2vec_openai(),
58
  properties=[
59
+ wvc.config.Property(name="DateCreated", data_type=wvc.config.DataType.DATE),
60
+ wvc.config.Property(name="UsedInComps", data_type=wvc.config.DataType.TEXT_ARRAY),
61
+ wvc.config.Property(name="FieldsOfStudy", data_type=wvc.config.DataType.TEXT_ARRAY),
62
+ wvc.config.Property(name="Experiment_Name", data_type=wvc.config.DataType.TEXT),
63
+ wvc.config.Property(name="Material", data_type=wvc.config.DataType.TEXT_ARRAY),
64
+ wvc.config.Property(name="Sources", data_type=wvc.config.DataType.TEXT_ARRAY),
65
+ wvc.config.Property(name="Protocal", data_type=wvc.config.DataType.TEXT_ARRAY),
66
+ wvc.config.Property(name="Purpose_of_Experiments", data_type=wvc.config.DataType.TEXT),
67
+ wvc.config.Property(name="Safety_Precaution", data_type=wvc.config.DataType.TEXT),
68
+ wvc.config.Property(name="Level_of_Difficulty", data_type=wvc.config.DataType.TEXT),
69
+ ]
70
+ )
71
  finally:
72
  client.close()
73