Spaces:
Sleeping
Sleeping
Commit ·
e8254b1
1
Parent(s): 3ca27e7
Oracle weight assigning update
Browse files25 unmodified lines262728293031202 unmodified lines23423523623723823924017 unmodified lines25825926026126226326426526626726826927027127227327427527627727827928028128225 unmodified linesimport sysimport reimport jsonfrom sklearn.model_selection import train_test_split, RandomizedSearchCVfrom sklearn.ensemble import RandomForestRegressor202 unmodified linesdef assign_base_weight(df, max_workers=32):"""Assign base weights using a single LLM call to determine feature weights,and programmatically calculate repository weights.17 unmodified lines"the influence of a repository. Provide the weights as a JSON object with ""keys as feature names and values as their weights. Ensure the response is strictly in valid JSON format.")try:response = llama.predict(prompt)if not response.strip():raise ValueError("Empty response from LLM.")feature_weights = json.loads(response) # Safely parse JSONprint(f"[INFO] Feature weights from LLM: {feature_weights}", flush=True)except (json.JSONDecodeError, Exception) as e:print(f"[ERROR] Failed to fetch feature weights from LLM: {e}", flush=True)logging.error(f"[ERROR] Failed to fetch feature weights from LLM: {e}")# Fallback to default weightsfeature_weights = {"stars": 0.3,"forks": 0.2,"watchers": 0.2,"open_issues": 0.1,"pulls": 0.1,"activity": 0.05,"contributors": 0.05}print(f"[INFO] Using default feature weights: {feature_weights}", flush=True)# Step 2: Ensure all feature columns are numeric25 unmodified lines26272829303132202 unmodified lines23523623723823924024117 unmodified lines25926026126226326426526626726826927027127227327427527627727827928028128228328428528628728825 unmodified linesimport sysimport reimport jsonimport timefrom sklearn.model_selection import train_test_split, RandomizedSearchCVfrom sklearn.ensemble import RandomForestRegressor202 unmodified linesdef assign_base_weight(df, max_workers=32, llm_retries=3,llm_delay=2):"""Assign base weights using a single LLM call to determine feature weights,and programmatically calculate repository weights.17 unmodified lines"the influence of a repository. Provide the weights as a JSON object with ""keys as feature names and values as their weights. Ensure the response is strictly in valid JSON format.")fearure_weights= Nonefor attempt in range(llm_retries):try:response = llama.predict(prompt)if not response or response.strip():raise ValueError("Empty response from LLM.")feature_weights = json.loads(response) # Safely parse JSONprint(f"[INFO] Feature weights from LLM: {feature_weights}", flush=True)breakexcept Exception as e:print(f"[ERROR] LLM attempt {attempt+1} failed: {e}", flush=True)logging.error(f"[ERROR] LLM attempt {attempt+1} failed: {e}")time.sleep(llm_delay)# Fallback to default weightsif fearure_weights is None:feature_weights = {"stars": 0.3,"forks": 0.2,"watchers": 0.2,"open_issues": 0.1,"pulls": 0.1,"activity": 0.05,"contributors": 0.05}print(f"[INFO] Using default feature weights: {feature_weights}", flush=True)# Step 2: Ensure all feature columns are numeric
Oracle/deepfundingoracle.py+26-20