Skip to content

Commit 9ed8210

Browse files
committed
refactor: simplify llm_text_3h.py and unify examples path resolution
- Simplify quality_name extraction in llm_text_3h.py by using class name directly - Replace ../../ relative paths with PROJECT_ROOT pattern in all examples - Use Path(__file__).parent.parent.parent for consistent project root detection
1 parent 5048d80 commit 9ed8210

38 files changed

+145
-70
lines changed

dingo/model/llm/hhh/llm_text_3h.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,11 @@ def process_response(cls, response: str) -> EvalDetail:
4040

4141
result = EvalDetail(metric=cls.__name__)
4242

43-
# Get the quality dimension name
44-
# If prompt has __name__ (e.g., PromptTextHelpful), extract from it; otherwise from class name
45-
prompt_name = getattr(cls.prompt, '__name__', None)
46-
prompt_prefix = "PromptText"
43+
# Get the quality dimension name from class name
44+
# e.g., LLMText3HHelpful -> HELPFUL
4745
class_prefix = "LLMText3H"
48-
if prompt_name and prompt_name.startswith(prompt_prefix):
49-
quality_name = prompt_name[len(prompt_prefix):].upper() # PromptTextHelpful -> HELPFUL
50-
elif cls.__name__.startswith(class_prefix):
51-
quality_name = cls.__name__[len(class_prefix):].upper() # LLMText3HHelpful -> HELPFUL
46+
if cls.__name__.startswith(class_prefix):
47+
quality_name = cls.__name__[len(class_prefix):].upper()
5248
else:
5349
quality_name = cls.__name__.upper()
5450

examples/3h/3h_eval.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from dingo.config import InputArgs
55
from dingo.exec import Executor
66

7+
# 获取项目根目录
8+
PROJECT_ROOT = Path(__file__).parent.parent.parent
9+
710
if __name__ == '__main__':
811
# Configure LLM (set your API key via environment variable OPENAI_KEY)
912
OPENAI_MODEL = os.getenv("OPENAI_MODEL", "gpt-4o")
@@ -15,12 +18,8 @@
1518
"api_url": OPENAI_URL,
1619
}
1720

18-
# Get the path relative to this script
19-
script_dir = Path(__file__).parent
20-
data_path = script_dir / "../../test/data/test_3h_jsonl.jsonl"
21-
2221
input_data = {
23-
"input_path": str(data_path.resolve()),
22+
"input_path": str(PROJECT_ROOT / "test/data/test_3h_jsonl.jsonl"),
2423
"dataset": {
2524
"source": "local",
2625
"format": "jsonl"

examples/artimuse/artimuse.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from dingo.config import InputArgs
44
from dingo.exec import Executor
55

6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
8+
69
if __name__ == '__main__':
710
input_data = {
8-
"input_path": str(Path(__file__).parent.joinpath("../../test/data/test_imgae_artimuse.jsonl").resolve()),
11+
"input_path": str(PROJECT_ROOT / "test/data/test_imgae_artimuse.jsonl"),
912
"dataset": {
1013
"source": "local",
1114
"format": "jsonl"

examples/audio/audioSnr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import os
21
from pathlib import Path
32

43
from dingo.config import InputArgs
54
from dingo.exec import Executor
65

6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
8+
79
if __name__ == '__main__':
810
input_data = {
9-
"input_path": str(Path(__file__).parent.joinpath("../../test/data/test_audio_snr.jsonl").resolve()),
11+
"input_path": str(PROJECT_ROOT / "test/data/test_audio_snr.jsonl"),
1012
"dataset": {
1113
"source": "local",
1214
"format": "jsonl",

examples/classify/sdk_QR_classification.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
from dingo.config import InputArgs
44
from dingo.exec import Executor
55

6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
8+
69

710
def classify_QR():
811
input_data = {
9-
"input_path": str(Path(__file__).parent.joinpath("../../test/data/test_imgQR_jsonl.jsonl").resolve()),
12+
"input_path": str(PROJECT_ROOT / "test/data/test_imgQR_jsonl.jsonl"),
1013
"dataset": {
1114
"source": "local",
1215
"format": "jsonl",

examples/classify/sdk_topic_classifcation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from dingo.config import InputArgs
55
from dingo.exec import Executor
66

7+
# 获取项目根目录
8+
PROJECT_ROOT = Path(__file__).parent.parent.parent
9+
710
# Configure LLM (set your API key via environment variable OPENAI_KEY)
811
LLM_CONFIG = {
912
"key": os.getenv("OPENAI_KEY", "YOUR_API_KEY"),
@@ -13,11 +16,8 @@
1316

1417

1518
def classify_topic():
16-
script_dir = Path(__file__).parent
17-
data_path = script_dir / "../../test/data/test_sft_jsonl.jsonl"
18-
1919
input_data = {
20-
"input_path": str(data_path.resolve()),
20+
"input_path": str(PROJECT_ROOT / "test/data/test_sft_jsonl.jsonl"),
2121
"dataset": {
2222
"source": "local",
2323
"format": "jsonl"

examples/compare/compare_code.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from dingo.config import InputArgs
44
from dingo.exec import Executor
55

6-
SCRIPT_DIR = Path(__file__).parent
6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
78

89
input_data = {
9-
'input_path': str(SCRIPT_DIR.joinpath('../../test/data/compare/WebMainBench_test_1011_dataset_with_results_clean.jsonl').resolve()),
10+
'input_path': str(PROJECT_ROOT / 'test/data/compare/WebMainBench_test_1011_dataset_with_results_clean.jsonl'),
1011
'dataset': {
1112
'source': 'local',
1213
'format': 'jsonl',

examples/compare/compare_math.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from dingo.config import InputArgs
44
from dingo.exec import Executor
55

6-
SCRIPT_DIR = Path(__file__).parent
6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
78

89
input_data = {
9-
'input_path': str(SCRIPT_DIR.joinpath('../../test/data/compare/WebMainBench_test_1011_dataset_with_results_clean.jsonl').resolve()),
10+
'input_path': str(PROJECT_ROOT / 'test/data/compare/WebMainBench_test_1011_dataset_with_results_clean.jsonl'),
1011
'dataset': {
1112
'source': 'local',
1213
'format': 'jsonl',

examples/compare/compare_table.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
from dingo.config import InputArgs
44
from dingo.exec import Executor
55

6-
SCRIPT_DIR = Path(__file__).parent
6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
78

89
input_data = {
9-
'input_path': str(SCRIPT_DIR.joinpath('../../test/data/compare/WebMainBench_test_1011_dataset_with_results_clean_llm_webkit_html.jsonl').resolve()),
10+
'input_path': str(PROJECT_ROOT / 'test/data/compare/WebMainBench_test_1011_dataset_with_results_clean_llm_webkit_html.jsonl'),
1011
'dataset': {
1112
'source': 'local',
1213
'format': 'jsonl',

examples/compare/html_extract_compare_v1.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
from dingo.config import InputArgs
44
from dingo.exec import Executor
55

6+
# 获取项目根目录
7+
PROJECT_ROOT = Path(__file__).parent.parent.parent
8+
69
if __name__ == '__main__':
710
input_data = {
8-
"input_path": str(Path(__file__).parent.joinpath("../../test/data/compare/old_new_compare_10000.jsonl").resolve()),
11+
"input_path": str(PROJECT_ROOT / "test/data/compare/old_new_compare_10000.jsonl"),
912
"dataset": {
1013
"source": "local",
1114
"format": "jsonl",

0 commit comments

Comments
 (0)