Spaces:
Runtime error
Runtime error
Commit
·
b6743fd
1
Parent(s):
13e710f
task: updates design_rag with doc args, removed css
Browse files- src/chains/design_rag.py +8 -5
src/chains/design_rag.py
CHANGED
@@ -29,8 +29,8 @@ class DesignRAG:
|
|
29 |
"""Create FAISS vector store from design metadata"""
|
30 |
try:
|
31 |
# Update path to look in data/designs
|
32 |
-
designs_dir = Path("data/designs"
|
33 |
-
|
34 |
documents = []
|
35 |
|
36 |
# Load all metadata files
|
@@ -48,12 +48,14 @@ class DesignRAG:
|
|
48 |
"""
|
49 |
|
50 |
# Load associated CSS
|
|
|
51 |
css_path = design_dir.parent / "style.css"
|
52 |
if css_path.exists():
|
53 |
with open(css_path, "r") as f:
|
54 |
css = f.read()
|
55 |
text += f"\nCSS:\n{css}"
|
56 |
-
|
|
|
57 |
# Create Document object with minimal metadata
|
58 |
documents.append(
|
59 |
Document(
|
@@ -76,13 +78,14 @@ class DesignRAG:
|
|
76 |
self.embeddings
|
77 |
)
|
78 |
|
|
|
79 |
# Create and return vector store
|
80 |
return FAISS.from_documents(documents, self.embeddings)
|
81 |
except Exception as e:
|
82 |
print(f"Error creating vector store: {str(e)}")
|
83 |
raise
|
84 |
|
85 |
-
async def query_similar_designs(self, requirements: Dict) -> str:
|
86 |
"""Find similar designs based on requirements"""
|
87 |
# Create search query from requirements
|
88 |
query = f"""
|
@@ -94,7 +97,7 @@ class DesignRAG:
|
|
94 |
"""
|
95 |
|
96 |
# Get similar documents
|
97 |
-
docs = await self.retriever.get_relevant_documents(query)
|
98 |
|
99 |
# Format examples
|
100 |
examples = []
|
|
|
29 |
"""Create FAISS vector store from design metadata"""
|
30 |
try:
|
31 |
# Update path to look in data/designs
|
32 |
+
designs_dir = Path(__file__).parent.parent / "data" / "designs"
|
33 |
+
|
34 |
documents = []
|
35 |
|
36 |
# Load all metadata files
|
|
|
48 |
"""
|
49 |
|
50 |
# Load associated CSS
|
51 |
+
'''
|
52 |
css_path = design_dir.parent / "style.css"
|
53 |
if css_path.exists():
|
54 |
with open(css_path, "r") as f:
|
55 |
css = f.read()
|
56 |
text += f"\nCSS:\n{css}"
|
57 |
+
'''
|
58 |
+
|
59 |
# Create Document object with minimal metadata
|
60 |
documents.append(
|
61 |
Document(
|
|
|
78 |
self.embeddings
|
79 |
)
|
80 |
|
81 |
+
print(f"Loaded {len(documents)} design documents")
|
82 |
# Create and return vector store
|
83 |
return FAISS.from_documents(documents, self.embeddings)
|
84 |
except Exception as e:
|
85 |
print(f"Error creating vector store: {str(e)}")
|
86 |
raise
|
87 |
|
88 |
+
async def query_similar_designs(self, requirements: Dict, num_examples: int = 5) -> str:
|
89 |
"""Find similar designs based on requirements"""
|
90 |
# Create search query from requirements
|
91 |
query = f"""
|
|
|
97 |
"""
|
98 |
|
99 |
# Get similar documents
|
100 |
+
docs = await self.retriever.get_relevant_documents(query, k=num_examples)
|
101 |
|
102 |
# Format examples
|
103 |
examples = []
|