From 41998612d65b04027fb4b023f53921198778b5ca Mon Sep 17 00:00:00 2001 From: Andrew Wray Date: Mon, 26 May 2025 18:38:25 +0100 Subject: [PATCH 1/2] Fix config bug for frequency penalty --- neural_providers/chatgpt.py | 2 +- neural_providers/openai.py | 2 +- test/python/test_chatgpt.py | 13 +++++++++++++ test/python/test_openai.py | 13 +++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/neural_providers/chatgpt.py b/neural_providers/chatgpt.py index e981c62..c699367 100644 --- a/neural_providers/chatgpt.py +++ b/neural_providers/chatgpt.py @@ -152,7 +152,7 @@ def load_config(raw_config: Dict[str, Any]) -> Config: top_p=top_p, max_tokens=max_tokens, presence_penalty=presence_penalty, - frequency_penalty=presence_penalty, + frequency_penalty=frequency_penalty, ) diff --git a/neural_providers/openai.py b/neural_providers/openai.py index bbb2f16..2c8ca8e 100644 --- a/neural_providers/openai.py +++ b/neural_providers/openai.py @@ -142,7 +142,7 @@ def load_config(raw_config: Dict[str, Any]) -> Config: top_p=top_p, max_tokens=max_tokens, presence_penalty=presence_penalty, - frequency_penalty=presence_penalty, + frequency_penalty=frequency_penalty, ) diff --git a/test/python/test_chatgpt.py b/test/python/test_chatgpt.py index 3fff5b5..7a9bedc 100644 --- a/test/python/test_chatgpt.py +++ b/test/python/test_chatgpt.py @@ -66,6 +66,19 @@ def test_load_config_errors(): assert str(exc.value) == expected_error, config +def test_load_config_valid_values(): + raw = get_valid_config() + cfg = chatgpt.load_config(raw) + + assert cfg.api_key == raw["api_key"] + assert cfg.model == raw["model"] + assert cfg.temperature == raw["temperature"] + assert cfg.top_p == raw["top_p"] + assert cfg.max_tokens == raw["max_tokens"] + assert cfg.presence_penalty == raw["presence_penalty"] + assert cfg.frequency_penalty == raw["frequency_penalty"] + + def test_main_function_rate_other_error(): with mock.patch.object(sys.stdin, 'readline') as readline_mock, \ mock.patch.object(chatgpt, 'get_chatgpt_completion') as compl_mock: diff --git a/test/python/test_openai.py b/test/python/test_openai.py index 24d4c10..2a3adb2 100644 --- a/test/python/test_openai.py +++ b/test/python/test_openai.py @@ -66,6 +66,19 @@ def test_load_config_errors(): assert str(exc.value) == expected_error, config +def test_load_config_valid_values(): + raw = get_valid_config() + cfg = openai.load_config(raw) + + assert cfg.api_key == raw["api_key"] + assert cfg.model == raw["model"] + assert cfg.temperature == raw["temperature"] + assert cfg.top_p == raw["top_p"] + assert cfg.max_tokens == raw["max_tokens"] + assert cfg.presence_penalty == raw["presence_penalty"] + assert cfg.frequency_penalty == raw["frequency_penalty"] + + def test_main_function_rate_other_error(): with mock.patch.object(sys.stdin, 'readline') as readline_mock, \ mock.patch.object(openai, 'get_openai_completion') as completion_mock: From eff3112e2f0e3f2dd29086d1ef7e54d2137e0611 Mon Sep 17 00:00:00 2001 From: Andrew Wray Date: Wed, 28 May 2025 11:30:20 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- test/python/test_chatgpt.py | 2 ++ test/python/test_openai.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/python/test_chatgpt.py b/test/python/test_chatgpt.py index 7a9bedc..37268e9 100644 --- a/test/python/test_chatgpt.py +++ b/test/python/test_chatgpt.py @@ -68,6 +68,8 @@ def test_load_config_errors(): def test_load_config_valid_values(): raw = get_valid_config() + raw["presence_penalty"] = 0.5 + raw["frequency_penalty"] = 1.0 cfg = chatgpt.load_config(raw) assert cfg.api_key == raw["api_key"] diff --git a/test/python/test_openai.py b/test/python/test_openai.py index 2a3adb2..e5a7328 100644 --- a/test/python/test_openai.py +++ b/test/python/test_openai.py @@ -68,6 +68,8 @@ def test_load_config_errors(): def test_load_config_valid_values(): raw = get_valid_config() + raw["presence_penalty"] = 0.5 + raw["frequency_penalty"] = 1.0 cfg = openai.load_config(raw) assert cfg.api_key == raw["api_key"]