forked from phoenix/litellm-mirror
use tenacity for langsmith
This commit is contained in:
parent
15277aff1c
commit
0a6a437e64
1 changed files with 10 additions and 11 deletions
|
@ -9,13 +9,16 @@ import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Any, List, Optional, Union
|
from typing import Any, List, Optional, Union
|
||||||
|
|
||||||
import backoff
|
|
||||||
import dotenv # type: ignore
|
import dotenv # type: ignore
|
||||||
import httpx
|
import httpx
|
||||||
import requests # type: ignore
|
import requests # type: ignore
|
||||||
from backoff import on_exception
|
|
||||||
from backoff._typing import Details
|
|
||||||
from pydantic import BaseModel # type: ignore
|
from pydantic import BaseModel # type: ignore
|
||||||
|
from tenacity import (
|
||||||
|
retry,
|
||||||
|
retry_if_exception_type,
|
||||||
|
stop_after_attempt,
|
||||||
|
wait_exponential,
|
||||||
|
)
|
||||||
|
|
||||||
import litellm
|
import litellm
|
||||||
from litellm._logging import verbose_logger
|
from litellm._logging import verbose_logger
|
||||||
|
@ -58,12 +61,6 @@ def is_serializable(value):
|
||||||
return not isinstance(value, non_serializable_types)
|
return not isinstance(value, non_serializable_types)
|
||||||
|
|
||||||
|
|
||||||
def on_backoff(details: Details) -> None:
|
|
||||||
verbose_logger.warning(
|
|
||||||
f"Langsmith batch send failed. Retrying in {details['wait']} seconds. Attempt {details['tries']}/3"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class LangsmithLogger(CustomLogger):
|
class LangsmithLogger(CustomLogger):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.langsmith_api_key = os.getenv("LANGSMITH_API_KEY")
|
self.langsmith_api_key = os.getenv("LANGSMITH_API_KEY")
|
||||||
|
@ -290,8 +287,10 @@ class LangsmithLogger(CustomLogger):
|
||||||
except:
|
except:
|
||||||
verbose_logger.error(f"Langsmith Layer Error - {traceback.format_exc()}")
|
verbose_logger.error(f"Langsmith Layer Error - {traceback.format_exc()}")
|
||||||
|
|
||||||
@on_exception(
|
@retry(
|
||||||
backoff.expo, (httpx.HTTPError, Exception), max_tries=3, on_backoff=on_backoff
|
stop=stop_after_attempt(3),
|
||||||
|
wait=wait_exponential(multiplier=1, min=4, max=10),
|
||||||
|
retry=retry_if_exception_type((httpx.HTTPStatusError, Exception)),
|
||||||
)
|
)
|
||||||
async def _async_send_batch(self):
|
async def _async_send_batch(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue