akseljoonas HF Staff commited on
Commit
1dec1c0
·
1 Parent(s): 8b2c9e3

Show file contents in hf_repo_files approval request

Browse files
Files changed (1) hide show
  1. agent/main.py +47 -0
agent/main.py CHANGED
@@ -287,6 +287,53 @@ async def event_listener(
287
  if len(all_lines) > 5:
288
  print("...")
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  # Get user decision for this item
291
  response = await prompt_session.prompt_async(
292
  f"Approve item {i}? (y=yes, yolo=approve all, n=no, or provide feedback): "
 
287
  if len(all_lines) > 5:
288
  print("...")
289
 
290
+ elif tool_name == "hf_repo_files":
291
+ # Handle repo files operations (upload, delete)
292
+ repo_id = arguments.get("repo_id", "")
293
+ repo_type = arguments.get("repo_type", "model")
294
+ revision = arguments.get("revision", "main")
295
+
296
+ # Build repo URL
297
+ if repo_type == "model":
298
+ repo_url = f"https://huggingface.co/{repo_id}"
299
+ else:
300
+ repo_url = f"https://huggingface.co/{repo_type}s/{repo_id}"
301
+
302
+ print(f"Repository: {repo_id}")
303
+ print(f"Type: {repo_type}")
304
+ print(f"Branch: {revision}")
305
+ print(f"URL: {repo_url}")
306
+
307
+ if operation == "upload":
308
+ path = arguments.get("path", "")
309
+ content = arguments.get("content", "")
310
+ create_pr = arguments.get("create_pr", False)
311
+
312
+ print(f"File: {path}")
313
+ if create_pr:
314
+ print("Mode: Create PR")
315
+
316
+ if isinstance(content, str):
317
+ all_lines = content.split("\n")
318
+ line_count = len(all_lines)
319
+ size_bytes = len(content.encode("utf-8"))
320
+ size_kb = size_bytes / 1024
321
+
322
+ print(f"Lines: {line_count}")
323
+ if size_kb < 1024:
324
+ print(f"Size: {size_kb:.2f} KB")
325
+ else:
326
+ print(f"Size: {size_kb / 1024:.2f} MB")
327
+
328
+ # Show full content
329
+ print(f"Content:\n{content}")
330
+
331
+ elif operation == "delete":
332
+ patterns = arguments.get("patterns", [])
333
+ if isinstance(patterns, str):
334
+ patterns = [patterns]
335
+ print(f"Patterns to delete: {', '.join(patterns)}")
336
+
337
  # Get user decision for this item
338
  response = await prompt_session.prompt_async(
339
  f"Approve item {i}? (y=yes, yolo=approve all, n=no, or provide feedback): "