Skip to content

Commit

Permalink
Merge branch 'apache:main' into delete_gremlin_tmpl
Browse files Browse the repository at this point in the history
  • Loading branch information
HJ-Young authored Dec 26, 2024
2 parents 75693e3 + 2854948 commit 251cbec
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions hugegraph-llm/src/hugegraph_llm/models/llms/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@

import openai
import tiktoken
from openai import OpenAI, AsyncOpenAI
from retry import retry
from openai import OpenAI, AsyncOpenAI, RateLimitError, APITimeoutError, APIConnectionError
from tenacity import (
retry,
stop_after_attempt,
wait_exponential,
retry_if_exception_type,
)

from hugegraph_llm.models.llms.base import BaseLLM
from hugegraph_llm.utils.log import log
Expand All @@ -43,7 +48,11 @@ def __init__(
self.max_tokens = max_tokens
self.temperature = temperature

@retry(tries=3, delay=1)
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=4, max=10),
retry=retry_if_exception_type((RateLimitError, APIConnectionError, APITimeoutError)),
)
def generate(
self,
messages: Optional[List[Dict[str, Any]]] = None,
Expand Down Expand Up @@ -74,7 +83,11 @@ def generate(
log.error("Retrying LLM call %s", e)
raise e

@retry(tries=3, delay=1)
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=4, max=10),
retry=retry_if_exception_type((RateLimitError, APIConnectionError, APITimeoutError)),
)
async def agenerate(
self,
messages: Optional[List[Dict[str, Any]]] = None,
Expand Down

0 comments on commit 251cbec

Please sign in to comment.