From 533144f2595cf506a5cc242483291e17a2bc4363 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 22 Apr 2024 09:25:51 +0800 Subject: [PATCH 1/2] fix: Prevent PROMPT mutation in devchat chat_json - Introduced variable prompt_new to avoid mutating the original prompt - Ensured prompt_new is consistently used for message comparison and appending - Adjusted both chat and chat_json functions to utilize prompt_new effectively --- devchat/llm/chat.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/devchat/llm/chat.py b/devchat/llm/chat.py index fc3e80a2..8252e901 100644 --- a/devchat/llm/chat.py +++ b/devchat/llm/chat.py @@ -49,10 +49,10 @@ def decorator(func): @wraps(func) def wrapper(*args, **kwargs): # pylint: disable=unused-argument nonlocal prompt, memory, model, llm_config - prompt = prompt.format(**kwargs) + prompt_new = prompt.format(**kwargs) messages = memory.contexts() if memory else [] - if not any(item["content"] == prompt for item in messages) and prompt: - messages.append({"role": "user", "content": prompt}) + if not any(item["content"] == prompt_new for item in messages) and prompt_new: + messages.append({"role": "user", "content": prompt_new}) if "__user_request__" in kwargs: messages.append(kwargs["__user_request__"]) del kwargs["__user_request__"] @@ -68,7 +68,7 @@ def wrapper(*args, **kwargs): # pylint: disable=unused-argument if memory: memory.append( - {"role": "user", "content": prompt}, + {"role": "user", "content": prompt_new}, {"role": "assistant", "content": response["content"]}, ) return response["content"] @@ -88,10 +88,10 @@ def decorator(func): @wraps(func) def wrapper(*args, **kwargs): # pylint: disable=unused-argument nonlocal prompt, memory, model, llm_config - prompt = prompt.format(**kwargs) + prompt_new = prompt.format(**kwargs) messages = memory.contexts() if memory else [] - if not any(item["content"] == prompt for item in messages): - messages.append({"role": "user", "content": prompt}) + if not any(item["content"] == prompt_new for item in messages): + messages.append({"role": "user", "content": prompt_new}) llm_config["model"] = model response = chat_completion_no_stream_return_json(messages, llm_config=llm_config) @@ -100,7 +100,7 @@ def wrapper(*args, **kwargs): # pylint: disable=unused-argument if memory: memory.append( - {"role": "user", "content": prompt}, + {"role": "user", "content": prompt_new}, {"role": "assistant", "content": json.dumps(response)}, ) return response From e11cb2a4fb96a8654deb3e081aa91ca2c103184c Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Mon, 22 Apr 2024 09:39:05 +0800 Subject: [PATCH 2/2] fix: Enhance function name detection in tests - Expanded assert in CLI prompt tests to include camelCase variation - Ensures tests now cover different naming conventions effectively - Improves the reliability of function name assertions in CLI tests --- tests/test_cli_prompt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_cli_prompt.py b/tests/test_cli_prompt.py index e558d269..91e66bb7 100644 --- a/tests/test_cli_prompt.py +++ b/tests/test_cli_prompt.py @@ -184,7 +184,9 @@ def test_prompt_with_function_replay(git_repo, functions_file): # pylint: disab content = get_content(result.output) assert result.exit_code == 0 - assert 'get_current_weather' in content or 'GetCurrentWeather' in content + assert 'get_current_weather' in content \ + or 'GetCurrentWeather' in content \ + or 'getCurrentWeather' in content def test_prompt_without_repo(mock_home_dir): # pylint: disable=W0613