This commit is contained in:
didi 2024-08-01 17:00:04 +08:00
parent bdfa6eb512
commit 47470fb74c
3 changed files with 7 additions and 10 deletions

View file

@ -71,13 +71,11 @@ async def samples_generate(mode: ModeType, result_path: str = "samples.jsonl"):
ids = list(get_human_eval_plus().keys())
file_lock = asyncio.Lock()
@handle_exception(
exception_type=Exception,
exception_msg="Error in solve_and_write function",
default_return=lambda id, *args, **kwargs: id,
)
async def solve_and_write(id: str, mode: ModeType) -> Optional[str]:
sample_dict = await route_generate(mode, id)
try:
sample_dict = await route_generate(mode, id)
except Exception:
return id
async with file_lock:
async with aiofiles.open(result_path, mode="a") as f:
await f.write(json.dumps(sample_dict) + "\n")

View file

@ -539,7 +539,7 @@ class ActionNode:
if self.schema:
schema = self.schema
if mode == self.MODE_CODE_FILL:
if mode == MODE_CODE_FILL:
result = await self.code_fill(context, function_name, timeout)
self.instruct_content = self.create_class()(**result)
return self

View file

@ -595,15 +595,14 @@ def read_jsonl_file(jsonl_file: str, encoding="utf-8") -> list[dict]:
return datas
def add_jsonl_file(jsonl_file: str, data: list[dict], encoding: str = None, indent: int = 4):
def add_jsonl_file(jsonl_file: str, data: list[dict], encoding: str = None):
folder_path = Path(jsonl_file).parent
if not folder_path.exists():
folder_path.mkdir(parents=True, exist_ok=True)
with open(jsonl_file, "a", encoding=encoding) as fout:
for json_item in data:
json_str = json.dumps(json_item, indent=indent)
fout.write(json_str + "\n")
fout.write(json.dumps(json_item) + "\n")
def read_csv_to_list(curr_file: str, header=False, strip_trail=True):