From 4cbac67f6fba70eb79f36d20e0e2286e0bd49416 Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:10:35 -0400 Subject: [PATCH 1/9] fix: increase retry limit and provide override --- src/gpt_review/constants.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gpt_review/constants.py b/src/gpt_review/constants.py index d16c331a..20b1d4ff 100644 --- a/src/gpt_review/constants.py +++ b/src/gpt_review/constants.py @@ -20,3 +20,5 @@ PRESENCE_PENALTY_DEFAULT = 0 PRESENCE_PENALTY_MIN = 0 PRESENCE_PENALTY_MAX = 2 + +RETRY_COUNT = 10 From 7c8c8436fef9de206d429b57a2a0db6d0b4d59c9 Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:11:32 -0400 Subject: [PATCH 2/9] Update constants.py --- src/gpt_review/constants.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gpt_review/constants.py b/src/gpt_review/constants.py index 20b1d4ff..0548e43b 100644 --- a/src/gpt_review/constants.py +++ b/src/gpt_review/constants.py @@ -1,4 +1,5 @@ """Contains constants for minimum and maximum values of various parameters used in GPT Review.""" +import os import sys MAX_TOKENS_DEFAULT = 100 @@ -21,4 +22,4 @@ PRESENCE_PENALTY_MIN = 0 PRESENCE_PENALTY_MAX = 2 -RETRY_COUNT = 10 +RETRY_LIMIT = os.getenv("RETRY_LIMIT", 10) From 2f36d680b1ef7676b1476b957de4e3df7193c9d8 Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:11:55 -0400 Subject: [PATCH 3/9] Update _ask.py --- src/gpt_review/_ask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpt_review/_ask.py b/src/gpt_review/_ask.py index 29c9e843..c96a417e 100644 --- a/src/gpt_review/_ask.py +++ b/src/gpt_review/_ask.py @@ -164,7 +164,7 @@ def _call_gpt( ) return completion.choices[0].message.content # type: ignore except RateLimitError as error: - if retry < 5: + if retry < C.RETRY_LIMIT: logging.warning("Call to GPT failed due to rate limit, retry attempt: %s", retry) time.sleep(retry * 10) return _call_gpt(prompt, temperature, max_tokens, top_p, frequency_penalty, presence_penalty, retry + 1) From 3d0284246a328a00cd68d040a6b61d3650c747e1 Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:13:06 -0400 Subject: [PATCH 4/9] Update _llama_index.py --- src/gpt_review/_llama_index.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gpt_review/_llama_index.py b/src/gpt_review/_llama_index.py index 6137a26b..a6d9cf68 100644 --- a/src/gpt_review/_llama_index.py +++ b/src/gpt_review/_llama_index.py @@ -9,6 +9,8 @@ from llama_index import GPTVectorStoreIndex, LLMPredictor, LangchainEmbedding, ServiceContext, SimpleDirectoryReader from llama_index.indices.base import BaseGPTIndex +import gpt_review.constants as C + def _ask_doc(question: str, files: List[str], fast: bool = False, large: bool = False) -> str: """ @@ -54,7 +56,7 @@ def _document_indexer( "api_type": "azure", "api_version": "2023-03-15-preview", }, - max_retries=10, + max_retries=MAX_RETRIES, ) llm_predictor = LLMPredictor(llm=llm) From 2d417967669726aeb9b594b852720bbd2e1f2d55 Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:13:17 -0400 Subject: [PATCH 5/9] Update _ask.py --- src/gpt_review/_ask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpt_review/_ask.py b/src/gpt_review/_ask.py index c96a417e..4c63937d 100644 --- a/src/gpt_review/_ask.py +++ b/src/gpt_review/_ask.py @@ -164,7 +164,7 @@ def _call_gpt( ) return completion.choices[0].message.content # type: ignore except RateLimitError as error: - if retry < C.RETRY_LIMIT: + if retry < C.MAX_RETRIES: logging.warning("Call to GPT failed due to rate limit, retry attempt: %s", retry) time.sleep(retry * 10) return _call_gpt(prompt, temperature, max_tokens, top_p, frequency_penalty, presence_penalty, retry + 1) From c9f701376420c3842fb75e5c338cf595b55aecde Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:13:27 -0400 Subject: [PATCH 6/9] Update constants.py --- src/gpt_review/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpt_review/constants.py b/src/gpt_review/constants.py index 0548e43b..3b9cc161 100644 --- a/src/gpt_review/constants.py +++ b/src/gpt_review/constants.py @@ -22,4 +22,4 @@ PRESENCE_PENALTY_MIN = 0 PRESENCE_PENALTY_MAX = 2 -RETRY_LIMIT = os.getenv("RETRY_LIMIT", 10) +MAX_RETRIES = os.getenv("MAX_RETRIES", 10) From 1aabdbe639491ca7bf1cd85caf8bebbcf04466fb Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:16:40 -0400 Subject: [PATCH 7/9] Apply suggestions from code review --- src/gpt_review/_ask.py | 2 +- src/gpt_review/constants.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gpt_review/_ask.py b/src/gpt_review/_ask.py index 4c63937d..c12055a4 100644 --- a/src/gpt_review/_ask.py +++ b/src/gpt_review/_ask.py @@ -165,7 +165,7 @@ def _call_gpt( return completion.choices[0].message.content # type: ignore except RateLimitError as error: if retry < C.MAX_RETRIES: - logging.warning("Call to GPT failed due to rate limit, retry attempt: %s", retry) + logging.warning("Call to GPT failed due to rate limit, retry attempt %s of %s", retry, C.RETRY_LIMIT) time.sleep(retry * 10) return _call_gpt(prompt, temperature, max_tokens, top_p, frequency_penalty, presence_penalty, retry + 1) raise RateLimitError("Retry limit exceeded") from error diff --git a/src/gpt_review/constants.py b/src/gpt_review/constants.py index 3b9cc161..40b3e1dc 100644 --- a/src/gpt_review/constants.py +++ b/src/gpt_review/constants.py @@ -22,4 +22,4 @@ PRESENCE_PENALTY_MIN = 0 PRESENCE_PENALTY_MAX = 2 -MAX_RETRIES = os.getenv("MAX_RETRIES", 10) +MAX_RETRIES = int(os.getenv("MAX_RETRIES", 10)) From 3ab49ed34599ed12917068ccb0b28874baa4baf1 Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:18:14 -0400 Subject: [PATCH 8/9] Update src/gpt_review/_llama_index.py --- src/gpt_review/_llama_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpt_review/_llama_index.py b/src/gpt_review/_llama_index.py index a6d9cf68..1308b4ab 100644 --- a/src/gpt_review/_llama_index.py +++ b/src/gpt_review/_llama_index.py @@ -56,7 +56,7 @@ def _document_indexer( "api_type": "azure", "api_version": "2023-03-15-preview", }, - max_retries=MAX_RETRIES, + max_retries=C.MAX_RETRIES, ) llm_predictor = LLMPredictor(llm=llm) From 7630712712d9f03fba3e4ed6c813f6373cdc5d9e Mon Sep 17 00:00:00 2001 From: Daniel Ciborowski Date: Mon, 8 May 2023 17:27:35 -0400 Subject: [PATCH 9/9] Apply suggestions from code review --- src/gpt_review/_ask.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gpt_review/_ask.py b/src/gpt_review/_ask.py index c12055a4..5ed020df 100644 --- a/src/gpt_review/_ask.py +++ b/src/gpt_review/_ask.py @@ -165,7 +165,7 @@ def _call_gpt( return completion.choices[0].message.content # type: ignore except RateLimitError as error: if retry < C.MAX_RETRIES: - logging.warning("Call to GPT failed due to rate limit, retry attempt %s of %s", retry, C.RETRY_LIMIT) + logging.warning("Call to GPT failed due to rate limit, retry attempt %s of %s", retry, C.MAX_RETRIES) time.sleep(retry * 10) return _call_gpt(prompt, temperature, max_tokens, top_p, frequency_penalty, presence_penalty, retry + 1) raise RateLimitError("Retry limit exceeded") from error