repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import logging |
| #2 | import os # noqa: F401 |
| #3 | from typing import Any |
| #4 | |
| #5 | from gptcache import cache # noqa: F401 |
| #6 | from gptcache.adapter.adapter import adapt # noqa: F401 |
| #7 | from gptcache.config import Config # noqa: F401 |
| #8 | from gptcache.manager import get_data_manager |
| #9 | from gptcache.manager.scalar_data.base import Answer |
| #10 | from gptcache.manager.scalar_data.base import DataType as CacheDataType |
| #11 | from gptcache.session import Session |
| #12 | from gptcache.similarity_evaluation.distance import ( # noqa: F401 |
| #13 | SearchDistanceEvaluation, |
| #14 | ) |
| #15 | from gptcache.similarity_evaluation.exact_match import ( # noqa: F401 |
| #16 | ExactMatchEvaluation, |
| #17 | ) |
| #18 | |
| #19 | logger = logging.getLogger(__name__) |
| #20 | |
| #21 | |
| #22 | def gptcache_pre_function(data: dict[str, Any], **params: dict[str, Any]): |
| #23 | return data["input_query"] |
| #24 | |
| #25 | |
| #26 | def gptcache_data_manager(vector_dimension): |
| #27 | return get_data_manager(cache_base="sqlite", vector_base="chromadb", max_size=1000, eviction="LRU") |
| #28 | |
| #29 | |
| #30 | def gptcache_data_convert(cache_data): |
| #31 | logger.info("[Cache] Cache hit, returning cache data...") |
| #32 | return cache_data |
| #33 | |
| #34 | |
| #35 | def gptcache_update_cache_callback(llm_data, update_cache_func, *args, **kwargs): |
| #36 | logger.info("[Cache] Cache missed, updating cache...") |
| #37 | update_cache_func(Answer(llm_data, CacheDataType.STR)) |
| #38 | return llm_data |
| #39 | |
| #40 | |
| #41 | def _gptcache_session_hit_func(cur_session_id: str, cache_session_ids: list, cache_questions: list, cache_answer: str): |
| #42 | return cur_session_id in cache_session_ids |
| #43 | |
| #44 | |
| #45 | def get_gptcache_session(session_id: str): |
| #46 | return Session(name=session_id, check_hit_func=_gptcache_session_hit_func) |
| #47 |