mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 02:28:30 +08:00
fix: fix conversation title is overwrite empty (#39004)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
120c38bad8
commit
d914ece3fb
@ -164,21 +164,22 @@ class LLMGenerator:
|
||||
prompt_messages=list(prompts), model_parameters={"max_tokens": 500, "temperature": 1}, stream=False
|
||||
)
|
||||
answer = response.message.get_text_content()
|
||||
if answer == "":
|
||||
return ""
|
||||
try:
|
||||
result_dict = json.loads(answer)
|
||||
except json.JSONDecodeError:
|
||||
result_dict = json_repair.loads(answer)
|
||||
|
||||
if not isinstance(result_dict, dict):
|
||||
if not answer.strip():
|
||||
answer = query
|
||||
else:
|
||||
output = result_dict.get("Your Output")
|
||||
if isinstance(output, str) and output.strip():
|
||||
answer = output.strip()
|
||||
else:
|
||||
try:
|
||||
result_dict = json.loads(answer)
|
||||
except json.JSONDecodeError:
|
||||
result_dict = json_repair.loads(answer)
|
||||
|
||||
if not isinstance(result_dict, dict):
|
||||
answer = query
|
||||
else:
|
||||
output = result_dict.get("Your Output")
|
||||
if isinstance(output, str) and output.strip():
|
||||
answer = output.strip()
|
||||
else:
|
||||
answer = query
|
||||
|
||||
name = answer.strip()
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ class TestLLMGenerator:
|
||||
mock_model_instance.invoke_llm.return_value = mock_response
|
||||
|
||||
name = LLMGenerator.generate_conversation_name("tenant_id", "test query")
|
||||
assert name == ""
|
||||
assert name == "test query"
|
||||
|
||||
def test_generate_conversation_name_json_repair(self, mock_model_instance):
|
||||
mock_response = MagicMock()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user