mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-12 21:09:06 +08:00
Fix mutable default argument (#2635)
### What problem does this PR solve? The default value of Python function parameters cannot be mutable. Modifying this parameter inside the function will permanently change the default value ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
c103dd2746
commit
604061c4a5
@ -14,23 +14,25 @@ ErrorHandlerFn = Callable[[BaseException | None, str | None, dict | None], None]
|
|||||||
|
|
||||||
|
|
||||||
def perform_variable_replacements(
|
def perform_variable_replacements(
|
||||||
input: str, history: list[dict]=[], variables: dict | None ={}
|
input: str, history: list[dict] | None = None, variables: dict | None = None
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Perform variable replacements on the input string and in a chat log."""
|
"""Perform variable replacements on the input string and in a chat log."""
|
||||||
|
if history is None:
|
||||||
|
history = []
|
||||||
|
if variables is None:
|
||||||
|
variables = {}
|
||||||
result = input
|
result = input
|
||||||
|
|
||||||
def replace_all(input: str) -> str:
|
def replace_all(input: str) -> str:
|
||||||
result = input
|
result = input
|
||||||
if variables:
|
for k, v in variables.items():
|
||||||
for entry in variables:
|
result = result.replace(f"{{{k}}}", v)
|
||||||
result = result.replace(f"{{{entry}}}", variables[entry])
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
result = replace_all(result)
|
result = replace_all(result)
|
||||||
for i in range(len(history)):
|
for i, entry in enumerate(history):
|
||||||
entry = history[i]
|
|
||||||
if entry.get("role") == "system":
|
if entry.get("role") == "system":
|
||||||
history[i]["content"] = replace_all(entry.get("content") or "")
|
entry["content"] = replace_all(entry.get("content") or "")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user