Skip to content

Commit

Permalink
🔄 Refactor retry logic in helpers.py
Browse files Browse the repository at this point in the history
  • Loading branch information
shroominic committed Nov 8, 2023
1 parent 3e84c10 commit e9f567a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions funcchain/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from docstring_parser import parse
from langchain.chat_models import ChatOpenAI
from langchain.chat_models.base import BaseChatModel
from langchain.llms.base import BaseLanguageModel
from langchain.pydantic_v1 import BaseModel
from langchain.schema.language_model import BaseLanguageModel
from langchain.schema.messages import HumanMessage, SystemMessage
from langchain.schema.output_parser import OutputParserException
from langchain.schema.runnable import Runnable, RunnableWithFallbacks
Expand All @@ -27,11 +27,11 @@ def decorator(fn):

@wraps(fn)
async def async_wrapper(*args, **kwargs):
for _ in range(retry):
for r in range(retry):
try:
return await fn(*args, **kwargs)
except OutputParserException as e:
if _ == retry - 1:
if r == retry - 1:
raise e
await asyncio.sleep(1)

Expand All @@ -41,11 +41,11 @@ async def async_wrapper(*args, **kwargs):

@wraps(fn)
def sync_wrapper(*args, **kwargs):
for _ in range(retry):
for r in range(retry):
try:
return fn(*args, **kwargs)
except OutputParserException as e:
if _ == retry - 1:
if r == retry - 1:
raise e

return sync_wrapper
Expand Down

0 comments on commit e9f567a

Please sign in to comment.