From 501ad14f66f8bfef3e8470b6c64d8b3d5cd048a5 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Mon, 5 Aug 2024 12:10:53 +0200 Subject: [PATCH] added name of the file --- lollms/personality.py | 51 ++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/lollms/personality.py b/lollms/personality.py index 61ece57..26595ce 100644 --- a/lollms/personality.py +++ b/lollms/personality.py @@ -3414,7 +3414,7 @@ class APScript(StateMachine): Returns: List[dict]: A list of dictionaries where each dictionary represents a code block and contains the following keys: - 'index' (int): The index of the code block in the text. - - 'file_name' (str): An empty string. This field is not used in the current implementation. + - 'file_name' (str): The name of the file extracted from the preceding line, if available. - 'content' (str): The content of the code block. - 'type' (str): The type of the code block. If the code block starts with a language specifier (like 'python' or 'java'), this field will contain that specifier. Otherwise, it will be set to 'language-specific'. @@ -3424,18 +3424,18 @@ class APScript(StateMachine): """ remaining = text bloc_index = 0 - first_index=0 + first_index = 0 indices = [] - while len(remaining)>0: + while len(remaining) > 0: try: index = remaining.index("```") - indices.append(index+first_index) - remaining = remaining[index+3:] - first_index += index+3 - bloc_index +=1 + indices.append(index + first_index) + remaining = remaining[index + 3:] + first_index += index + 3 + bloc_index += 1 except Exception as ex: - if bloc_index%2==1: - index=len(remaining) + if bloc_index % 2 == 1: + index = len(remaining) indices.append(index) remaining = "" @@ -3443,15 +3443,22 @@ class APScript(StateMachine): is_start = True for index, code_delimiter_position in enumerate(indices): block_infos = { - 'index':index, + 'index': index, 'file_name': "", 'content': "", - 'type':"" + 'type': "" } if is_start: + # Check the preceding line for file name + preceding_text = text[:code_delimiter_position].strip().splitlines() + if preceding_text: + last_line = preceding_text[-1] + if last_line.startswith("") and last_line.endswith(""): + file_name = last_line[len(""):-len("")].strip() + block_infos['file_name'] = file_name - sub_text = text[code_delimiter_position+3:] - if len(sub_text)>0: + sub_text = text[code_delimiter_position + 3:] + if len(sub_text) > 0: try: find_space = sub_text.index(" ") except: @@ -3462,19 +3469,18 @@ class APScript(StateMachine): find_return = int(1e10) next_index = min(find_return, find_space) if '{' in sub_text[:next_index]: - next_index =0 + next_index = 0 start_pos = next_index - if code_delimiter_position+3