From 3dcf3cf9816a186ec2fc3ac0cbe1d3166f77adff Mon Sep 17 00:00:00 2001 From: w_xiaolizu Date: Tue, 6 Jun 2023 16:47:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2prompt?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __main__.py | 2 +- func_box.py | 17 ++++++++++++----- requirements.txt | 1 + theme.py | 5 ++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/__main__.py b/__main__.py index 08f3c0b..ea6a191 100644 --- a/__main__.py +++ b/__main__.py @@ -101,7 +101,7 @@ class ChatBot(ChatBotFrame): with gr.Box(): with gr.Row(): with gr.Column(scale=100): - self.pro_results = gr.Chatbot(label='Prompt and result').style(height=422) + self.pro_results = gr.Chatbot(label='Prompt and result', elem_id='prompt_result').style() with gr.Column(scale=10): Tips = "用 BORF 分析法设计chat GPT prompt:\n" \ "1、阐述背景 B(Background): 说明背景,为chatGPT提供充足的信息\n" \ diff --git a/func_box.py b/func_box.py index bf0cf5c..d3e8a01 100644 --- a/func_box.py +++ b/func_box.py @@ -10,6 +10,8 @@ import os.path import subprocess import threading import time +from concurrent.futures import ThreadPoolExecutor +import Levenshtein import psutil import re import tempfile @@ -284,25 +286,30 @@ def diff_list(txt='', percent=0.70, switch: list = None, lst: list = None, sp=15 Returns: 返回一个列表 """ - import difflib count_dict = {} if not lst: lst = SqliteHandle('ai_common').get_prompt_value(txt) lst.update(SqliteHandle(f"ai_private_{hosts}").get_prompt_value(txt)) # diff 数据,根据precent系数归类数据 - for i in lst: + str_ = time.time() + + def tf_factor_calcul(i): found = False - for key in count_dict.keys(): - str_tf = difflib.SequenceMatcher(None, i, key).ratio() + dict_copy = count_dict.copy() + for key in dict_copy.keys(): + str_tf = Levenshtein.jaro_winkler(i, key) if str_tf >= percent: if len(i) > len(key): - count_dict[i] = count_dict[key] + 1 + count_dict[i] = count_dict.copy()[key] + 1 count_dict.pop(key) else: count_dict[key] += 1 found = True break if not found: count_dict[i] = 1 + with ThreadPoolExecutor(1000) as executor: + executor.map(tf_factor_calcul, lst) + print('计算耗时', time.time()-str_) sorted_dict = sorted(count_dict.items(), key=lambda x: x[1], reverse=True) if switch: sorted_dict += prompt_retrieval(is_all=switch, hosts=hosts, search=True) diff --git a/requirements.txt b/requirements.txt index d3082a3..110e0ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,4 @@ psutil distro python-dotenv rich +Levenshtein \ No newline at end of file diff --git a/theme.py b/theme.py index c123f9c..3b36edf 100644 --- a/theme.py +++ b/theme.py @@ -139,6 +139,10 @@ textarea { /* overflow: auto !important; */ z-index: 2; } +#prompt_result{ + height: 50vh !important; + max-height: 50vh !important; +} .wrap.svelte-18telvq.svelte-18telvq { padding: var(--block-padding) !important; height: 100% !important; @@ -153,7 +157,6 @@ textarea { width: 100%; height: 100%; } - .markdown-body table { margin: 1em 0; border-collapse: collapse;