From d0424135c3ded110acaa552a6390beed88624525 Mon Sep 17 00:00:00 2001 From: shijinpjlab Date: Wed, 11 Jun 2025 10:57:27 +0800 Subject: [PATCH 1/5] feat: fit lint --- .pre-commit-config.yaml | 2 +- examples/classify/sdk_3h_evaluation.py | 20 ++-- examples/classify/sdk_QR_classification.py | 13 ++- examples/classify/sdk_topic_classifcation.py | 13 ++- examples/compare/compare_content.py | 12 +-- examples/continue/continue.py | 2 + examples/core/score.py | 2 + examples/custom/sdk_custom_llm.py | 19 ++-- examples/dataman/dataman.py | 12 +-- examples/dataset/sdk_huggingface.py | 4 + examples/dataset/sdk_local.py | 6 +- examples/image/sdk_image_relevant.py | 13 ++- examples/image/sdk_image_repeat.py | 1 + examples/image/sdk_image_text_similar.py | 1 + examples/llm_and_rule/llm_and_rule_mix.py | 12 +-- examples/llm_and_rule/local_llm.py | 12 +-- examples/llm_and_rule/remote_llm.py | 14 ++- .../sdk_mtbench101_llm.py | 14 ++- .../multi_turn_dialogues/sdk_mtbench_llm.py | 14 ++- examples/register/sdk_register_llm.py | 20 ++-- examples/register/sdk_register_prompt.py | 20 ++-- examples/register/sdk_register_rule.py | 2 +- examples/security/text_security_politics.py | 21 ++--- examples/spark/sdk_spark.py | 4 +- test/scripts/data/dataset/test_hf_dataset.py | 92 +++++++++++-------- .../data/datasource/test_hf_datasource.py | 74 ++++++++------- .../model/rule/utils/test_rule_utils.py | 2 +- 27 files changed, 214 insertions(+), 207 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b2095995..2f08101c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,4 +17,4 @@ repos: hooks: - id: flake8 args: [ "--max-line-length=2200", "--ignore=E121,E131,E125,W503,W504,W604,E203,E231,E702,E128,F541" ] - exclude: 'app/|examples/|test/|dingo/run/vsl.py' + exclude: 'app/' diff --git a/examples/classify/sdk_3h_evaluation.py b/examples/classify/sdk_3h_evaluation.py index 92d39e25..294ec99f 100644 --- a/examples/classify/sdk_3h_evaluation.py +++ b/examples/classify/sdk_3h_evaluation.py @@ -12,23 +12,21 @@ def classify_3H(): "data_format": "jsonl", "column_prompt": "input", "column_content": "response", - "custom_config": - { - "prompt_list": ["PromptTextHarmless"], # options:['PromptIsHelpful', 'PromptIsHonest'] - "llm_config": - { - "LLMText3HHarmless": - { - "key": "", - "api_url": "" - } - } + "custom_config": { + "prompt_list": ["PromptTextHarmless"], # options:['PromptIsHelpful', 'PromptIsHonest'] + "llm_config": { + "LLMText3HHarmless": { + "key": "", + "api_url": "" + } } + } } input_args = InputArgs(**input_data) executor = Executor.exec_map["local"](input_args) result = executor.execute() print(result) + if __name__ == '__main__': classify_3H() diff --git a/examples/classify/sdk_QR_classification.py b/examples/classify/sdk_QR_classification.py index 080aa4c8..64e940db 100644 --- a/examples/classify/sdk_QR_classification.py +++ b/examples/classify/sdk_QR_classification.py @@ -14,14 +14,12 @@ def classify_QR(): "column_content": "content", "custom_config": { "prompt_list": ["PromptClassifyQR"], - "llm_config": - { - "LLMClassifyQR": - { - "key": "", - "api_url": "", - } + "llm_config": { + "LLMClassifyQR": { + "key": "", + "api_url": "", } + } } } input_args = InputArgs(**input_data) @@ -29,5 +27,6 @@ def classify_QR(): result = executor.execute() print(result) + if __name__ == '__main__': classify_QR() diff --git a/examples/classify/sdk_topic_classifcation.py b/examples/classify/sdk_topic_classifcation.py index b344afba..01a0b70b 100644 --- a/examples/classify/sdk_topic_classifcation.py +++ b/examples/classify/sdk_topic_classifcation.py @@ -13,14 +13,12 @@ def classify_topic(): "column_content": "question", "custom_config": { "prompt_list": ["PromptClassifyTopic"], - "llm_config": - { - "LLMClassifyTopic": - { - "key": "", - "api_url": "", - } + "llm_config": { + "LLMClassifyTopic": { + "key": "", + "api_url": "", } + } } } input_args = InputArgs(**input_data) @@ -28,5 +26,6 @@ def classify_topic(): result = executor.execute() print(result) + if __name__ == '__main__': classify_topic() diff --git a/examples/compare/compare_content.py b/examples/compare/compare_content.py index c9d3c866..b37dca77 100644 --- a/examples/compare/compare_content.py +++ b/examples/compare/compare_content.py @@ -15,14 +15,12 @@ "custom_config": { "prompt_list": ["PromptHtmlAbstract"], - "llm_config": - { - "LLMHtmlAbstract": - { - "key": "", - "api_url": "" - } + "llm_config": { + "LLMHtmlAbstract": { + "key": "", + "api_url": "" } + } }, "log_level": "INFO" } diff --git a/examples/continue/continue.py b/examples/continue/continue.py index b5c75ee4..815075a6 100644 --- a/examples/continue/continue.py +++ b/examples/continue/continue.py @@ -20,6 +20,7 @@ def exec_first(): result = executor.execute() print(result) + def exec_second(): input_data = { "eval_group": "sft", @@ -38,6 +39,7 @@ def exec_second(): result = executor.execute() print(result) + if __name__ == '__main__': exec_first() exec_second() diff --git a/examples/core/score.py b/examples/core/score.py index c72c662f..3c0188a5 100644 --- a/examples/core/score.py +++ b/examples/core/score.py @@ -19,6 +19,7 @@ def llm(): res = LLMTextQualityModelBase.eval(data) print(res) + def rule(): data = Data( data_id='123', @@ -29,6 +30,7 @@ def rule(): res = RuleEnterAndSpace().eval(data) print(res) + if __name__ == "__main__": llm() rule() diff --git a/examples/custom/sdk_custom_llm.py b/examples/custom/sdk_custom_llm.py index 6501e8f1..4ce8a7b0 100644 --- a/examples/custom/sdk_custom_llm.py +++ b/examples/custom/sdk_custom_llm.py @@ -8,18 +8,15 @@ "dataset": "local", "data_format": "jsonl", "column_content": "content", - "custom_config": - { - "prompt_list": ["PromptRepeat"], - "llm_config": - { - "LLMTextQualityPromptBase": - { - "key": "", - "api_url": "", - } - } + "custom_config": { + "prompt_list": ["PromptRepeat"], + "llm_config": { + "LLMTextQualityPromptBase": { + "key": "", + "api_url": "", + } } + } } input_args = InputArgs(**input_data) executor = Executor.exec_map["local"](input_args) diff --git a/examples/dataman/dataman.py b/examples/dataman/dataman.py index d7bdbe44..87191c46 100644 --- a/examples/dataman/dataman.py +++ b/examples/dataman/dataman.py @@ -11,14 +11,12 @@ "custom_config": { "prompt_list": ["PromptDataManAssessment"], - "llm_config": - { - "dataman_assessment": - { - "key": "enter your key, such as:EMPTY", - "api_url": "enter your local llm api url, such as:http://127.0.0.1:8080/v1", - } + "llm_config": { + "dataman_assessment": { + "key": "enter your key, such as:EMPTY", + "api_url": "enter your local llm api url, such as:http://127.0.0.1:8080/v1", } + } }, "log_level": "INFO" } diff --git a/examples/dataset/sdk_huggingface.py b/examples/dataset/sdk_huggingface.py index 94da3866..8f8ffe19 100644 --- a/examples/dataset/sdk_huggingface.py +++ b/examples/dataset/sdk_huggingface.py @@ -15,6 +15,7 @@ def huggingface_plaintext(): result = executor.execute() print(result) + def huggingface_json(): input_data = { "eval_group": "sft", @@ -29,6 +30,7 @@ def huggingface_json(): result = executor.execute() print(result) + def huggingface_jsonl(): input_data = { "eval_group": "sft", @@ -42,6 +44,7 @@ def huggingface_jsonl(): result = executor.execute() print(result) + def huggingface_listjson(): input_data = { "eval_group": "sft", @@ -56,6 +59,7 @@ def huggingface_listjson(): result = executor.execute() print(result) + if __name__ == '__main__': huggingface_plaintext() huggingface_json() diff --git a/examples/dataset/sdk_local.py b/examples/dataset/sdk_local.py index f4d222ee..6ddc6ed0 100644 --- a/examples/dataset/sdk_local.py +++ b/examples/dataset/sdk_local.py @@ -5,7 +5,7 @@ def local_plaintext(): input_data = { "eval_group": "sft", - "input_path": "../../test/data/test_local_plaintext.txt", # local filesystem dataset + "input_path": "../../test/data/test_local_plaintext.txt", # local filesystem dataset "dataset": "local", "data_format": "plaintext", } @@ -15,6 +15,7 @@ def local_plaintext(): result = executor.execute() print(result) + def local_json(): input_data = { "eval_group": "sft", @@ -29,6 +30,7 @@ def local_json(): result = executor.execute() print(result) + def local_jsonl(): input_data = { "eval_group": "sft", @@ -43,6 +45,7 @@ def local_jsonl(): result = executor.execute() print(result) + def local_listjson(): input_data = { "eval_group": "sft", @@ -57,6 +60,7 @@ def local_listjson(): result = executor.execute() print(result) + if __name__ == '__main__': local_plaintext() local_json() diff --git a/examples/image/sdk_image_relevant.py b/examples/image/sdk_image_relevant.py index e60e0acd..45a2ef0d 100644 --- a/examples/image/sdk_image_relevant.py +++ b/examples/image/sdk_image_relevant.py @@ -15,14 +15,12 @@ def image_relevant(): "column_content": "url_2", "custom_config": { "prompt_list": ["PromptImageRelevant"], - "llm_config": - { - "VLMImageRelevant": - { - "key": "", - "api_url": "", - } + "llm_config": { + "VLMImageRelevant": { + "key": "", + "api_url": "", } + } } } input_args = InputArgs(**input_data) @@ -30,5 +28,6 @@ def image_relevant(): result = executor.execute() print(result) + if __name__ == '__main__': image_relevant() diff --git a/examples/image/sdk_image_repeat.py b/examples/image/sdk_image_repeat.py index 87c3cf23..f066214e 100644 --- a/examples/image/sdk_image_repeat.py +++ b/examples/image/sdk_image_repeat.py @@ -20,5 +20,6 @@ def image_repeat(): result = executor.execute() print(result) + if __name__ == '__main__': image_repeat() diff --git a/examples/image/sdk_image_text_similar.py b/examples/image/sdk_image_text_similar.py index 081acc6d..d2061476 100644 --- a/examples/image/sdk_image_text_similar.py +++ b/examples/image/sdk_image_text_similar.py @@ -22,5 +22,6 @@ def image_text_similar(): result = executor.execute() print(result) + if __name__ == '__main__': image_text_similar() diff --git a/examples/llm_and_rule/llm_and_rule_mix.py b/examples/llm_and_rule/llm_and_rule_mix.py index 3095a156..bea27cc7 100644 --- a/examples/llm_and_rule/llm_and_rule_mix.py +++ b/examples/llm_and_rule/llm_and_rule_mix.py @@ -12,14 +12,12 @@ { "rule_list": ["RuleColonEnd"], "prompt_list": ["PromptRepeat"], - "llm_config": - { - "LLMTextQualityPromptBase": - { - "key": "enter your key, such as:EMPTY", - "api_url": "enter your local llm api url, such as:http://127.0.0.1:8080/v1", - } + "llm_config": { + "LLMTextQualityPromptBase": { + "key": "enter your key, such as:EMPTY", + "api_url": "enter your local llm api url, such as:http://127.0.0.1:8080/v1", } + } }, "log_level": "INFO" } diff --git a/examples/llm_and_rule/local_llm.py b/examples/llm_and_rule/local_llm.py index ff558679..c0b4a2ce 100644 --- a/examples/llm_and_rule/local_llm.py +++ b/examples/llm_and_rule/local_llm.py @@ -11,14 +11,12 @@ "custom_config": { "prompt_list": ["PromptRepeat"], - "llm_config": - { - "LLMTextQualityPromptBase": - { - "key": "enter your key, such as:EMPTY", - "api_url": "enter your local llm api url, such as:http://127.0.0.1:8080/v1", - } + "llm_config": { + "LLMTextQualityPromptBase": { + "key": "enter your key, such as:EMPTY", + "api_url": "enter your local llm api url, such as:http://127.0.0.1:8080/v1", } + } }, "log_level": "INFO" } diff --git a/examples/llm_and_rule/remote_llm.py b/examples/llm_and_rule/remote_llm.py index 2e463e60..a56f4cbb 100644 --- a/examples/llm_and_rule/remote_llm.py +++ b/examples/llm_and_rule/remote_llm.py @@ -11,15 +11,13 @@ "custom_config": { "prompt_list": ["PromptRepeat"], - "llm_config": - { - "LLMTextQualityPromptBase": - { - "model": "enter your llm, such as:deepseek-chat", - "key": "enter your key, such as:sk-123456789012345678901234567890xx", - "api_url": "enter remote llm api url, such as:https://api.deepseek.com/v1", - } + "llm_config": { + "LLMTextQualityPromptBase": { + "model": "enter your llm, such as:deepseek-chat", + "key": "enter your key, such as:sk-123456789012345678901234567890xx", + "api_url": "enter remote llm api url, such as:https://api.deepseek.com/v1", } + } }, "log_level": "INFO" } diff --git a/examples/multi_turn_dialogues/sdk_mtbench101_llm.py b/examples/multi_turn_dialogues/sdk_mtbench101_llm.py index e97ede41..afe91ac7 100644 --- a/examples/multi_turn_dialogues/sdk_mtbench101_llm.py +++ b/examples/multi_turn_dialogues/sdk_mtbench101_llm.py @@ -12,14 +12,12 @@ "custom_config": { "prompt_list": ["PromptTextQualityV3"], - "llm_config": - { - "detect_text_quality_detail": - { - "key": "", - "api_url": "", - } - }, + "llm_config": { + "detect_text_quality_detail": { + "key": "", + "api_url": "", + } + }, "multi_turn_mode": "all" } } diff --git a/examples/multi_turn_dialogues/sdk_mtbench_llm.py b/examples/multi_turn_dialogues/sdk_mtbench_llm.py index 13180bbc..844e74ea 100644 --- a/examples/multi_turn_dialogues/sdk_mtbench_llm.py +++ b/examples/multi_turn_dialogues/sdk_mtbench_llm.py @@ -13,14 +13,12 @@ "custom_config": { "prompt_list": ["PromptTextQualityV3"], - "llm_config": - { - "detect_text_quality_detail": - { - "key": "", - "api_url": "", - } - }, + "llm_config": { + "detect_text_quality_detail": { + "key": "", + "api_url": "", + } + }, "multi_turn_mode": "all" } } diff --git a/examples/register/sdk_register_llm.py b/examples/register/sdk_register_llm.py index 6f40ab4c..5da0cefe 100644 --- a/examples/register/sdk_register_llm.py +++ b/examples/register/sdk_register_llm.py @@ -43,6 +43,7 @@ def process_response(cls, response: str) -> ModelRes: return result + if __name__ == '__main__': from dingo.exec import Executor from dingo.io import InputArgs @@ -55,18 +56,15 @@ def process_response(cls, response: str) -> ModelRes: "dataset": "local", "data_format": "jsonl", "column_content": "content", - "custom_config": - { - "prompt_list": ["PromptTextQualityV2"], - "llm_config": - { - "LlmTextQualityRegister": - { - "key": "", - "api_url": "", - } - } + "custom_config": { + "prompt_list": ["PromptTextQualityV2"], + "llm_config": { + "LlmTextQualityRegister": { + "key": "", + "api_url": "", + } } + } } input_args = InputArgs(**input_data) executor = Executor.exec_map["local"](input_args) diff --git a/examples/register/sdk_register_prompt.py b/examples/register/sdk_register_prompt.py index 3d43bd09..ba805cee 100644 --- a/examples/register/sdk_register_prompt.py +++ b/examples/register/sdk_register_prompt.py @@ -12,6 +12,7 @@ class PromptRepeatDemo(BasePrompt): 以下是需要判断的文本: """ + if __name__ == '__main__': from dingo.exec import Executor from dingo.io import InputArgs @@ -24,18 +25,15 @@ class PromptRepeatDemo(BasePrompt): "dataset": "local", "data_format": "jsonl", "column_content": "content", - "custom_config": - { - "prompt_list": ["PromptRepeatDemo"], - "llm_config": - { - "LLMTextQualityPromptBase": - { - "key": "", - "api_url": "" - } - } + "custom_config": { + "prompt_list": ["PromptRepeatDemo"], + "llm_config": { + "LLMTextQualityPromptBase": { + "key": "", + "api_url": "" + } } + } } input_args = InputArgs(**input_data) executor = Executor.exec_map["local"](input_args) diff --git a/examples/register/sdk_register_rule.py b/examples/register/sdk_register_rule.py index 09c1823a..35071ce6 100644 --- a/examples/register/sdk_register_rule.py +++ b/examples/register/sdk_register_rule.py @@ -1,5 +1,4 @@ import re -from typing import List from dingo.config.config import DynamicRuleConfig from dingo.io import Data @@ -24,6 +23,7 @@ def eval(cls, input_data: Data) -> ModelRes: res.reason = matches return res + if __name__ == '__main__': from dingo.exec import Executor from dingo.io import InputArgs diff --git a/examples/security/text_security_politics.py b/examples/security/text_security_politics.py index cce11e7f..0d2da0f6 100644 --- a/examples/security/text_security_politics.py +++ b/examples/security/text_security_politics.py @@ -8,18 +8,15 @@ "dataset": "local", "data_format": "jsonl", "column_content": "content", - "custom_config": - { - "prompt_list": ["PromptPolitics"], - "llm_config": - { - "LLMSecurityPolitics": - { - "key": "", - "api_url": "", - } - } - }, + "custom_config": { + "prompt_list": ["PromptPolitics"], + "llm_config": { + "LLMSecurityPolitics": { + "key": "", + "api_url": "", + } + } + }, "log_level": "INFO" } input_args = InputArgs(**input_data) diff --git a/examples/spark/sdk_spark.py b/examples/spark/sdk_spark.py index 22f81e1b..6e9210b4 100644 --- a/examples/spark/sdk_spark.py +++ b/examples/spark/sdk_spark.py @@ -6,8 +6,8 @@ ################## # please prepare # -spark: SparkSession = None # please input -input_df: DataFrame = None # please input +spark: SparkSession = None # please input +input_df: DataFrame = None # please input input_rdd = input_df.rdd.map(lambda x: Data( data_id= str(json.loads(x)['id']), prompt=str(json.loads(x)['prompt']), diff --git a/test/scripts/data/dataset/test_hf_dataset.py b/test/scripts/data/dataset/test_hf_dataset.py index 887fdefb..0446ab10 100644 --- a/test/scripts/data/dataset/test_hf_dataset.py +++ b/test/scripts/data/dataset/test_hf_dataset.py @@ -1,5 +1,5 @@ import pytest -from dingo.data.dataset.huggingface import HuggingFaceDataset, from_huggingface +from dingo.data.dataset.huggingface import HuggingFaceDataset from dingo.data.datasource.huggingface import HuggingFaceSource from dingo.io import InputArgs @@ -7,12 +7,14 @@ class TestHfDataset: def test_hf_dataset_get_data(self): path = "chupei/format-text" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='plaintext', - column_content='text', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='plaintext', + column_content='text', + custom_config=None + ) source = HuggingFaceSource(input_args=ri) dataset: HuggingFaceDataset = HuggingFaceDataset(source=source, name="chupei_text") data_iter = dataset.get_data() @@ -21,13 +23,15 @@ def test_hf_dataset_get_data(self): def test_hf_dataset_get_data_1(self): path = "chupei/format-json" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='json', - column_content='prediction', - column_prompt='origin_prompt', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='json', + column_content='prediction', + column_prompt='origin_prompt', + custom_config=None + ) source = HuggingFaceSource(input_args=ri) dataset: HuggingFaceDataset = HuggingFaceDataset(source=source, name="chupei_json") data_iter = dataset.get_data() @@ -36,12 +40,14 @@ def test_hf_dataset_get_data_1(self): def test_hf_dataset_get_data_2(self): path = "chupei/format-jsonl" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='jsonl', - column_content='content', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='jsonl', + column_content='content', + custom_config=None + ) source = HuggingFaceSource(input_args=ri) dataset: HuggingFaceDataset = HuggingFaceDataset(source=source, name="chupei_jsonl") data_iter = dataset.get_data() @@ -50,13 +56,15 @@ def test_hf_dataset_get_data_2(self): def test_hf_dataset_get_data_3(self): path = "chupei/format-listjson" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='./test/outputs/', - data_format='listjson', - column_content='output', - column_prompt="instruction", - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='./test/outputs/', + data_format='listjson', + column_content='output', + column_prompt="instruction", + custom_config=None + ) source = HuggingFaceSource(input_args=ri) dataset: HuggingFaceDataset = HuggingFaceDataset(source=source, name="chupei_listjson") data_iter = dataset.get_data() @@ -66,12 +74,14 @@ def test_hf_dataset_get_data_3(self): def test_hf_dataset_get_data_4(self): path = "lmms-lab/LLaVA-OneVision-Data" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='./test/outputs/', - data_format='hf-image', - column_image=['image'], - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='./test/outputs/', + data_format='hf-image', + column_image=['image'], + custom_config=None + ) source = HuggingFaceSource(input_args=ri, config_name='CLEVR-Math(MathV360K)') dataset: HuggingFaceDataset = HuggingFaceDataset(source=source, name="LLaVA-OneVision-Data") data_iter = dataset.get_data() @@ -80,13 +90,15 @@ def test_hf_dataset_get_data_4(self): def test_hf_dataset_get_data_5(self): path = "HuggingFaceM4/Docmatix" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='./test/outputs/', - data_format='hf-image', - column_image=['images'], - custom_config=None, - huggingface_split='test') + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='./test/outputs/', + data_format='hf-image', + column_image=['images'], + custom_config=None, + huggingface_split='test' + ) source = HuggingFaceSource(input_args=ri, config_name='zero-shot-exp') dataset: HuggingFaceDataset = HuggingFaceDataset(source=source, name="Docmatix") data_iter = dataset.get_data() diff --git a/test/scripts/data/datasource/test_hf_datasource.py b/test/scripts/data/datasource/test_hf_datasource.py index 0a1ae9fb..525658af 100644 --- a/test/scripts/data/datasource/test_hf_datasource.py +++ b/test/scripts/data/datasource/test_hf_datasource.py @@ -6,12 +6,14 @@ class TestHfDataset: def test_hf_datasource_get_data(self): path = "chupei/format-text" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='plaintext', - column_content='text', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='plaintext', + column_content='text', + custom_config=None + ) source = HuggingFaceSource(input_args=ri) data_iter = source.load() for i in data_iter: @@ -19,13 +21,15 @@ def test_hf_datasource_get_data(self): def test_hf_datasource_get_data_2(self): path = "chupei/format-json" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='json', - column_content='prediction', - column_prompt='origin_prompt', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='json', + column_content='prediction', + column_prompt='origin_prompt', + custom_config=None + ) source = HuggingFaceSource(input_args=ri) data_iter = source.load() for i in data_iter: @@ -33,12 +37,14 @@ def test_hf_datasource_get_data_2(self): def test_hf_datasource_get_data_3(self): path = "chupei/format-jsonl" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='jsonl', - column_content='content', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='jsonl', + column_content='content', + custom_config=None + ) source = HuggingFaceSource(input_args=ri) data_iter = source.load() for i in data_iter: @@ -46,13 +52,15 @@ def test_hf_datasource_get_data_3(self): def test_hf_datasource_get_data_4(self): path = "chupei/format-listjson" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='data/outputs/', - data_format='listjson', - column_content='output', - column_prompt="instruction", - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='data/outputs/', + data_format='listjson', + column_content='output', + column_prompt="instruction", + custom_config=None + ) source = HuggingFaceSource(input_args=ri) data_iter = source.load() for i in data_iter: @@ -60,12 +68,14 @@ def test_hf_datasource_get_data_4(self): def test_hf_datasource_get_data_5(self): path = "lmms-lab/LLaVA-OneVision-Data" - ri = InputArgs(eval_group='default', - input_path=path, - output_path='./test/outputs/', - column_image=['image'], - column_content='conversations', - custom_config=None) + ri = InputArgs( + eval_group='default', + input_path=path, + output_path='./test/outputs/', + column_image=['image'], + column_content='conversations', + custom_config=None + ) source = HuggingFaceSource(input_args=ri, config_name='CLEVR-Math(MathV360K)') data_iter = source.load() print(data_iter[0]) diff --git a/test/scripts/model/rule/utils/test_rule_utils.py b/test/scripts/model/rule/utils/test_rule_utils.py index 32cc9395..fe5e0114 100644 --- a/test/scripts/model/rule/utils/test_rule_utils.py +++ b/test/scripts/model/rule/utils/test_rule_utils.py @@ -1,7 +1,7 @@ import time import pytest -from dingo.model.rule.utils.detect_lang import * +from dingo.model.rule.utils.detect_lang import download_fasttext class TestDownloadFasttext: From 1bfda548b6aded00e54077bad0d0a8dc2c90451f Mon Sep 17 00:00:00 2001 From: shijinpjlab Date: Wed, 11 Jun 2025 14:08:23 +0800 Subject: [PATCH 2/5] feat: fit lint --- .pre-commit-config.yaml | 2 +- test/scripts/model/rule/utils/test_rule_utils.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f08101c..03d4ddb4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,5 +16,5 @@ repos: rev: 5.0.4 hooks: - id: flake8 - args: [ "--max-line-length=2200", "--ignore=E121,E131,E125,W503,W504,W604,E203,E231,E702,E128,F541" ] + args: [ "--max-line-length=2200", "--ignore=E121,E131,E125,W503,W504,W604,E203,E231,E702,E128,F541,F401" ] exclude: 'app/' diff --git a/test/scripts/model/rule/utils/test_rule_utils.py b/test/scripts/model/rule/utils/test_rule_utils.py index fe5e0114..eec904df 100644 --- a/test/scripts/model/rule/utils/test_rule_utils.py +++ b/test/scripts/model/rule/utils/test_rule_utils.py @@ -1,7 +1,7 @@ import time import pytest -from dingo.model.rule.utils.detect_lang import download_fasttext +from dingo.model.rule.utils.detect_lang import calculate_md5, download_fasttext class TestDownloadFasttext: @@ -11,10 +11,9 @@ def test_download_fasttext(self): assert calculate_md5(path) == expected_md5 def test_not_download_fasttext(self): - expected_md5 = "01810bc59c6a3d2b79c79e6336612f65" path_first = download_fasttext() timestamp1 = time.time() - print(timestamp1) + path_second = download_fasttext() timestamp2 = time.time() From d39d15ca891927fa7151bc28bea4496461e99f5a Mon Sep 17 00:00:00 2001 From: shijinpjlab Date: Wed, 11 Jun 2025 14:24:02 +0800 Subject: [PATCH 3/5] feat: update flake8 version --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 03d4ddb4..e4487857 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 args: [ "--max-line-length=2200", "--ignore=E121,E131,E125,W503,W504,W604,E203,E231,E702,E128,F541,F401" ] From 0957ee5ec8afecb0b45066c1adb53a73490478df Mon Sep 17 00:00:00 2001 From: shijinpjlab Date: Wed, 11 Jun 2025 14:47:02 +0800 Subject: [PATCH 4/5] feat: update test yml --- .github/workflows/IntegrationTest.yml | 21 +++++++-------------- .github/workflows/lint.yml | 18 ++++++------------ .pre-commit-config.yaml | 2 +- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/.github/workflows/IntegrationTest.yml b/.github/workflows/IntegrationTest.yml index 4844d506..3c4e977d 100644 --- a/.github/workflows/IntegrationTest.yml +++ b/.github/workflows/IntegrationTest.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application +name: Test on: push: @@ -12,28 +12,21 @@ on: jobs: - build: - + test: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 + - name: Set up Python + uses: actions/setup-python@v4 with: python-version: "3.10" - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + pip install pytest if [ -f requirements/runtime.txt ]; then pip install -r requirements/runtime.txt; fi pip install -e . - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Integration Test(local plaintext) run: | python -m dingo.run.cli --input_path test/data/test_local_plaintext.txt --dataset local -e default --data_format plaintext @@ -62,6 +55,6 @@ jobs: - name: Integration Test(custom config) run: | python -m dingo.run.cli --input_path test/data/test_local_json.json --dataset local -e test --data_format json --column_content prediction --custom_config test/config/config_rule.json --log_level=DEBUG - - name: Run unit tests with pytest + - name: Run unit tests run: | pytest test/scripts --ignore=test/scripts/data diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 92816ab6..267b283d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: lint +name: Lint on: [push, pull_request] @@ -9,19 +9,13 @@ concurrency: jobs: lint: runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.10.15] steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + - uses: actions/checkout@v4 + - name: Set up Python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} - - name: Install pre-commit hook + python-version: "3.10" + - name: Run pre-commit run: | pip install pre-commit==3.8.0 - pre-commit install - - name: Linting - run: | - pre-commit run --all-files + pre-commit run --all-files \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4487857..8b57ecd4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 args: [ "--max-line-length=2200", "--ignore=E121,E131,E125,W503,W504,W604,E203,E231,E702,E128,F541,F401" ] From 5873aeb352716f7bd1d234e6817067b59897aadd Mon Sep 17 00:00:00 2001 From: shijinpjlab Date: Wed, 11 Jun 2025 14:49:30 +0800 Subject: [PATCH 5/5] feat: fix lint --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 267b283d..5569e069 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,4 +18,4 @@ jobs: - name: Run pre-commit run: | pip install pre-commit==3.8.0 - pre-commit run --all-files \ No newline at end of file + pre-commit run --all-files