优化代码! 真的最有一次优化isay的逻辑了!!!!
This commit is contained in:
35
func_box.py
35
func_box.py
@ -403,7 +403,7 @@ def prompt_save(txt, name, prompt: gr.Dataset, ipaddr: gr.Request):
|
||||
return txt, name, [], prompt.update(samples=result, visible=True), prompt
|
||||
|
||||
|
||||
def prompt_input(txt, index, data: gr.Dataset):
|
||||
def prompt_input(txt: str, index, data: gr.Dataset, tabs_index):
|
||||
"""
|
||||
点击dataset的值使用Prompt
|
||||
Args:
|
||||
@ -414,11 +414,18 @@ def prompt_input(txt, index, data: gr.Dataset):
|
||||
返回注册函数所需的对象
|
||||
"""
|
||||
data_str = str(data.samples[index][1])
|
||||
if txt:
|
||||
txt = data_str + '\n' + txt
|
||||
data_name = str(data.samples[index][0])
|
||||
rp_str = '"""{v}"""'
|
||||
if data_str.find(rp_str) != -1:
|
||||
new_txt = data_str.replace(rp_str, txt)
|
||||
elif txt and tabs_index == 0:
|
||||
new_txt = data_str + '\n' + txt
|
||||
else:
|
||||
txt = data_str
|
||||
return txt
|
||||
new_txt = data_str
|
||||
if tabs_index == 1:
|
||||
return txt, new_txt, data_name
|
||||
else:
|
||||
return new_txt, '', ''
|
||||
|
||||
|
||||
def copy_result(history):
|
||||
@ -484,7 +491,7 @@ prompt_path = os.path.join(base_path, 'prompt_users')
|
||||
def reuse_chat(result, chatbot, history, pro_numb):
|
||||
"""复用对话记录"""
|
||||
if result is None or result == []:
|
||||
pass
|
||||
return chatbot, history, gr.update(), gr.update(), ''
|
||||
else:
|
||||
if pro_numb:
|
||||
chatbot += result
|
||||
@ -505,6 +512,7 @@ def num_tokens_from_string(listing: list, encoding_name: str = 'cl100k_base') ->
|
||||
count_tokens += len(encoding.encode(i))
|
||||
return count_tokens
|
||||
|
||||
|
||||
def spinner_chatbot_loading(chatbot):
|
||||
loading = [''.join(['.' * random.randint(1, 5)])]
|
||||
# 将元组转换为列表并修改元素
|
||||
@ -518,6 +526,21 @@ def spinner_chatbot_loading(chatbot):
|
||||
loading_msg[-1] = tuple(temp_list)
|
||||
return loading_msg
|
||||
|
||||
|
||||
def txt_converter_json(input_string):
|
||||
try:
|
||||
if input_string.startswith("{") and input_string.endswith("}"):
|
||||
# 尝试将字符串形式的字典转换为字典对象
|
||||
dict_object = ast.literal_eval(input_string)
|
||||
else:
|
||||
# 尝试将字符串解析为JSON对象
|
||||
dict_object = json.loads(input_string)
|
||||
formatted_json_string = json.dumps(dict_object, indent=4, ensure_ascii=False)
|
||||
return formatted_json_string
|
||||
except (ValueError, SyntaxError):
|
||||
return input_string
|
||||
|
||||
|
||||
class YamlHandle:
|
||||
|
||||
def __init__(self, file=os.path.join(prompt_path, 'ai_common.yaml')):
|
||||
|
||||
Reference in New Issue
Block a user