Spaces:
Sleeping
Sleeping
Commit
·
e8254b1
1
Parent(s):
3ca27e7
Oracle weight assigning update
Browse files- Oracle/deepfundingoracle.py +26 -20
Oracle/deepfundingoracle.py
CHANGED
@@ -26,6 +26,7 @@ from tqdm import tqdm
|
|
26 |
import sys
|
27 |
import re
|
28 |
import json
|
|
|
29 |
|
30 |
from sklearn.model_selection import train_test_split, RandomizedSearchCV
|
31 |
from sklearn.ensemble import RandomForestRegressor
|
@@ -234,7 +235,7 @@ def timeout_handler(signum, frame):
|
|
234 |
|
235 |
|
236 |
|
237 |
-
def assign_base_weight(df, max_workers=32):
|
238 |
"""
|
239 |
Assign base weights using a single LLM call to determine feature weights,
|
240 |
and programmatically calculate repository weights.
|
@@ -258,25 +259,30 @@ def assign_base_weight(df, max_workers=32):
|
|
258 |
"the influence of a repository. Provide the weights as a JSON object with "
|
259 |
"keys as feature names and values as their weights. Ensure the response is strictly in valid JSON format."
|
260 |
)
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
"
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
|
|
|
|
|
|
|
|
|
|
280 |
print(f"[INFO] Using default feature weights: {feature_weights}", flush=True)
|
281 |
|
282 |
# Step 2: Ensure all feature columns are numeric
|
|
|
26 |
import sys
|
27 |
import re
|
28 |
import json
|
29 |
+
import time
|
30 |
|
31 |
from sklearn.model_selection import train_test_split, RandomizedSearchCV
|
32 |
from sklearn.ensemble import RandomForestRegressor
|
|
|
235 |
|
236 |
|
237 |
|
238 |
+
def assign_base_weight(df, max_workers=32, llm_retries=3,llm_delay=2):
|
239 |
"""
|
240 |
Assign base weights using a single LLM call to determine feature weights,
|
241 |
and programmatically calculate repository weights.
|
|
|
259 |
"the influence of a repository. Provide the weights as a JSON object with "
|
260 |
"keys as feature names and values as their weights. Ensure the response is strictly in valid JSON format."
|
261 |
)
|
262 |
+
fearure_weights= None
|
263 |
+
for attempt in range(llm_retries):
|
264 |
+
try:
|
265 |
+
response = llama.predict(prompt)
|
266 |
+
if not response or response.strip():
|
267 |
+
raise ValueError("Empty response from LLM.")
|
268 |
+
feature_weights = json.loads(response) # Safely parse JSON
|
269 |
+
print(f"[INFO] Feature weights from LLM: {feature_weights}", flush=True)
|
270 |
+
break
|
271 |
+
except Exception as e:
|
272 |
+
print(f"[ERROR] LLM attempt {attempt+1} failed: {e}", flush=True)
|
273 |
+
logging.error(f"[ERROR] LLM attempt {attempt+1} failed: {e}")
|
274 |
+
time.sleep(llm_delay)
|
275 |
+
# Fallback to default weights
|
276 |
+
if fearure_weights is None:
|
277 |
+
feature_weights = {
|
278 |
+
"stars": 0.3,
|
279 |
+
"forks": 0.2,
|
280 |
+
"watchers": 0.2,
|
281 |
+
"open_issues": 0.1,
|
282 |
+
"pulls": 0.1,
|
283 |
+
"activity": 0.05,
|
284 |
+
"contributors": 0.05
|
285 |
+
}
|
286 |
print(f"[INFO] Using default feature weights: {feature_weights}", flush=True)
|
287 |
|
288 |
# Step 2: Ensure all feature columns are numeric
|