tao-shen commited on
Commit
03b9c12
·
verified ·
1 Parent(s): 5d48f4e

Upload scripts/sync.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/sync.py +39 -6
scripts/sync.py CHANGED
@@ -1,11 +1,12 @@
1
  #!/usr/bin/env python3
2
  """
3
- Basic sync script for HuggingClaw-Cain
4
- Synchronizes content with the configured model and services.
5
  """
6
 
7
  import os
8
  import sys
 
9
  import logging
10
  from datetime import datetime
11
 
@@ -16,28 +17,60 @@ logging.basicConfig(
16
  )
17
  logger = logging.getLogger(__name__)
18
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def main():
20
  """Main sync function"""
21
  try:
22
  logger.info("Starting Cain sync process...")
23
 
 
 
 
 
 
 
24
  # Get configuration from environment
25
  model = os.getenv("MODEL", "openrouter/openai/gpt-oss-20b")
26
  port = os.getenv("PORT", "7860")
27
 
 
 
 
 
28
  logger.info(f"Cain sync configured with model: {model}")
29
  logger.info(f"Running on port: {port}")
30
 
31
- # Sync process would go here
32
- # For now, just mark as completed
33
- logger.info("Sync process completed successfully")
 
 
34
 
35
- # Create a simple completion marker
 
 
 
 
36
  with open("/tmp/sync_complete", "w") as f:
37
  f.write(f"Sync completed at {datetime.now().isoformat()}")
38
 
39
  return 0
40
 
 
 
 
 
41
  except Exception as e:
42
  logger.error(f"Error during sync: {str(e)}")
43
  return 1
 
1
  #!/usr/bin/env python3
2
  """
3
+ OpenClaw sync script for HuggingClaw-Cain
4
+ Initializes the OpenClaw agent with proper configuration.
5
  """
6
 
7
  import os
8
  import sys
9
+ import json
10
  import logging
11
  from datetime import datetime
12
 
 
17
  )
18
  logger = logging.getLogger(__name__)
19
 
20
+ def load_config():
21
+ """Load OpenClaw configuration"""
22
+ config_path = os.path.join(os.path.dirname(__file__), "..", "dataset", ".openclaw", "openclaw.json")
23
+
24
+ try:
25
+ with open(config_path, 'r') as f:
26
+ config = json.load(f)
27
+ return config
28
+ except Exception as e:
29
+ logger.error(f"Failed to load config: {str(e)}")
30
+ return None
31
+
32
  def main():
33
  """Main sync function"""
34
  try:
35
  logger.info("Starting Cain sync process...")
36
 
37
+ # Load configuration
38
+ config = load_config()
39
+ if not config:
40
+ logger.error("Failed to load configuration")
41
+ return 1
42
+
43
  # Get configuration from environment
44
  model = os.getenv("MODEL", "openrouter/openai/gpt-oss-20b")
45
  port = os.getenv("PORT", "7860")
46
 
47
+ # Update config with environment values
48
+ config["model"] = model
49
+ config["port"] = int(port)
50
+
51
  logger.info(f"Cain sync configured with model: {model}")
52
  logger.info(f"Running on port: {port}")
53
 
54
+ # Initialize OpenClaw service
55
+ from openclaw import OpenClaw
56
+
57
+ # Create OpenClaw instance
58
+ claw = OpenClaw(**config)
59
 
60
+ # Start the service
61
+ logger.info("Starting OpenClaw service...")
62
+ claw.start()
63
+
64
+ # Create a completion marker
65
  with open("/tmp/sync_complete", "w") as f:
66
  f.write(f"Sync completed at {datetime.now().isoformat()}")
67
 
68
  return 0
69
 
70
+ except ImportError as e:
71
+ logger.error(f"OpenClaw module not found: {str(e)}")
72
+ logger.info("Please ensure OpenClaw is installed: pip install openclaw")
73
+ return 1
74
  except Exception as e:
75
  logger.error(f"Error during sync: {str(e)}")
76
  return 1