Skip to content

Commit

Permalink
persist and load function fix (#1753)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfahad1414 authored Jan 22, 2025
1 parent c0d1f9c commit 15e86fa
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions kairon/nlu/classifiers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import faiss
import litellm
import numpy as np
import rasa.utils.io as io_utils
import ujson as json
from more_itertools import chunked
from rasa.engine.graph import GraphComponent, ExecutionContext
Expand Down Expand Up @@ -251,11 +250,11 @@ def load(
file_name = cls.__name__

vector_file = os.path.join(model_path, file_name + "_vector.db")
data_file = os.path.join(model_path, file_name + "_data.pkl")
data_file = os.path.join(model_path, file_name + "_data.json")

if os.path.exists(vector_file):
vector = faiss.read_index(vector_file)
data = io_utils.json_unpickle(data_file)
data = json.load(open(data_file, "r"))
return cls(
config, model_storage, resource, execution_context, vector, data
)
Expand All @@ -272,15 +271,16 @@ def persist(self) -> None:
"""Persist this model into the passed directory."""
with self._model_storage.write_to(self._resource) as model_path:
file_name = self.__class__.__name__
vector_file_name = file_name + "_vector.db"
data_file_name = file_name + "_data.pkl"
vector_file = os.path.join(model_path, file_name + "_vector.db")
data_file = os.path.join(model_path, file_name + "_data.json")

if self.vector and self.data:
create_directory_for_file(model_path)
faiss.write_index(
self.vector, os.path.join(model_path, vector_file_name)
self.vector, vector_file
)
io_utils.json_pickle(
os.path.join(model_path, data_file_name), self.data
json.dump(
self.data, open(data_file, "w"), escape_forward_slashes=True
)

def add_extractor_name(
Expand Down

0 comments on commit 15e86fa

Please sign in to comment.