def summarize_sentence_scope()

in src/models/struxgpt_v2.py [0:0]


    def summarize_sentence_scope(self, raw_query: str, timeout: int = 5, 
                                 raw_scope: str = '', verbose=False):
        input_prompt = (
            "Summarize a union scope (central theme) within ten words to cover all the given sentences:\n"
            f"```\n{raw_query}\n```\n\n"
            "Your answer should use the same language as the senteces, and follow this format:\n"
            "```[scope goes here]```"
        )
        generate_params = {
            "temperature": 0.1,
            "maxOutputLength": 128,
            "system": "You are a helpful assistant."
        }
        # scope_backup = self.remapping_sentence(raw_query)[0]
        
        scope = ''
        for i in range(timeout):
            try:
                if i == 0 and raw_scope:
                    response = raw_scope
                else:
                    if verbose:
                        print('Model called...')
                    response = self.call_model(input_prompt, **generate_params)
                if '[' in response and ']' in response:
                    # scope = white_space_fix(re.findall('\[(.*)\]', response)[0])
                    candidates = [white_space_fix(cand) for cand in re.findall('\[(.*)\]', response)]
                    candidates = [cand for cand in candidates if not is_empty(cand)]
                    assert len(candidates)
                    scope = candidates[0]
                elif '```' in response:
                    scope = white_space_fix(response.split('```')[-2])
                    assert not is_empty(scope)
                elif '"' == response[0] and '"' == response[-1] and response.count('"') == 2:
                    scope = response[1:-1]
                elif raw_scope:
                    # print('Use the additional candidate:', raw_scope)
                    scope = raw_scope
                else:
                    if i < timeout - 1:
                        if verbose:
                            print('Failed to summarize. Try again.', response)
                        raise RuntimeError
                    else:
                        scope = response # if not is_empty(response) else scope_backup
                        if verbose:
                            print('Summarization timeout. Current result: ', response, 'Final result: ', scope)
                break
            except:
                continue

        # if is_empty(scope) or len(scope) == 0 or 'scope' in scope.lower():
        #     scope = scope_backup
        # print('Successful summarization:', scope)
        return scope