-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_package_system.py
More file actions
188 lines (160 loc) · 6.36 KB
/
test_package_system.py
File metadata and controls
188 lines (160 loc) · 6.36 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
#!/usr/bin/env python3
"""
Test script to verify the package management system design and functionality.
This simulates what the Rust implementation would do.
"""
import json
import requests
from typing import List, Dict, Optional
import re
class PackageManager:
"""Simulates the Inferno package management system"""
def __init__(self):
self.repositories = [
{
"name": "huggingface",
"url": "https://huggingface.co/api/models",
"priority": 1,
"type": "rest_api"
},
{
"name": "ollama",
"url": "https://ollama.ai/library",
"priority": 2,
"type": "web_scrape"
},
{
"name": "onnx",
"url": "https://github.com/onnx/models",
"priority": 3,
"type": "github"
}
]
def search_models(self, query: str) -> List[Dict]:
"""Search for models across repositories"""
results = []
# Simulated search results
if "llama" in query.lower():
results.append({
"name": "llama-2-7b",
"repository": "huggingface",
"description": "LLaMA 2 7B parameter model",
"size": "13GB",
"format": "gguf"
})
results.append({
"name": "llama2",
"repository": "ollama",
"description": "Ollama's optimized LLaMA 2",
"size": "4GB",
"format": "gguf"
})
if "gpt" in query.lower():
results.append({
"name": "gpt2",
"repository": "huggingface",
"description": "OpenAI's GPT-2 model",
"size": "1.5GB",
"format": "pytorch"
})
return results
def fuzzy_match(self, input_str: str, target: str, threshold: float = 0.8) -> bool:
"""Simple fuzzy matching using Levenshtein distance ratio"""
# Simplified implementation
if input_str.lower() in target.lower() or target.lower() in input_str.lower():
return True
# Calculate similarity ratio
longer = max(len(input_str), len(target))
if longer == 0:
return True
# Count matching characters
matches = sum(1 for a, b in zip(input_str.lower(), target.lower()) if a == b)
ratio = matches / longer
return ratio >= threshold
def suggest_command(self, typo: str) -> Optional[str]:
"""Suggest correct command for common typos"""
commands = ["install", "remove", "search", "list", "update", "info"]
for cmd in commands:
if self.fuzzy_match(typo, cmd, 0.6):
return cmd
return None
def install_model(self, model_name: str) -> Dict:
"""Simulate model installation"""
# Search for the model first
results = self.search_models(model_name)
if not results:
# Try fuzzy matching
suggestion = None
if "lama" in model_name.lower(): # Common typo
suggestion = "llama"
elif "gtp" in model_name.lower(): # Common typo
suggestion = "gpt"
if suggestion:
return {
"status": "error",
"message": f"Model '{model_name}' not found.",
"suggestion": f"Did you mean '{suggestion}'? Try: inferno install {suggestion}"
}
return {
"status": "error",
"message": f"Model '{model_name}' not found in any repository"
}
# Simulate installation
model = results[0]
return {
"status": "success",
"message": f"Successfully installed {model['name']} from {model['repository']}",
"details": model
}
def test_package_system():
"""Test the package management functionality"""
pm = PackageManager()
print("🔥 Testing Inferno Package Management System")
print("=" * 50)
# Test 1: Search functionality
print("\n1️⃣ Testing search functionality...")
results = pm.search_models("llama")
print(f" ✅ Found {len(results)} models for 'llama'")
for r in results:
print(f" - {r['name']} ({r['repository']}): {r['size']}")
# Test 2: Fuzzy matching
print("\n2️⃣ Testing fuzzy command matching...")
typos = ["instal", "isntall", "intall", "serch", "lst"]
for typo in typos:
suggestion = pm.suggest_command(typo)
if suggestion:
print(f" ✅ '{typo}' → suggested: '{suggestion}'")
else:
print(f" ❌ No suggestion for '{typo}'")
# Test 3: Installation with typo correction
print("\n3️⃣ Testing installation with typo correction...")
result = pm.install_model("lama-2") # Typo: missing 'l'
if result["status"] == "error" and "suggestion" in result:
print(f" ✅ Typo detected: {result['message']}")
print(f" {result['suggestion']}")
# Test 4: Successful installation
print("\n4️⃣ Testing successful installation...")
result = pm.install_model("llama")
if result["status"] == "success":
print(f" ✅ {result['message']}")
print(f" Model: {result['details']['name']}")
print(f" Size: {result['details']['size']}")
# Test 5: Repository prioritization
print("\n5️⃣ Testing repository prioritization...")
print(" Repository priority order:")
for repo in sorted(pm.repositories, key=lambda x: x["priority"]):
print(f" {repo['priority']}. {repo['name']} ({repo['url']})")
print("\n" + "=" * 50)
print("✅ All package management tests completed!")
# Test the actual repository connectivity (optional)
print("\n6️⃣ Testing repository connectivity...")
try:
response = requests.get("https://huggingface.co/api/models", params={"limit": 1}, timeout=5)
if response.status_code == 200:
print(" ✅ HuggingFace API is accessible")
else:
print(f" ⚠️ HuggingFace API returned status {response.status_code}")
except Exception as e:
print(f" ❌ Could not connect to HuggingFace: {e}")
if __name__ == "__main__":
test_package_system()