CodeMode Agent commited on
Commit
e5c403f
·
1 Parent(s): 0498daa

Deploy CodeMode via Agent

Browse files
Files changed (1) hide show
  1. app.py +30 -20
app.py CHANGED
@@ -143,23 +143,28 @@ def get_chunks_for_file_baseline(file_name):
143
  return {"error": "No file selected"}
144
 
145
  try:
 
146
  data = baseline_collection.get(
147
- where={"file_name": file_name},
148
  include=["documents", "metadatas", "embeddings"]
149
  )
150
 
151
  if not data['documents']:
152
- return {"error": "No chunks found for this file"}
153
 
 
154
  chunks = []
155
- for i, (doc, meta) in enumerate(zip(data['documents'], data['metadatas'])):
156
- chunks.append({
157
- "chunk_id": i + 1,
158
- "content": doc[:500] + "..." if len(doc) > 500 else doc,
159
- "full_length": len(doc),
160
- "metadata": meta,
161
- "embedding_dim": len(data['embeddings'][i]) if data['embeddings'] else 0
162
- })
 
 
 
 
163
 
164
  return {
165
  "file_name": file_name,
@@ -175,23 +180,28 @@ def get_chunks_for_file_finetuned(file_name):
175
  return {"error": "No file selected"}
176
 
177
  try:
 
178
  data = finetuned_collection.get(
179
- where={"file_name": file_name},
180
  include=["documents", "metadatas", "embeddings"]
181
  )
182
 
183
  if not data['documents']:
184
- return {"error": "No chunks found for this file"}
185
 
 
186
  chunks = []
187
- for i, (doc, meta) in enumerate(zip(data['documents'], data['metadatas'])):
188
- chunks.append({
189
- "chunk_id": i + 1,
190
- "content": doc[:500] + "..." if len(doc) > 500 else doc,
191
- "full_length": len(doc),
192
- "metadata": meta,
193
- "embedding_dim": len(data['embeddings'][i]) if data['embeddings'] else 0
194
- })
 
 
 
 
195
 
196
  return {
197
  "file_name": file_name,
 
143
  return {"error": "No file selected"}
144
 
145
  try:
146
+ # Get all data and filter in Python
147
  data = baseline_collection.get(
 
148
  include=["documents", "metadatas", "embeddings"]
149
  )
150
 
151
  if not data['documents']:
152
+ return {"error": "No chunks found"}
153
 
154
+ # Filter by file_name in Python
155
  chunks = []
156
+ for i, (doc, meta, emb) in enumerate(zip(data['documents'], data['metadatas'], data['embeddings'])):
157
+ if meta.get("file_name") == file_name:
158
+ chunks.append({
159
+ "chunk_id": len(chunks) + 1,
160
+ "content": doc[:500] + "..." if len(doc) > 500 else doc,
161
+ "full_length": len(doc),
162
+ "metadata": meta,
163
+ "embedding_dim": len(emb) if emb else 0
164
+ })
165
+
166
+ if not chunks:
167
+ return {"error": "No chunks found for this file"}
168
 
169
  return {
170
  "file_name": file_name,
 
180
  return {"error": "No file selected"}
181
 
182
  try:
183
+ # Get all data and filter in Python
184
  data = finetuned_collection.get(
 
185
  include=["documents", "metadatas", "embeddings"]
186
  )
187
 
188
  if not data['documents']:
189
+ return {"error": "No chunks found"}
190
 
191
+ # Filter by file_name in Python
192
  chunks = []
193
+ for i, (doc, meta, emb) in enumerate(zip(data['documents'], data['metadatas'], data['embeddings'])):
194
+ if meta.get("file_name") == file_name:
195
+ chunks.append({
196
+ "chunk_id": len(chunks) + 1,
197
+ "content": doc[:500] + "..." if len(doc) > 500 else doc,
198
+ "full_length": len(doc),
199
+ "metadata": meta,
200
+ "embedding_dim": len(emb) if emb else 0
201
+ })
202
+
203
+ if not chunks:
204
+ return {"error": "No chunks found for this file"}
205
 
206
  return {
207
  "file_name": file_name,