fix: password setting improvements
This commit is contained in:
parent
2fa838943c
commit
26524e3b6d
3 changed files with 31 additions and 30 deletions
|
|
@ -19,7 +19,7 @@ class BaseCustomChain(ConversationChain):
|
||||||
|
|
||||||
template: Optional[str]
|
template: Optional[str]
|
||||||
|
|
||||||
ai_prefix_key: Optional[str]
|
ai_prefix_value: Optional[str]
|
||||||
"""Field to use as the ai_prefix. It needs to be set and has to be in the template"""
|
"""Field to use as the ai_prefix. It needs to be set and has to be in the template"""
|
||||||
|
|
||||||
@root_validator(pre=False)
|
@root_validator(pre=False)
|
||||||
|
|
@ -27,13 +27,13 @@ class BaseCustomChain(ConversationChain):
|
||||||
format_dict = {}
|
format_dict = {}
|
||||||
input_variables = extract_input_variables_from_prompt(values["template"])
|
input_variables = extract_input_variables_from_prompt(values["template"])
|
||||||
|
|
||||||
if values.get("ai_prefix_key", None) is None:
|
if values.get("ai_prefix_value", None) is None:
|
||||||
values["ai_prefix_key"] = values["memory"].ai_prefix
|
values["ai_prefix_value"] = values["memory"].ai_prefix
|
||||||
|
|
||||||
for key in input_variables:
|
for key in input_variables:
|
||||||
new_value = values.get(key, f"{{{key}}}")
|
new_value = values.get(key, f"{{{key}}}")
|
||||||
format_dict[key] = new_value
|
format_dict[key] = new_value
|
||||||
if key == values.get("ai_prefix_key", None):
|
if key == values.get("ai_prefix_value", None):
|
||||||
values["memory"].ai_prefix = new_value
|
values["memory"].ai_prefix = new_value
|
||||||
|
|
||||||
values["template"] = values["template"].format(**format_dict)
|
values["template"] = values["template"].format(**format_dict)
|
||||||
|
|
@ -62,7 +62,7 @@ Current conversation:
|
||||||
Human: {input}
|
Human: {input}
|
||||||
{character}:"""
|
{character}:"""
|
||||||
memory: BaseMemory = Field(default_factory=ConversationBufferMemory)
|
memory: BaseMemory = Field(default_factory=ConversationBufferMemory)
|
||||||
ai_prefix_key: Optional[str] = "character"
|
ai_prefix_value: Optional[str] = "character"
|
||||||
"""Default memory store."""
|
"""Default memory store."""
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -179,12 +179,13 @@ class FrontendNode(BaseModel):
|
||||||
(field.required and key not in ["input_variables"])
|
(field.required and key not in ["input_variables"])
|
||||||
or key in FORCE_SHOW_FIELDS
|
or key in FORCE_SHOW_FIELDS
|
||||||
or "api" in key
|
or "api" in key
|
||||||
or "key" in key
|
or ("key" in key and "input" not in key and "output" not in key)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add password field
|
# Add password field
|
||||||
field.password = any(
|
field.password = (
|
||||||
text in key.lower() for text in {"password", "token", "api", "key"}
|
any(text in key.lower() for text in {"password", "token", "api", "key"})
|
||||||
|
and field.show
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add multline
|
# Add multline
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ def test_conversation_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "input",
|
"value": "input",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "input_key",
|
"name": "input_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -60,7 +60,7 @@ def test_conversation_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "response",
|
"value": "response",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -121,7 +121,7 @@ def test_llm_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "text",
|
"value": "text",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -175,7 +175,7 @@ def test_llm_checker_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "query",
|
"value": "query",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "input_key",
|
"name": "input_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -186,7 +186,7 @@ def test_llm_checker_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "result",
|
"value": "result",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -247,7 +247,7 @@ def test_llm_math_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "question",
|
"value": "question",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "input_key",
|
"name": "input_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -258,7 +258,7 @@ def test_llm_math_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "answer",
|
"value": "answer",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -334,7 +334,7 @@ def test_series_character_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "input",
|
"value": "input",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "input_key",
|
"name": "input_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -345,7 +345,7 @@ def test_series_character_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "response",
|
"value": "response",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -361,14 +361,14 @@ def test_series_character_chain(client: TestClient):
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
}
|
}
|
||||||
assert template["ai_prefix_key"] == {
|
assert template["ai_prefix_value"] == {
|
||||||
"required": False,
|
"required": False,
|
||||||
"placeholder": "",
|
"placeholder": "",
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "character",
|
"value": "character",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "ai_prefix_key",
|
"name": "ai_prefix_value",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
}
|
}
|
||||||
|
|
@ -485,7 +485,7 @@ def test_mid_journey_prompt_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "response",
|
"value": "response",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -496,7 +496,7 @@ def test_mid_journey_prompt_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "input",
|
"value": "input",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "input_key",
|
"name": "input_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -512,13 +512,13 @@ def test_mid_journey_prompt_chain(client: TestClient):
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
}
|
}
|
||||||
assert template["ai_prefix_key"] == {
|
assert template["ai_prefix_value"] == {
|
||||||
"required": False,
|
"required": False,
|
||||||
"placeholder": "",
|
"placeholder": "",
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "ai_prefix_key",
|
"name": "ai_prefix_value",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
}
|
}
|
||||||
|
|
@ -613,7 +613,7 @@ def test_time_travel_guide_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "response",
|
"value": "response",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "output_key",
|
"name": "output_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -625,7 +625,7 @@ def test_time_travel_guide_chain(client: TestClient):
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"value": "input",
|
"value": "input",
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "input_key",
|
"name": "input_key",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
|
|
@ -642,13 +642,13 @@ def test_time_travel_guide_chain(client: TestClient):
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
}
|
}
|
||||||
assert template["ai_prefix_key"] == {
|
assert template["ai_prefix_value"] == {
|
||||||
"required": False,
|
"required": False,
|
||||||
"placeholder": "",
|
"placeholder": "",
|
||||||
"show": False,
|
"show": False,
|
||||||
"multiline": False,
|
"multiline": False,
|
||||||
"password": True,
|
"password": False,
|
||||||
"name": "ai_prefix_key",
|
"name": "ai_prefix_value",
|
||||||
"type": "str",
|
"type": "str",
|
||||||
"list": False,
|
"list": False,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue