to-164
This commit is contained in:
Executable
+109
@@ -0,0 +1,109 @@
|
||||
import os
|
||||
import re
|
||||
import orjson
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
from aiDataParser.core.data_normalizer import merge_json_dir
|
||||
|
||||
def load_orjson(path: str | Path):
|
||||
path = Path(path)
|
||||
with path.open("rb") as f: # باید باینری باز بشه برای orjson
|
||||
return orjson.loads(f.read())
|
||||
|
||||
|
||||
def save_orjson(path, data):
|
||||
with open(path, "wb") as f:
|
||||
f.write(
|
||||
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
|
||||
)
|
||||
|
||||
|
||||
def make_data(all_data, system_prompt, assistant_prompt=None):
|
||||
api_batch = []
|
||||
for item in all_data:
|
||||
|
||||
user_prompt = (
|
||||
f"`input`: `{item.get('content')}`"
|
||||
)
|
||||
api_batch.append(
|
||||
{
|
||||
"id": str(item.get("id")),
|
||||
"user_prompt": str(user_prompt),
|
||||
"system_prompt": system_prompt,
|
||||
"assistant_prompt": assistant_prompt,
|
||||
}
|
||||
)
|
||||
return api_batch
|
||||
|
||||
|
||||
SYSTEM_PROMPT_S = """You are a professional Persian-speaking legal expert and attorney.
|
||||
Your role is to **simplify and rewrite Persian legal and statutory texts** so that they become clear and understandable to non-lawyers — **without altering any legal terminology or specialized expressions**.
|
||||
|
||||
Your explanation must preserve the **legal accuracy and meaning**, but use **simple, fluent, and natural Persian sentences** suitable for the general public.
|
||||
|
||||
---
|
||||
|
||||
**Rewriting Rules:**
|
||||
1. Rewrite the text in clear, plain Persian, but keep all legal or technical terms unchanged.
|
||||
2. Do **not** add introductions, explanations, or summaries — only rewrite the given text.
|
||||
3. Avoid semantic repetition or redundant phrasing.
|
||||
4. Ensure each sentence is complete, precise, and logically connected to the next.
|
||||
5. The final version must fully convey the original meaning while being easier to understand.
|
||||
6. The output should contain **only the rewritten text** — no commentary, numbering, or formatting symbols like unordered list such as (ح- , الف- , - , etc.).
|
||||
|
||||
Now rewrite the following Persian text according to these rules:
|
||||
"""
|
||||
|
||||
ASSIST_PROMPT = '''=== Example1 ===
|
||||
`input`:
|
||||
`الف - حقوق و مزایای رئیس کل و قائم مقام رئیس کل بانک مرکزی ایران از طرف مجمع عمومی تعیین و از بودجه بانک پرداخت میشود.`
|
||||
`output` : [
|
||||
`حقوق و مزایای رئیس کل و قائم مقام رئیس کل بانک مرکزی ایران توسط مجمع عمومی تعیین میشود.`,
|
||||
`این حقوق و مزایا از بودجه بانک مرکزی ایران پرداخت میشود.`
|
||||
]
|
||||
'''
|
||||
|
||||
# ---------- مثال استفاده ----------
|
||||
if __name__ == "__main__":
|
||||
########################## make data #################################
|
||||
in_data = load_orjson(
|
||||
'/home1/ava3/init_mahdi/project/aiDataParser/task/simplify/output/f3.json'
|
||||
)
|
||||
_sections = load_orjson('/home1/ava3/init_mahdi/project/aiDataParser/task/simplify/input/valid_mj_qa_sections.json')
|
||||
print(
|
||||
f'in_data {len(in_data)}',
|
||||
f'_sections {len(_sections)}',
|
||||
)
|
||||
in_data_map = {i['id']:i for i in in_data}
|
||||
f_data = []
|
||||
for item in _sections:
|
||||
id = item['id']
|
||||
s_data = in_data_map.get(id)
|
||||
if s_data:
|
||||
item['simplifies'] = s_data['simplify_list']
|
||||
item['ai_code_version'] = s_data['ai_code_version']
|
||||
f_data.append(item)
|
||||
# 216179
|
||||
save_orjson(
|
||||
data=_sections,
|
||||
path='/home1/ava3/init_mahdi/project/aiDataParser/task/simplify/simlify_v1_216179.json'
|
||||
|
||||
)
|
||||
###########################################################
|
||||
# finall_data = [
|
||||
# {
|
||||
# "id": i["id"],
|
||||
# "content": i["content"],
|
||||
# }
|
||||
# for i in data
|
||||
# ]
|
||||
# procces_list = make_data(
|
||||
# all_data=finall_data, assistant_prompt=ASSIST_PROMPT, system_prompt=SYSTEM_PROMPT_S
|
||||
# )
|
||||
# save_orjson(
|
||||
# data=procces_list,
|
||||
# path="/home1/ava3/aiDataParser/task/simplify/input/prompt.json",
|
||||
# )
|
||||
########### #
|
||||
|
||||
# python3 -m aiDataParser.task.simplify.data_gen
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
from aiDataParser import AsyncCore
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
|
||||
class Output(BaseModel):
|
||||
simplify_list : List[str]
|
||||
|
||||
if __name__ == '__main__':
|
||||
ruuner = AsyncCore(
|
||||
model_name='gpt-oss-120b',
|
||||
data_path='/home1/ava3/init_mahdi/project/aiDataParser/task/simplify/input/prompt.json',
|
||||
output_path='/home1/ava3/init_mahdi/project/aiDataParser/task/simplify/output',
|
||||
api_url="http://172.16.29.102:8001/v1/",
|
||||
task_name='simplify-all-v1-oss-120b-med',
|
||||
output_schema=Output,
|
||||
reasoning_effort='medium',
|
||||
ai_code_version='oss120b_med',
|
||||
request_timeout=600,
|
||||
save_number=2,
|
||||
max_token=64000,
|
||||
)
|
||||
ruuner.async_eval()
|
||||
|
||||
# python3 -m aiDataParser.task.simplify.run
|
||||
Reference in New Issue
Block a user