Add caching for langchain types dictionary

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-11-23 12:16:39 -03:00
commit 4e5ec2a4de

View file

@ -6,6 +6,7 @@ import warnings
from typing import Any, List, Optional, Union from typing import Any, List, Optional, Union
from uuid import UUID from uuid import UUID
from cachetools import LRUCache, cached
from fastapi import HTTPException from fastapi import HTTPException
from loguru import logger from loguru import logger
@ -49,6 +50,7 @@ def get_type_list():
return all_types return all_types
@cached(LRUCache(maxsize=1))
def build_langchain_types_dict(): # sourcery skip: dict-assign-update-to-union def build_langchain_types_dict(): # sourcery skip: dict-assign-update-to-union
"""Build a dictionary of all langchain types""" """Build a dictionary of all langchain types"""
all_types = {} all_types = {}