Fix llm cache save problem in json_kv storage
This commit is contained in:
@@ -96,12 +96,12 @@ class JsonDocStatusStorage(DocStatusStorage):
|
|||||||
write_json(data_dict, self._file_name)
|
write_json(data_dict, self._file_name)
|
||||||
|
|
||||||
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
|
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
|
||||||
logger.info(f"Inserting {len(data)} to {self.namespace}")
|
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
|
logger.info(f"Inserting {len(data)} to {self.namespace}")
|
||||||
async with self._storage_lock:
|
async with self._storage_lock:
|
||||||
self._data.update(data)
|
self._data.update(data)
|
||||||
|
|
||||||
await self.index_done_callback()
|
await self.index_done_callback()
|
||||||
|
|
||||||
async def get_by_id(self, id: str) -> Union[dict[str, Any], None]:
|
async def get_by_id(self, id: str) -> Union[dict[str, Any], None]:
|
||||||
|
@@ -98,11 +98,9 @@ class JsonKVStorage(BaseKVStorage):
|
|||||||
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
|
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
|
||||||
if not data:
|
if not data:
|
||||||
return
|
return
|
||||||
|
logger.info(f"Inserting {len(data)} to {self.namespace}")
|
||||||
async with self._storage_lock:
|
async with self._storage_lock:
|
||||||
left_data = {k: v for k, v in data.items() if k not in self._data}
|
self._data.update(data)
|
||||||
if left_data:
|
|
||||||
logger.info(f"Process {os.getpid()} KV inserting {len(left_data)} to {self.namespace}")
|
|
||||||
self._data.update(left_data)
|
|
||||||
|
|
||||||
async def delete(self, ids: list[str]) -> None:
|
async def delete(self, ids: list[str]) -> None:
|
||||||
async with self._storage_lock:
|
async with self._storage_lock:
|
||||||
|
@@ -403,6 +403,7 @@ async def extract_entities(
|
|||||||
else:
|
else:
|
||||||
_prompt = input_text
|
_prompt = input_text
|
||||||
|
|
||||||
|
# TODO: add cache_type="extract"
|
||||||
arg_hash = compute_args_hash(_prompt)
|
arg_hash = compute_args_hash(_prompt)
|
||||||
cached_return, _1, _2, _3 = await handle_cache(
|
cached_return, _1, _2, _3 = await handle_cache(
|
||||||
llm_response_cache,
|
llm_response_cache,
|
||||||
@@ -431,7 +432,6 @@ async def extract_entities(
|
|||||||
cache_type="extract",
|
cache_type="extract",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
logger.info(f"Extract: saved cache for {arg_hash}")
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
if history_messages:
|
if history_messages:
|
||||||
|
Reference in New Issue
Block a user