Spaces:
Runtime error
Runtime error
Update models/llamaCustom.py
Browse files- models/llamaCustom.py +7 -4
models/llamaCustom.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import Any, List, Mapping, Optional
|
|
| 5 |
|
| 6 |
import numpy as np
|
| 7 |
import openai
|
|
|
|
| 8 |
import pandas as pd
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
from huggingface_hub import HfFileSystem
|
|
@@ -76,7 +77,7 @@ class CustomLLM(LLM):
|
|
| 76 |
def _llm_type(self) -> str:
|
| 77 |
return "custom"
|
| 78 |
|
| 79 |
-
|
| 80 |
class LlamaCustom:
|
| 81 |
# define llm
|
| 82 |
llm_predictor = LLMPredictor(llm=CustomLLM())
|
|
@@ -84,10 +85,12 @@ class LlamaCustom:
|
|
| 84 |
llm_predictor=llm_predictor, prompt_helper=prompt_helper
|
| 85 |
)
|
| 86 |
|
| 87 |
-
def __init__(self,
|
| 88 |
-
self.vector_index = self.initialize_index(index_name=
|
| 89 |
|
| 90 |
-
def initialize_index(self,
|
|
|
|
|
|
|
| 91 |
file_path = f"./vectorStores/{index_name}"
|
| 92 |
if os.path.exists(path=file_path):
|
| 93 |
# rebuild storage context
|
|
|
|
| 5 |
|
| 6 |
import numpy as np
|
| 7 |
import openai
|
| 8 |
+
import streamlit as st
|
| 9 |
import pandas as pd
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from huggingface_hub import HfFileSystem
|
|
|
|
| 77 |
def _llm_type(self) -> str:
|
| 78 |
return "custom"
|
| 79 |
|
| 80 |
+
@st.cache_resource
|
| 81 |
class LlamaCustom:
|
| 82 |
# define llm
|
| 83 |
llm_predictor = LLMPredictor(llm=CustomLLM())
|
|
|
|
| 85 |
llm_predictor=llm_predictor, prompt_helper=prompt_helper
|
| 86 |
)
|
| 87 |
|
| 88 |
+
def __init__(self, model_name: str) -> None:
|
| 89 |
+
self.vector_index = self.initialize_index(index_name=model_name)
|
| 90 |
|
| 91 |
+
def initialize_index(self, model_name: str):
|
| 92 |
+
index_name = model_name.split("/")[-1]
|
| 93 |
+
|
| 94 |
file_path = f"./vectorStores/{index_name}"
|
| 95 |
if os.path.exists(path=file_path):
|
| 96 |
# rebuild storage context
|