Skip to content

Commit 88c67e2

Browse files
committed
Text-classification removed
Signed-off-by: zesk1999 <zesk1999@gmail.com>
1 parent 3675757 commit 88c67e2

File tree

8 files changed

+86
-25
lines changed

8 files changed

+86
-25
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140
- name: Download Annoy Index file from Google Drive
141141
run: |
142142
pip install gdown
143-
gdown --id 1eR9IKrO0yS9ITl29rFjoWfARBlIYnDLq -O ${{ github.workspace }}/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1/rag/models_index.ann
143+
gdown --id 1TQvt1bSXares-I9l7Wki0Jge3oubRkOJ -O ${{ github.workspace }}/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1/rag/models_index.ann
144144
145145
- name: Compile and run tests
146146
uses: eProsima/eProsima-CI/multiplatform/colcon_build_test@v0
@@ -230,7 +230,7 @@ jobs:
230230
- name: Download file from Google Drive
231231
run: |
232232
pip install gdown
233-
gdown --id 1eR9IKrO0yS9ITl29rFjoWfARBlIYnDLq -O ${{ github.workspace }}/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1/rag/models_index.ann
233+
gdown --id 1TQvt1bSXares-I9l7Wki0Jge3oubRkOJ -O ${{ github.workspace }}/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1/rag/models_index.ann
234234
235235
- name: Compile and run tests
236236
uses: eProsima/eProsima-CI/multiplatform/clang_build_test@v0

sustainml_docs/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ compile_documentation()
5353
# Test
5454
###############################################################################
5555
# Compile tests if CMake options requires it
56-
compile_test_documentation(
57-
"${PROJECT_SOURCE_DIR}/test" # Test directory
58-
)
56+
if (EXISTS "${PROJECT_SOURCE_DIR}/test/CMakeLists.txt")
57+
compile_test_documentation("${PROJECT_SOURCE_DIR}/test")
58+
else()
59+
message(STATUS "[sustainml_docs] No tests directory; skipping test compilation.")
60+
endif()
5961

6062
###############################################################################
6163
# Packaging

sustainml_docs/rst/developer_manual/architecture/backend/module_nodes/mlmodelprovider.rst

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,26 @@ And inside ``configuration_callback()`` implement the response to the configurat
8989
import json
9090
9191
from rdftool.ModelONNXCodebase import model
92+
from neo4j import GraphDatabase
9293
from rdftool.rdfCode import load_graph, get_models_for_problem, get_models_for_problem_and_tag
9394
94-
from rag.rag_backend import answer_question, get_allowed_models_for_problem
95+
from rag.rag_backend import answer_question
96+
97+
# Neo4j config/driver for local checks (used by _model_has_goal)
98+
NEO4J_URI = "bolt://localhost:7687"
99+
NEO4J_USER = "neo4j"
100+
NEO4J_PASSWORD = "12345678"
101+
neo4j_driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))
102+
103+
def _model_has_goal(neo4j_driver, model_name: str, goal: str) -> bool:
104+
cypher = """
105+
MATCH (m:Model {name: $model})-[:HAS_PROBLEM]->(p:Problem)
106+
WHERE toLower(p.name) = toLower($goal)
107+
RETURN COUNT(*) AS cnt
108+
"""
109+
with neo4j_driver.session() as s:
110+
r = s.run(cypher, model=model_name, goal=goal).single()
111+
return bool(r and r["cnt"] > 0)
95112
96113
# Whether to go on spinning or interrupt
97114
running = False
@@ -160,17 +177,55 @@ And inside ``configuration_callback()`` implement the response to the configurat
160177
161178
problem_short_description = extra_data_dict["problem_short_description"]
162179
163-
metadata = ml_model_metadata.ml_model_metadata()[0]
180+
goal = ml_model_metadata.ml_model_metadata()[0] # goal selected by metadata node
181+
print(f"Problem short description: {problem_short_description}")
182+
print(f"Selected goal (metadata): {goal}")
183+
184+
# Build strictly goal-scoped allowed list (names only)
185+
goal_models = get_models_for_problem(goal) # [(model_name, downloads), ...]
186+
allowed_names = [name for (name, _) in goal_models]
187+
print(f"[INFO] {len(allowed_names)} candidates for goal '{goal}'")
188+
if not allowed_names:
189+
raise Exception("No candidates in graph for the selected goal")
164190
165-
if chosen_model is None:
166-
print(f"Problem short description: {problem_short_description}")
191+
# Track models to avoid repeats across outputs
192+
restrained_models = []
193+
if extra_data_bytes:
194+
try:
195+
if "model_restrains" in extra_data_dict:
196+
restrained_models = list(set(extra_data_dict["model_restrains"]))
197+
except Exception:
198+
pass
167199
168-
# Build the whitelist and force the RAG to pick ONLY from it
169-
allowed = get_allowed_models_for_problem(metadata) # Metadata is the goal name
170-
chosen_model = answer_question(
171-
f"Task {metadata} with problem description: {problem_short_description}?",
172-
allowed_models=allowed
200+
# Try up to 10 candidates, skipping misfits transparently
201+
chosen_model = None
202+
for _ in range(10):
203+
remaining = [n for n in allowed_names if n not in restrained_models]
204+
if not remaining:
205+
break
206+
207+
candidate = answer_question(
208+
f"Task {goal} with problem description: {problem_short_description}?",
209+
allowed_models=remaining
173210
)
211+
212+
if not candidate or candidate.strip().lower() == "none":
213+
# mark and try again
214+
if candidate:
215+
restrained_models.append(candidate)
216+
continue
217+
218+
# Final safety: ensure candidate really belongs to goal
219+
if not _model_has_goal(neo4j_driver, candidate, goal):
220+
print(f"[GUARD] Dropping {candidate}: not linked to goal {goal}")
221+
restrained_models.append(candidate)
222+
continue
223+
224+
chosen_model = candidate
225+
break
226+
227+
if not chosen_model:
228+
raise Exception("No suitable model after screening candidates")
174229
print(f"ML Model chosen: {chosen_model}")
175230
176231
# Generate model code and keywords
@@ -183,11 +238,11 @@ And inside ``configuration_callback()`` implement the response to the configurat
183238
ml_model.extra_data(encoded_data)
184239
185240
except Exception as e:
186-
print(f"Failed to determine ML model for task {ml_model_metadata.task_id()}: {e}.")
187-
ml_model.model("Error")
188-
ml_model.model_path("Error")
189-
error_message = "Failed to obtain ML model for task: " + str(e)
190-
error_info = {"error": error_message}
241+
print(f"[WARN] No suitable model found for task {ml_model_metadata.task_id()}: {e}")
242+
ml_model.model("NO_MODEL")
243+
ml_model.model_path("N/A")
244+
error_message = "No suitable model found for the given problem."
245+
error_info = {"error_code": "NO_MODEL", "error": error_message}
191246
encoded_error = json.dumps(error_info).encode("utf-8")
192247
ml_model.extra_data(encoded_error)
193248

sustainml_docs/rst/installation/framework.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The following command also builds and installs the SustainML framework and all i
9999
vcs import src < sustainml.repos && cd ~/SustainML/SustainML_ws/src/sustainml_lib && \
100100
git submodule update --init --recursive && \
101101
cd ~/SustainML/SustainML_ws/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1 && \
102-
gdown --id 1eR9IKrO0yS9ITl29rFjoWfARBlIYnDLq -O rag/models_index.ann && \
102+
gdown --id 1TQvt1bSXares-I9l7Wki0Jge3oubRkOJ -O rag/models_index.ann && \
103103
pip3 install -r ~/SustainML/SustainML_ws/src/sustainml_lib/sustainml_modules/requirements.txt && \
104104
cd ~/SustainML/SustainML_ws && colcon build && \
105105
source ~/SustainML/SustainML_ws/install/setup.bash && \
@@ -123,7 +123,7 @@ The following command also builds and installs the SustainML framework and all i
123123
vcs import src < sustainml.repos && cd ~/SustainML/SustainML_ws/src/sustainml_lib && \
124124
git submodule update --init --recursive && \
125125
cd ~/SustainML/SustainML_ws/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1 && \
126-
gdown --id 1eR9IKrO0yS9ITl29rFjoWfARBlIYnDLq -O rag/models_index.ann && \
126+
gdown --id 1TQvt1bSXares-I9l7Wki0Jge3oubRkOJ -O rag/models_index.ann && \
127127
pip3 install -r ~/SustainML/SustainML_ws/src/sustainml_lib/sustainml_modules/requirements.txt && \
128128
cd ~/SustainML/SustainML_ws && colcon build --packages-up-to sustainml --cmake-args -DCMAKE_CXX_STANDARD=17 \
129129
-DQt5_DIR=/usr/local/opt/qt5/lib/cmake/Qt5 && \

sustainml_docs/rst/installation/library.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ The following command builds and installs the *SustainML library* and its depend
9090
vcs import src < sustainml.repos && \
9191
git submodule update --init --recursive && \
9292
cd ~/SustainML/SustainML_ws/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1 && \
93-
gdown --id 1eR9IKrO0yS9ITl29rFjoWfARBlIYnDLq -O rag/models_index.ann && \
93+
gdown --id 1TQvt1bSXares-I9l7Wki0Jge3oubRkOJ -O rag/models_index.ann && \
9494
pip3 install -r ~/SustainML/SustainML_ws/src/sustainml_docs/requirements.txt && \
9595
colcon build && \
9696
sudo neo4j-admin database load system \
@@ -112,7 +112,7 @@ The following command builds and installs the *SustainML library* and its depend
112112
vcs import src < sustainml.repos && \
113113
git submodule update --init --recursive && \
114114
cd ~/SustainML/SustainML_ws/src/sustainml_lib/sustainml_modules/sustainml_modules/sustainml-wp1 && \
115-
gdown --id 1eR9IKrO0yS9ITl29rFjoWfARBlIYnDLq -O rag/models_index.ann && \
115+
gdown --id 1TQvt1bSXares-I9l7Wki0Jge3oubRkOJ -O rag/models_index.ann && \
116116
pip3 install -r ~/SustainML/SustainML_ws/src/sustainml_docs/requirements.txt && \
117117
colcon build --cmake-args -DCMAKE_CXX_STANDARD=17 && \
118118
sudo neo4j-admin database load system \

sustainml_modules/test/communication/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,8 @@ if (Python3_FOUND)
103103
-ap app_requirements_node.py
104104
-py-orc RequestOrchestratorNode.py)
105105

106+
set_tests_properties(SimpleCommunicationOrchestratorSixNodesPython PROPERTIES TIMEOUT 600)
107+
set_tests_properties(SimpleCommunicationPythonOrchestratorSixNodesPython PROPERTIES TIMEOUT 600)
108+
set_tests_properties(SimpleServicePythonOrchestratorSixNodesPython PROPERTIES TIMEOUT 600)
109+
106110
endif()

sustainml_modules/test/communication/chained_nodes_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def run(args):
326326
sleep(1)
327327

328328
try:
329-
outs, errs = listener_proc.communicate(timeout=350)
329+
outs, errs = listener_proc.communicate(timeout=600)
330330
except subprocess.TimeoutExpired:
331331
print('Subscriber process timed out, terminating...')
332332
listener_proc.kill()

0 commit comments

Comments
 (0)