mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-13 22:59:05 +00:00
x
This commit is contained in:
parent
078f73f3f8
commit
008e6b3e41
@ -375,7 +375,7 @@ class BaseLanguageModel(
|
||||
Returns:
|
||||
The sum of the number of tokens across the messages.
|
||||
"""
|
||||
return sum([self.get_num_tokens(get_buffer_string([m])) for m in messages])
|
||||
return sum(self.get_num_tokens(get_buffer_string([m])) for m in messages)
|
||||
|
||||
@classmethod
|
||||
def _all_required_field_names(cls) -> set:
|
||||
|
@ -1387,10 +1387,10 @@ class BaseLLM(BaseLanguageModel[str], ABC):
|
||||
prompt_dict = self.dict()
|
||||
|
||||
if save_path.suffix == ".json":
|
||||
with open(file_path, "w") as f:
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
json.dump(prompt_dict, f, indent=4)
|
||||
elif save_path.suffix.endswith((".yaml", ".yml")):
|
||||
with open(file_path, "w") as f:
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
yaml.dump(prompt_dict, f, default_flow_style=False)
|
||||
else:
|
||||
msg = f"{save_path} must be json or yaml"
|
||||
|
@ -359,10 +359,10 @@ class BasePromptTemplate(
|
||||
directory_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if save_path.suffix == ".json":
|
||||
with open(file_path, "w") as f:
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
json.dump(prompt_dict, f, indent=4)
|
||||
elif save_path.suffix.endswith((".yaml", ".yml")):
|
||||
with open(file_path, "w") as f:
|
||||
with open(file_path, "w", encoding="utf-8") as f:
|
||||
yaml.dump(prompt_dict, f, default_flow_style=False)
|
||||
else:
|
||||
msg = f"{save_path} must be json or yaml"
|
||||
|
@ -588,7 +588,7 @@ class _StringImageMessagePromptTemplate(BaseMessagePromptTemplate):
|
||||
Returns:
|
||||
A new instance of this class.
|
||||
"""
|
||||
with open(str(template_file)) as f:
|
||||
with open(str(template_file), encoding="utf-8") as f:
|
||||
template = f.read()
|
||||
return cls.from_template(template, input_variables=input_variables, **kwargs)
|
||||
|
||||
|
@ -53,7 +53,7 @@ def _load_template(var_name: str, config: dict) -> dict:
|
||||
template_path = Path(config.pop(f"{var_name}_path"))
|
||||
# Load the template.
|
||||
if template_path.suffix == ".txt":
|
||||
with open(template_path) as f:
|
||||
with open(template_path, encoding="utf-8") as f:
|
||||
template = f.read()
|
||||
else:
|
||||
raise ValueError
|
||||
@ -67,7 +67,7 @@ def _load_examples(config: dict) -> dict:
|
||||
if isinstance(config["examples"], list):
|
||||
pass
|
||||
elif isinstance(config["examples"], str):
|
||||
with open(config["examples"]) as f:
|
||||
with open(config["examples"], encoding="utf-8") as f:
|
||||
if config["examples"].endswith(".json"):
|
||||
examples = json.load(f)
|
||||
elif config["examples"].endswith((".yaml", ".yml")):
|
||||
|
@ -248,7 +248,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
|
||||
if not blocking:
|
||||
return self._consume()
|
||||
|
||||
while not self._consume():
|
||||
while not self._consume(): # noqa: ASYNC110
|
||||
await asyncio.sleep(self.check_every_n_seconds)
|
||||
return True
|
||||
|
||||
|
@ -314,7 +314,7 @@ async def test_runnable_sequence_parallel_trace_nesting(method: str) -> None:
|
||||
"other_thing": "RunnableParallel<chain_result,other_thing>",
|
||||
"after": "RunnableSequence",
|
||||
}
|
||||
assert len(posts) == sum([1 if isinstance(n, str) else len(n) for n in name_order])
|
||||
assert len(posts) == sum(1 if isinstance(n, str) else len(n) for n in name_order)
|
||||
prev_dotted_order = None
|
||||
dotted_order_map = {}
|
||||
id_map = {}
|
||||
|
Loading…
Reference in New Issue
Block a user