Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase retry limit and provide override #61

Merged
merged 9 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gpt_review/_ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.MAX_RETRIES:
logging.warning("Call to GPT failed due to rate limit, retry attempt: %s", retry)
dciborow marked this conversation as resolved.
Show resolved Hide resolved
time.sleep(retry * 10)
return _call_gpt(prompt, temperature, max_tokens, top_p, frequency_penalty, presence_penalty, retry + 1)
Expand Down
4 changes: 3 additions & 1 deletion src/gpt_review/_llama_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -54,7 +56,7 @@ def _document_indexer(
"api_type": "azure",
"api_version": "2023-03-15-preview",
},
max_retries=10,
max_retries=MAX_RETRIES,
dciborow marked this conversation as resolved.
Show resolved Hide resolved
)

llm_predictor = LLMPredictor(llm=llm)
Expand Down
3 changes: 3 additions & 0 deletions src/gpt_review/constants.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,3 +21,5 @@
PRESENCE_PENALTY_DEFAULT = 0
PRESENCE_PENALTY_MIN = 0
PRESENCE_PENALTY_MAX = 2

MAX_RETRIES = os.getenv("MAX_RETRIES", 10)
dciborow marked this conversation as resolved.
Show resolved Hide resolved