fix utils.py

This commit is contained in:
Ishaan Jaff 2024-05-15 19:54:52 -07:00
parent 1a67f244fb
commit 765d43d241

View file

@ -19,7 +19,7 @@ from functools import wraps, lru_cache
import datetime, time import datetime, time
import tiktoken import tiktoken
import uuid import uuid
from pydantic import ConfigDict, BaseModel, VERSION from pydantic import BaseModel
import aiohttp import aiohttp
import textwrap import textwrap
import logging import logging
@ -185,23 +185,6 @@ last_fetched_at_keys = None
# } # }
# Function to get Pydantic version
def is_pydantic_v2() -> int:
return int(VERSION.split(".")[0])
def get_model_config(arbitrary_types_allowed: bool = False) -> ConfigDict:
# Version-specific configuration
if is_pydantic_v2() >= 2:
model_config = ConfigDict(extra="allow", arbitrary_types_allowed=arbitrary_types_allowed, protected_namespaces=()) # type: ignore
else:
from pydantic import Extra
model_config = ConfigDict(extra=Extra.allow, arbitrary_types_allowed=arbitrary_types_allowed) # type: ignore
return model_config
class UnsupportedParamsError(Exception): class UnsupportedParamsError(Exception):
def __init__(self, status_code, message): def __init__(self, status_code, message):
self.status_code = status_code self.status_code = status_code
@ -348,7 +331,10 @@ class HiddenParams(OpenAIObject):
original_response: Optional[str] = None original_response: Optional[str] = None
model_id: Optional[str] = None # used in Router for individual deployments model_id: Optional[str] = None # used in Router for individual deployments
api_base: Optional[str] = None # returns api base used for making completion call api_base: Optional[str] = None # returns api base used for making completion call
model_config = get_model_config()
class Config:
extra = "allow"
protected_namespaces = ()
def get(self, key, default=None): def get(self, key, default=None):
# Custom .get() method to access attributes with a default value if the attribute doesn't exist # Custom .get() method to access attributes with a default value if the attribute doesn't exist