mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-30 15:01:31 +00:00
style:fmt
This commit is contained in:
parent
71b9cd14a6
commit
e70f05aea1
@ -170,7 +170,7 @@ async def dialogue_scenes():
|
||||
|
||||
@router.post("/v1/chat/dialogue/new", response_model=Result[ConversationVo])
|
||||
async def dialogue_new(
|
||||
chat_mode: str = ChatScene.ChatNormal.value(), user_id: str = None
|
||||
chat_mode: str = ChatScene.ChatNormal.value(), user_id: str = None
|
||||
):
|
||||
conv_vo = __new_conversation(chat_mode, user_id)
|
||||
return Result.succ(conv_vo)
|
||||
@ -201,7 +201,7 @@ async def params_load(conv_uid: str, chat_mode: str, doc_file: UploadFile = File
|
||||
if not os.path.exists(os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode)):
|
||||
os.makedirs(os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode))
|
||||
with NamedTemporaryFile(
|
||||
dir=os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode), delete=False
|
||||
dir=os.path.join(KNOWLEDGE_UPLOAD_ROOT_PATH, chat_mode), delete=False
|
||||
) as tmp:
|
||||
tmp.write(await doc_file.read())
|
||||
tmp_path = tmp.name
|
||||
|
@ -39,7 +39,7 @@ logger = build_logger("api_editor_v1", LOGDIR + "api_editor_v1.log")
|
||||
|
||||
@router.get("/v1/editor/db/tables", response_model=Result[DbTable])
|
||||
async def get_editor_tables(
|
||||
db_name: str, page_index: int, page_size: int, search_str: str = ""
|
||||
db_name: str, page_index: int, page_size: int, search_str: str = ""
|
||||
):
|
||||
logger.info(f"get_editor_tables:{db_name},{page_index},{page_size},{search_str}")
|
||||
db_conn = CFG.LOCAL_DB_MANAGE.get_connect(db_name)
|
||||
@ -285,7 +285,7 @@ async def chart_editor_submit(chart_edit_context: ChatChartEditContext = Body())
|
||||
find_chart = list(
|
||||
filter(
|
||||
lambda x: x["chart_name"]
|
||||
== chart_edit_context.chart_title,
|
||||
== chart_edit_context.chart_title,
|
||||
charts,
|
||||
)
|
||||
)[0]
|
||||
|
@ -155,7 +155,7 @@ class BaseOutputParser(ABC):
|
||||
if i < 0:
|
||||
return None
|
||||
count = 1
|
||||
for j, c in enumerate(s[i + 1:], start=i + 1):
|
||||
for j, c in enumerate(s[i + 1 :], start=i + 1):
|
||||
if c == "]":
|
||||
count -= 1
|
||||
elif c == "[":
|
||||
@ -163,13 +163,13 @@ class BaseOutputParser(ABC):
|
||||
if count == 0:
|
||||
break
|
||||
assert count == 0
|
||||
return s[i: j + 1]
|
||||
return s[i : j + 1]
|
||||
else:
|
||||
i = s.find("{")
|
||||
if i < 0:
|
||||
return None
|
||||
count = 1
|
||||
for j, c in enumerate(s[i + 1:], start=i + 1):
|
||||
for j, c in enumerate(s[i + 1 :], start=i + 1):
|
||||
if c == "}":
|
||||
count -= 1
|
||||
elif c == "{":
|
||||
@ -177,7 +177,7 @@ class BaseOutputParser(ABC):
|
||||
if count == 0:
|
||||
break
|
||||
assert count == 0
|
||||
return s[i: j + 1]
|
||||
return s[i : j + 1]
|
||||
|
||||
def parse_prompt_response(self, model_out_text) -> T:
|
||||
"""
|
||||
@ -194,9 +194,9 @@ class BaseOutputParser(ABC):
|
||||
# if "```" in cleaned_output:
|
||||
# cleaned_output, _ = cleaned_output.split("```")
|
||||
if cleaned_output.startswith("```json"):
|
||||
cleaned_output = cleaned_output[len("```json"):]
|
||||
cleaned_output = cleaned_output[len("```json") :]
|
||||
if cleaned_output.startswith("```"):
|
||||
cleaned_output = cleaned_output[len("```"):]
|
||||
cleaned_output = cleaned_output[len("```") :]
|
||||
if cleaned_output.endswith("```"):
|
||||
cleaned_output = cleaned_output[: -len("```")]
|
||||
cleaned_output = cleaned_output.strip()
|
||||
|
@ -60,7 +60,7 @@ class BaseChat(ABC):
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def __init__(
|
||||
self, chat_mode, chat_session_id, current_user_input, select_param: Any = None
|
||||
self, chat_mode, chat_session_id, current_user_input, select_param: Any = None
|
||||
):
|
||||
self.chat_session_id = chat_session_id
|
||||
self.chat_mode = chat_mode
|
||||
@ -305,7 +305,7 @@ class BaseChat(ABC):
|
||||
system_messages = []
|
||||
for system_conv in system_convs:
|
||||
system_text += (
|
||||
system_conv.type + ":" + system_conv.content + self.prompt_template.sep
|
||||
system_conv.type + ":" + system_conv.content + self.prompt_template.sep
|
||||
)
|
||||
system_messages.append(
|
||||
ModelMessage(role=system_conv.type, content=system_conv.content)
|
||||
@ -317,7 +317,7 @@ class BaseChat(ABC):
|
||||
user_messages = []
|
||||
if user_conv:
|
||||
user_text = (
|
||||
user_conv.type + ":" + user_conv.content + self.prompt_template.sep
|
||||
user_conv.type + ":" + user_conv.content + self.prompt_template.sep
|
||||
)
|
||||
user_messages.append(
|
||||
ModelMessage(role=user_conv.type, content=user_conv.content)
|
||||
@ -339,10 +339,10 @@ class BaseChat(ABC):
|
||||
message_type = round_message["type"]
|
||||
message_content = round_message["data"]["content"]
|
||||
example_text += (
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
)
|
||||
example_messages.append(
|
||||
ModelMessage(role=message_type, content=message_content)
|
||||
@ -363,10 +363,10 @@ class BaseChat(ABC):
|
||||
message_type = first_message["type"]
|
||||
message_content = first_message["data"]["content"]
|
||||
history_text += (
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
)
|
||||
history_messages.append(
|
||||
ModelMessage(role=message_type, content=message_content)
|
||||
@ -382,10 +382,10 @@ class BaseChat(ABC):
|
||||
message_type = round_message["type"]
|
||||
message_content = round_message["data"]["content"]
|
||||
history_text += (
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
)
|
||||
history_messages.append(
|
||||
ModelMessage(
|
||||
@ -405,10 +405,10 @@ class BaseChat(ABC):
|
||||
message_type = message["type"]
|
||||
message_content = message["data"]["content"]
|
||||
history_text += (
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
message_type
|
||||
+ ":"
|
||||
+ message_content
|
||||
+ self.prompt_template.sep
|
||||
)
|
||||
history_messages.append(
|
||||
ModelMessage(role=message_type, content=message_content)
|
||||
|
@ -167,7 +167,7 @@ def messages_from_dict(messages: List[dict]) -> List[BaseMessage]:
|
||||
|
||||
|
||||
def _parse_model_messages(
|
||||
messages: List[ModelMessage],
|
||||
messages: List[ModelMessage],
|
||||
) -> Tuple[str, List[str], List[List[str, str]]]:
|
||||
""" "
|
||||
Parameters:
|
||||
|
@ -22,11 +22,11 @@ class ChatDashboard(BaseChat):
|
||||
"""Number of results to return from the query"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
chat_session_id,
|
||||
user_input,
|
||||
select_param: str = "",
|
||||
report_name: str = "report",
|
||||
self,
|
||||
chat_session_id,
|
||||
user_input,
|
||||
select_param: str = "",
|
||||
report_name: str = "report",
|
||||
):
|
||||
""" """
|
||||
self.db_name = select_param
|
||||
|
@ -24,12 +24,12 @@ class ExcelLearning(BaseChat):
|
||||
chat_scene: str = ChatScene.ExcelLearning.value()
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
chat_session_id,
|
||||
user_input,
|
||||
parent_mode: Any = None,
|
||||
select_param: str = None,
|
||||
excel_reader: Any = None,
|
||||
self,
|
||||
chat_session_id,
|
||||
user_input,
|
||||
parent_mode: Any = None,
|
||||
select_param: str = None,
|
||||
excel_reader: Any = None,
|
||||
):
|
||||
chat_mode = ChatScene.ExcelLearning
|
||||
""" """
|
||||
|
@ -47,7 +47,7 @@ class LearningExcelOutputParser(BaseOutputParser):
|
||||
keys = item.keys()
|
||||
for key in keys:
|
||||
html_colunms = (
|
||||
html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n"
|
||||
html_colunms + f"- **{column_index}.[{key}]** _{item[key]}_\n"
|
||||
)
|
||||
|
||||
html_plans = f"### **分析计划**\n"
|
||||
|
Loading…
Reference in New Issue
Block a user