feat: mypy for all type check (#10921)

This commit is contained in:
yihong
2024-12-24 18:38:51 +08:00
committed by GitHub
parent c91e8b1737
commit 56e15d09a9
584 changed files with 3975 additions and 2826 deletions

View File

@@ -1,5 +1,5 @@
from collections.abc import Sequence
from typing import cast
from typing import Any, cast
from core.model_runtime.entities import (
AssistantPromptMessage,
@@ -72,7 +72,7 @@ class PromptMessageUtil:
}
)
else:
text = prompt_message.content
text = cast(str, prompt_message.content)
prompt = {"role": role, "text": text, "files": files}
@@ -99,9 +99,9 @@ class PromptMessageUtil:
}
)
else:
text = prompt_message.content
text = cast(str, prompt_message.content)
params = {
params: dict[str, Any] = {
"role": "user",
"text": text,
}

View File

@@ -1,4 +1,5 @@
import re
from collections.abc import Mapping
REGEX = re.compile(r"\{\{([a-zA-Z_][a-zA-Z0-9_]{0,29}|#histories#|#query#|#context#)\}\}")
WITH_VARIABLE_TMPL_REGEX = re.compile(
@@ -28,7 +29,7 @@ class PromptTemplateParser:
# Regular expression to match the template rules
return re.findall(self.regex, self.template)
def format(self, inputs: dict, remove_template_variables: bool = True) -> str:
def format(self, inputs: Mapping[str, str], remove_template_variables: bool = True) -> str:
def replacer(match):
key = match.group(1)
value = inputs.get(key, match.group(0)) # return original matched string if key not found