Spaces:
Build error
Build error
# This script inits the models and adds an example collection to the Vectorstore | |
# %% | |
import os | |
import pathlib | |
from load_model import load_embedding | |
from utils import get_chroma_client | |
from load_vectors import load_from_web, create_and_add, load_and_split | |
current_path = str( pathlib.Path(__file__).parent.resolve() ) | |
with open(current_path+'/.openaiapikey', 'r') as reader: | |
os.environ['OPENAI_API_KEY']=reader.read() | |
import load_model | |
# %% | |
#load_model.load_gpu_model("decapoda-research/llama-7b-hf") #Download local model | |
llm= load_model.load_openai_model() | |
# %% | |
#Load example Data | |
client = get_chroma_client() | |
client.reset() | |
ef = load_embedding("hkunlp/instructor-large") | |
collection_name="axaterms" | |
metadata= {"loaded_docs":[], "Subject":"AXA Terms", "model_name": ef.model_name} | |
selected_collection = client.create_collection(collection_name, embedding_function=ef, metadata=metadata) | |
docs_tarifs= [ | |
"https://www.axa.de/site/axa-de/get/documents_E1883536226/axade/medien/privatkunden/haus-und-wohnen/hausratversicherung/hausrat-versicherungsbedingungen-L.pdf", | |
] | |
# %% | |
# Load collection to get metadata | |
loaded_collection = client.get_collection(collection_name) | |
model_name = loaded_collection.metadata['model_name'] | |
# %% | |
docs = load_from_web(docs_tarifs) | |
sub_docs = load_and_split(docs, chunk_size=1000) | |
create_and_add(collection_name, sub_docs, model_name, metadata) | |
# %% | |
chain = load_model.create_chain(llm, collection=collection_name, model_name=model_name, metadata=metadata) | |
#result = chain({"query": "Ist mein Kinderwagen bei einem Leitungswasserschaden mitversichert?"}) | |
#print(result) | |