-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup_mixassist.py
More file actions
275 lines (218 loc) · 8.15 KB
/
setup_mixassist.py
File metadata and controls
275 lines (218 loc) · 8.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/env python3
"""
MixAssist Dataset Setup Script
Downloads and configures the MixAssist dataset for use with Carla MCP Server
"""
import argparse
import os
import sys
from pathlib import Path
from typing import Optional
def check_requirements():
"""Check if required packages are installed"""
try:
import datasets
import pandas as pd
except ImportError as e:
print(f"❌ Missing required package: {e.name}")
print("\nInstall required packages:")
print(" pip install datasets pandas pyarrow")
sys.exit(1)
def download_dataset(output_dir: Path, force: bool = False) -> bool:
"""Download MixAssist dataset from Hugging Face
Args:
output_dir: Directory to store the dataset
force: Force redownload even if dataset exists
Returns:
True if successful, False otherwise
"""
from datasets import load_dataset
# Check if dataset already exists
if output_dir.exists() and not force:
parquet_files = list(output_dir.glob("*.parquet"))
if len(parquet_files) >= 3:
print(f"✅ Dataset already exists at {output_dir}")
print(f" Found {len(parquet_files)} parquet files")
print("\n Use --force to redownload")
return True
# Create output directory
output_dir.mkdir(parents=True, exist_ok=True)
print(f"📥 Downloading MixAssist dataset from Hugging Face...")
print(f" Destination: {output_dir}")
try:
# Load dataset from Hugging Face
# Dataset: https://huggingface.co/datasets/MixAssist/mixassist
dataset = load_dataset("MixAssist/mixassist", trust_remote_code=True)
print(f"\n✅ Downloaded dataset with {len(dataset)} splits:")
for split_name, split_data in dataset.items():
print(f" - {split_name}: {len(split_data)} conversations")
# Save each split as parquet
output_file = output_dir / f"{split_name}-00000-of-00001.parquet"
split_data.to_parquet(str(output_file))
print(f" 💾 Saved: {output_file.name}")
print(f"\n🎉 Dataset successfully downloaded to: {output_dir}")
return True
except Exception as e:
print(f"\n❌ Failed to download dataset: {e}")
print("\nTroubleshooting:")
print(" 1. Check your internet connection")
print(" 2. Verify Hugging Face access (might need login for some datasets)")
print(" 3. Try: huggingface-cli login")
return False
def create_config(dataset_path: Path, config_file: Optional[Path] = None) -> bool:
"""Create configuration file with dataset path
Args:
dataset_path: Path to the dataset directory
config_file: Path to config file (default: .env in project root)
Returns:
True if successful
"""
if config_file is None:
config_file = Path(__file__).parent / ".env"
# Check if config already exists
if config_file.exists():
print(f"\n⚠️ Config file already exists: {config_file}")
response = input(" Overwrite? (y/N): ").strip().lower()
if response != 'y':
print(" Skipped config creation")
return True
# Create config content
config_content = f"""# Carla MCP Server Configuration
# Auto-generated by setup_mixassist.py
# MixAssist Dataset Configuration
MIXASSIST_DATASET_PATH={dataset_path.absolute()}
# Optional: Enable/disable MixAssist resources
MIXASSIST_ENABLED=true
"""
try:
config_file.write_text(config_content)
print(f"\n✅ Created config file: {config_file}")
print(f" Dataset path: {dataset_path.absolute()}")
return True
except Exception as e:
print(f"\n❌ Failed to create config: {e}")
return False
def verify_dataset(dataset_path: Path) -> bool:
"""Verify that the dataset is valid and complete
Args:
dataset_path: Path to verify
Returns:
True if valid, False otherwise
"""
import pandas as pd
print(f"\n🔍 Verifying dataset at: {dataset_path}")
if not dataset_path.exists():
print(f" ❌ Directory does not exist")
return False
# Check for required parquet files
required_splits = ["train", "test", "validation"]
total_conversations = 0
for split in required_splits:
parquet_file = dataset_path / f"{split}-00000-of-00001.parquet"
if not parquet_file.exists():
print(f" ❌ Missing {split} split: {parquet_file.name}")
return False
try:
df = pd.read_parquet(parquet_file)
conversation_count = len(df)
total_conversations += conversation_count
print(f" ✅ {split}: {conversation_count} conversations")
except Exception as e:
print(f" ❌ Failed to read {split} split: {e}")
return False
print(f"\n✅ Dataset verification passed!")
print(f" Total: {total_conversations} conversations across {len(required_splits)} splits")
return True
def main():
parser = argparse.ArgumentParser(
description="Setup MixAssist dataset for Carla MCP Server",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Download to default location and create config
python setup_mixassist.py --download
# Download to custom location
python setup_mixassist.py --download --output ~/datasets/mixassist
# Just create config for existing dataset
python setup_mixassist.py --path /path/to/existing/dataset
# Verify existing dataset
python setup_mixassist.py --verify --path /path/to/dataset
# Force redownload
python setup_mixassist.py --download --force
"""
)
parser.add_argument(
"--download",
action="store_true",
help="Download the dataset from Hugging Face"
)
parser.add_argument(
"--output",
type=Path,
default=Path.home() / ".cache" / "mixassist" / "data",
help="Output directory for downloaded dataset (default: ~/.cache/mixassist/data)"
)
parser.add_argument(
"--path",
type=Path,
help="Path to existing dataset (for config creation or verification)"
)
parser.add_argument(
"--verify",
action="store_true",
help="Verify dataset integrity"
)
parser.add_argument(
"--force",
action="store_true",
help="Force redownload even if dataset exists"
)
parser.add_argument(
"--config",
type=Path,
help="Path to config file (default: .env in project root)"
)
parser.add_argument(
"--no-config",
action="store_true",
help="Skip config file creation"
)
args = parser.parse_args()
# Show header
print("=" * 60)
print("MixAssist Dataset Setup for Carla MCP Server")
print("=" * 60)
# Determine dataset path
dataset_path = args.path if args.path else args.output
# Download if requested
if args.download:
check_requirements()
if not download_dataset(args.output, force=args.force):
sys.exit(1)
dataset_path = args.output
# Verify if requested or after download
if args.verify or args.download:
check_requirements()
if not verify_dataset(dataset_path):
print("\n❌ Dataset verification failed")
sys.exit(1)
# Create config unless explicitly disabled
if not args.no_config:
if not dataset_path.exists():
print(f"\n❌ Dataset path does not exist: {dataset_path}")
print(" Run with --download to download the dataset first")
sys.exit(1)
if not create_config(dataset_path, args.config):
sys.exit(1)
# Show success message
print("\n" + "=" * 60)
print("🎉 Setup Complete!")
print("=" * 60)
print("\nNext steps:")
print(" 1. The MixAssist resources will be automatically available in the MCP server")
print(" 2. Restart your MCP server if it's already running")
print(" 3. Resources are accessible via URIs like: mixassist://index")
print("\nFor more information, see: CLAUDE.md")
print("=" * 60)
if __name__ == "__main__":
main()