chore: apply ruff's pyflakes linter rules (#2420)
This commit is contained in:
parent
1b04382a9b
commit
14a19a3da9
34 changed files with 91 additions and 86 deletions
|
|
@ -38,7 +38,7 @@ class AssistantApplicationRunner(AppRunner):
|
|||
"""
|
||||
app_record = db.session.query(App).filter(App.id == application_generate_entity.app_id).first()
|
||||
if not app_record:
|
||||
raise ValueError(f"App not found")
|
||||
raise ValueError("App not found")
|
||||
|
||||
app_orchestration_config = application_generate_entity.app_orchestration_config_entity
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class BasicApplicationRunner(AppRunner):
|
|||
"""
|
||||
app_record = db.session.query(App).filter(App.id == application_generate_entity.app_id).first()
|
||||
if not app_record:
|
||||
raise ValueError(f"App not found")
|
||||
raise ValueError("App not found")
|
||||
|
||||
app_orchestration_config = application_generate_entity.app_orchestration_config_entity
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class BaseAssistantApplicationRunner(AppRunner):
|
|||
result += f"result link: {response.message}. please tell user to check it."
|
||||
elif response.type == ToolInvokeMessage.MessageType.IMAGE_LINK or \
|
||||
response.type == ToolInvokeMessage.MessageType.IMAGE:
|
||||
result += f"image has been created and sent to user already, you should tell user to check it now."
|
||||
result += "image has been created and sent to user already, you should tell user to check it now."
|
||||
else:
|
||||
result += f"tool response: {response.message}."
|
||||
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
|||
|
||||
message_file_ids = [message_file.id for message_file, _ in message_files]
|
||||
except ToolProviderCredentialValidationError as e:
|
||||
error_response = f"Please check your tool provider credentials"
|
||||
error_response = "Please check your tool provider credentials"
|
||||
except (
|
||||
ToolNotFoundError, ToolNotSupportedError, ToolProviderNotFoundError
|
||||
) as e:
|
||||
|
|
@ -473,7 +473,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
|
|||
next_iteration = agent_prompt_message.next_iteration
|
||||
|
||||
if not isinstance(first_prompt, str) or not isinstance(next_iteration, str):
|
||||
raise ValueError(f"first_prompt or next_iteration is required in CoT agent mode")
|
||||
raise ValueError("first_prompt or next_iteration is required in CoT agent mode")
|
||||
|
||||
# check instruction, tools, and tool_names slots
|
||||
if not first_prompt.find("{{instruction}}") >= 0:
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ class AssistantFunctionCallApplicationRunner(BaseAssistantApplicationRunner):
|
|||
message_file_ids.append(message_file.id)
|
||||
|
||||
except ToolProviderCredentialValidationError as e:
|
||||
error_response = f"Please check your tool provider credentials"
|
||||
error_response = "Please check your tool provider credentials"
|
||||
except (
|
||||
ToolNotFoundError, ToolNotSupportedError, ToolProviderNotFoundError
|
||||
) as e:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class VectorIndex:
|
|||
vector_type = self._dataset.index_struct_dict['type']
|
||||
|
||||
if not vector_type:
|
||||
raise ValueError(f"Vector store must be specified.")
|
||||
raise ValueError("Vector store must be specified.")
|
||||
|
||||
if vector_type == "weaviate":
|
||||
from core.index.vector_index.weaviate_vector_index import WeaviateConfig, WeaviateVectorIndex
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class ModelInstance:
|
|||
:return: full response or stream response chunk generator result
|
||||
"""
|
||||
if not isinstance(self.model_type_instance, LargeLanguageModel):
|
||||
raise Exception(f"Model type instance is not LargeLanguageModel")
|
||||
raise Exception("Model type instance is not LargeLanguageModel")
|
||||
|
||||
self.model_type_instance = cast(LargeLanguageModel, self.model_type_instance)
|
||||
return self.model_type_instance.invoke(
|
||||
|
|
@ -88,7 +88,7 @@ class ModelInstance:
|
|||
:return: embeddings result
|
||||
"""
|
||||
if not isinstance(self.model_type_instance, TextEmbeddingModel):
|
||||
raise Exception(f"Model type instance is not TextEmbeddingModel")
|
||||
raise Exception("Model type instance is not TextEmbeddingModel")
|
||||
|
||||
self.model_type_instance = cast(TextEmbeddingModel, self.model_type_instance)
|
||||
return self.model_type_instance.invoke(
|
||||
|
|
@ -112,7 +112,7 @@ class ModelInstance:
|
|||
:return: rerank result
|
||||
"""
|
||||
if not isinstance(self.model_type_instance, RerankModel):
|
||||
raise Exception(f"Model type instance is not RerankModel")
|
||||
raise Exception("Model type instance is not RerankModel")
|
||||
|
||||
self.model_type_instance = cast(RerankModel, self.model_type_instance)
|
||||
return self.model_type_instance.invoke(
|
||||
|
|
@ -135,7 +135,7 @@ class ModelInstance:
|
|||
:return: false if text is safe, true otherwise
|
||||
"""
|
||||
if not isinstance(self.model_type_instance, ModerationModel):
|
||||
raise Exception(f"Model type instance is not ModerationModel")
|
||||
raise Exception("Model type instance is not ModerationModel")
|
||||
|
||||
self.model_type_instance = cast(ModerationModel, self.model_type_instance)
|
||||
return self.model_type_instance.invoke(
|
||||
|
|
@ -155,7 +155,7 @@ class ModelInstance:
|
|||
:return: text for given audio file
|
||||
"""
|
||||
if not isinstance(self.model_type_instance, Speech2TextModel):
|
||||
raise Exception(f"Model type instance is not Speech2TextModel")
|
||||
raise Exception("Model type instance is not Speech2TextModel")
|
||||
|
||||
self.model_type_instance = cast(Speech2TextModel, self.model_type_instance)
|
||||
return self.model_type_instance.invoke(
|
||||
|
|
@ -176,7 +176,7 @@ class ModelInstance:
|
|||
:return: text for given audio file
|
||||
"""
|
||||
if not isinstance(self.model_type_instance, TTSModel):
|
||||
raise Exception(f"Model type instance is not TTSModel")
|
||||
raise Exception("Model type instance is not TTSModel")
|
||||
|
||||
self.model_type_instance = cast(TTSModel, self.model_type_instance)
|
||||
return self.model_type_instance.invoke(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class LoggingCallback(Callback):
|
|||
"""
|
||||
self.print_text("\n[on_llm_before_invoke]\n", color='blue')
|
||||
self.print_text(f"Model: {model}\n", color='blue')
|
||||
self.print_text(f"Parameters:\n", color='blue')
|
||||
self.print_text("Parameters:\n", color='blue')
|
||||
for key, value in model_parameters.items():
|
||||
self.print_text(f"\t{key}: {value}\n", color='blue')
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ class LoggingCallback(Callback):
|
|||
self.print_text(f"\tstop: {stop}\n", color='blue')
|
||||
|
||||
if tools:
|
||||
self.print_text(f"\tTools:\n", color='blue')
|
||||
self.print_text("\tTools:\n", color='blue')
|
||||
for tool in tools:
|
||||
self.print_text(f"\t\t{tool.name}\n", color='blue')
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ class LoggingCallback(Callback):
|
|||
if user:
|
||||
self.print_text(f"User: {user}\n", color='blue')
|
||||
|
||||
self.print_text(f"Prompt messages:\n", color='blue')
|
||||
self.print_text("Prompt messages:\n", color='blue')
|
||||
for prompt_message in prompt_messages:
|
||||
if prompt_message.name:
|
||||
self.print_text(f"\tname: {prompt_message.name}\n", color='blue')
|
||||
|
|
@ -101,7 +101,7 @@ class LoggingCallback(Callback):
|
|||
self.print_text(f"Content: {result.message.content}\n", color='yellow')
|
||||
|
||||
if result.message.tool_calls:
|
||||
self.print_text(f"Tool calls:\n", color='yellow')
|
||||
self.print_text("Tool calls:\n", color='yellow')
|
||||
for tool_call in result.message.tool_calls:
|
||||
self.print_text(f"\t{tool_call.id}\n", color='yellow')
|
||||
self.print_text(f"\t{tool_call.function.name}\n", color='yellow')
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class BaichuanLarguageModel(LargeLanguageModel):
|
|||
stop: List[str] | None = None, stream: bool = True, user: str | None = None) \
|
||||
-> LLMResult | Generator:
|
||||
if tools is not None and len(tools) > 0:
|
||||
raise InvokeBadRequestError(f"Baichuan model doesn't support tools")
|
||||
raise InvokeBadRequestError("Baichuan model doesn't support tools")
|
||||
|
||||
instance = BaichuanModel(
|
||||
api_key=credentials['api_key'],
|
||||
|
|
|
|||
|
|
@ -146,16 +146,16 @@ class OAIAPICompatLargeLanguageModel(_CommonOAI_API_Compat, LargeLanguageModel):
|
|||
try:
|
||||
json_result = response.json()
|
||||
except json.JSONDecodeError as e:
|
||||
raise CredentialsValidateFailedError(f'Credentials validation failed: JSON decode error')
|
||||
raise CredentialsValidateFailedError('Credentials validation failed: JSON decode error')
|
||||
|
||||
if (completion_type is LLMMode.CHAT
|
||||
and ('object' not in json_result or json_result['object'] != 'chat.completion')):
|
||||
raise CredentialsValidateFailedError(
|
||||
f'Credentials validation failed: invalid response object, must be \'chat.completion\'')
|
||||
'Credentials validation failed: invalid response object, must be \'chat.completion\'')
|
||||
elif (completion_type is LLMMode.COMPLETION
|
||||
and ('object' not in json_result or json_result['object'] != 'text_completion')):
|
||||
raise CredentialsValidateFailedError(
|
||||
f'Credentials validation failed: invalid response object, must be \'text_completion\'')
|
||||
'Credentials validation failed: invalid response object, must be \'text_completion\'')
|
||||
except CredentialsValidateFailedError:
|
||||
raise
|
||||
except Exception as ex:
|
||||
|
|
|
|||
|
|
@ -179,11 +179,11 @@ class OAICompatEmbeddingModel(_CommonOAI_API_Compat, TextEmbeddingModel):
|
|||
try:
|
||||
json_result = response.json()
|
||||
except json.JSONDecodeError as e:
|
||||
raise CredentialsValidateFailedError(f'Credentials validation failed: JSON decode error')
|
||||
raise CredentialsValidateFailedError('Credentials validation failed: JSON decode error')
|
||||
|
||||
if 'model' not in json_result:
|
||||
raise CredentialsValidateFailedError(
|
||||
f'Credentials validation failed: invalid response')
|
||||
'Credentials validation failed: invalid response')
|
||||
except CredentialsValidateFailedError:
|
||||
raise
|
||||
except Exception as ex:
|
||||
|
|
|
|||
|
|
@ -231,15 +231,15 @@ class ErnieBotModel(object):
|
|||
# so, we just disable function calling for now.
|
||||
|
||||
if tools is not None and len(tools) > 0:
|
||||
raise BadRequestError(f'function calling is not supported yet.')
|
||||
raise BadRequestError('function calling is not supported yet.')
|
||||
|
||||
if stop is not None:
|
||||
if len(stop) > 4:
|
||||
raise BadRequestError(f'stop list should not exceed 4 items.')
|
||||
raise BadRequestError('stop list should not exceed 4 items.')
|
||||
|
||||
for s in stop:
|
||||
if len(s) > 20:
|
||||
raise BadRequestError(f'stop item should not exceed 20 characters.')
|
||||
raise BadRequestError('stop item should not exceed 20 characters.')
|
||||
|
||||
def _build_request_body(self, model: str, messages: List[ErnieMessage], stream: bool, parameters: Dict[str, Any],
|
||||
tools: List[PromptMessageTool], stop: List[str], user: str) -> Dict[str, Any]:
|
||||
|
|
@ -252,9 +252,9 @@ class ErnieBotModel(object):
|
|||
stop: List[str], user: str) \
|
||||
-> Dict[str, Any]:
|
||||
if len(messages) % 2 == 0:
|
||||
raise BadRequestError(f'The number of messages should be odd.')
|
||||
raise BadRequestError('The number of messages should be odd.')
|
||||
if messages[0].role == 'function':
|
||||
raise BadRequestError(f'The first message should be user message.')
|
||||
raise BadRequestError('The first message should be user message.')
|
||||
|
||||
"""
|
||||
TODO: implement function calling
|
||||
|
|
@ -264,7 +264,7 @@ class ErnieBotModel(object):
|
|||
parameters: Dict[str, Any], stop: List[str], user: str) \
|
||||
-> Dict[str, Any]:
|
||||
if len(messages) == 0:
|
||||
raise BadRequestError(f'The number of messages should not be zero.')
|
||||
raise BadRequestError('The number of messages should not be zero.')
|
||||
|
||||
# check if the first element is system, shift it
|
||||
system_message = ''
|
||||
|
|
@ -273,9 +273,9 @@ class ErnieBotModel(object):
|
|||
system_message = message.content
|
||||
|
||||
if len(messages) % 2 == 0:
|
||||
raise BadRequestError(f'The number of messages should be odd.')
|
||||
raise BadRequestError('The number of messages should be odd.')
|
||||
if messages[0].role != 'user':
|
||||
raise BadRequestError(f'The first message should be user message.')
|
||||
raise BadRequestError('The first message should be user message.')
|
||||
body = {
|
||||
'messages': [message.to_dict() for message in messages],
|
||||
'stream': stream,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class ZhipuAI(HttpClient):
|
|||
if base_url is None:
|
||||
base_url = os.environ.get("ZHIPUAI_BASE_URL")
|
||||
if base_url is None:
|
||||
base_url = f"https://open.bigmodel.cn/api/paas/v4"
|
||||
base_url = "https://open.bigmodel.cn/api/paas/v4"
|
||||
from .__version__ import __version__
|
||||
super().__init__(
|
||||
version=__version__,
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ class RuleConfigGeneratorOutputParser(BaseOutputParser):
|
|||
raise ValueError("Expected 'prompt' to be a string.")
|
||||
if not isinstance(parsed["variables"], list):
|
||||
raise ValueError(
|
||||
f"Expected 'variables' to be a list."
|
||||
"Expected 'variables' to be a list."
|
||||
)
|
||||
if not isinstance(parsed["opening_statement"], str):
|
||||
raise ValueError(
|
||||
f"Expected 'opening_statement' to be a str."
|
||||
"Expected 'opening_statement' to be a str."
|
||||
)
|
||||
return parsed
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ class ToolModelManager:
|
|||
)
|
||||
|
||||
if not model_instance:
|
||||
raise InvokeModelError(f'Model not found')
|
||||
raise InvokeModelError('Model not found')
|
||||
|
||||
llm_model = cast(LargeLanguageModel, model_instance.model_type_instance)
|
||||
schema = llm_model.get_model_schema(model_instance.model, model_instance.credentials)
|
||||
|
||||
if not schema:
|
||||
raise InvokeModelError(f'No model schema found')
|
||||
raise InvokeModelError('No model schema found')
|
||||
|
||||
max_tokens = schema.model_properties.get(ModelPropertyKey.CONTEXT_SIZE, None)
|
||||
if max_tokens is None:
|
||||
|
|
@ -69,7 +69,7 @@ class ToolModelManager:
|
|||
)
|
||||
|
||||
if not model_instance:
|
||||
raise InvokeModelError(f'Model not found')
|
||||
raise InvokeModelError('Model not found')
|
||||
|
||||
llm_model = cast(LargeLanguageModel, model_instance.model_type_instance)
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ class ToolModelManager:
|
|||
except InvokeConnectionError as e:
|
||||
raise InvokeModelError(f'Invoke connection error: {e}')
|
||||
except InvokeAuthorizationError as e:
|
||||
raise InvokeModelError(f'Invoke authorization error')
|
||||
raise InvokeModelError('Invoke authorization error')
|
||||
except InvokeServerUnavailableError as e:
|
||||
raise InvokeModelError(f'Invoke server unavailable error: {e}')
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -66,5 +66,5 @@ class YahooFinanceAnalyticsTool(BuiltinTool):
|
|||
try:
|
||||
return self.create_text_message(str(summary_df.to_dict()))
|
||||
except (HTTPError, ReadTimeout):
|
||||
return self.create_text_message(f'There is a internet connection problem. Please try again later.')
|
||||
return self.create_text_message('There is a internet connection problem. Please try again later.')
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ class YahooFinanceSearchTickerTool(BuiltinTool):
|
|||
try:
|
||||
return self.run(ticker=query, user_id=user_id)
|
||||
except (HTTPError, ReadTimeout):
|
||||
return self.create_text_message(f'There is a internet connection problem. Please try again later.')
|
||||
return self.create_text_message('There is a internet connection problem. Please try again later.')
|
||||
|
||||
def run(self, ticker: str, user_id: str) -> ToolInvokeMessage:
|
||||
company = yfinance.Ticker(ticker)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class YahooFinanceSearchTickerTool(BuiltinTool):
|
|||
try:
|
||||
return self.create_text_message(self.run(ticker=query))
|
||||
except (HTTPError, ReadTimeout):
|
||||
return self.create_text_message(f'There is a internet connection problem. Please try again later.')
|
||||
return self.create_text_message('There is a internet connection problem. Please try again later.')
|
||||
|
||||
def run(self, ticker: str) -> str:
|
||||
return str(Ticker(ticker).info)
|
||||
|
|
@ -221,7 +221,7 @@ class Tool(BaseModel, ABC):
|
|||
result += f"result link: {response.message}. please tell user to check it."
|
||||
elif response.type == ToolInvokeMessage.MessageType.IMAGE_LINK or \
|
||||
response.type == ToolInvokeMessage.MessageType.IMAGE:
|
||||
result += f"image has been created and sent to user already, you should tell user to check it now."
|
||||
result += "image has been created and sent to user already, you should tell user to check it now."
|
||||
elif response.type == ToolInvokeMessage.MessageType.BLOB:
|
||||
if len(response.message) > 114:
|
||||
result += str(response.message[:114]) + '...'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue