Spaces:
Runtime error
Runtime error
Zwea Htet commited on
Commit ·
991fc6b
1
Parent(s): 215cfd3
fixed ui
Browse files35 unmodified lines363738394041424344454647484950515253545556575859604 unmodified lines656667686970717273747576777879808115 unmodified lines97989910010110210335 unmodified lines# set maximum chunk overlapCHUNK_OVERLAP_RATION = 0.2llm_model_name = "bigscience/bloom-560m"tokenizer = AutoTokenizer.from_pretrained(llm_model_name)model = AutoModelForCausalLM.from_pretrained(llm_model_name, config="T5Config")model_pipeline = pipeline(model=model,tokenizer=tokenizer,task="text-generation",# device=0, # GPU device number# max_length=512,do_sample=True,top_p=0.95,top_k=50,temperature=0.7,)class CustomLLM(LLM):pipeline = model_pipelinedef _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:prompt_length = len(prompt)4 unmodified lines@propertydef _identifying_params(self) -> Mapping[str, Any]:return {"name_of_model": llm_model_name}@propertydef _llm_type(self) -> str:return "custom"class LlamaCustom:def __init__(self, model_name: str) -> None:self.vector_index = self.initialize_index(model_name=model_name)def initialize_index(self, model_name: str):index_name = model_name.split("/")[-1]file_path = f"./vectorStores/{index_name}"15 unmodified linesnum_output=NUM_OUTPUT,chunk_overlap_ratio=CHUNK_OVERLAP_RATION,)llm_predictor = LLMPredictor(llm=CustomLLM())service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)35 unmodified lines36373839404142434445464748495051525354555657585960616263646566674 unmodified lines7273747576777879808182838485868788899015 unmodified lines10610710810911011111211335 unmodified lines# set maximum chunk overlapCHUNK_OVERLAP_RATION = 0.2@st.cache_resourcedef load_model(mode_name: str):# llm_model_name = "bigscience/bloom-560m"tokenizer = AutoTokenizer.from_pretrained(mode_name)model = AutoModelForCausalLM.from_pretrained(mode_name, config="T5Config")pipe = pipeline(task="text-generation",model=model,tokenizer=tokenizer,# device=0, # GPU device number# max_length=512,do_sample=True,top_p=0.95,top_k=50,temperature=0.7,)return pipeclass CustomLLM(LLM):def __init__(self, model_name: str):self.llm_model_name = model_nameself.pipeline = load_model(mode_name=model_name)def _call(self, prompt: str, stop: Optional[List[str]] = None) -> str:prompt_length = len(prompt)4 unmodified lines@propertydef _identifying_params(self) -> Mapping[str, Any]:return {"name_of_model": self.llm_model_name}@propertydef _llm_type(self) -> str:return "custom"class LlamaCustom:def __init__(self, model_name: str) -> None:self.vector_index = self.initialize_index(model_name=model_name)@st.cache_resourcedef initialize_index(_self, model_name: str):index_name = model_name.split("/")[-1]file_path = f"./vectorStores/{index_name}"15 unmodified linesnum_output=NUM_OUTPUT,chunk_overlap_ratio=CHUNK_OVERLAP_RATION,)llm_predictor = LLMPredictor(llm=CustomLLM(model_name=model_name))service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
models/llamaCustom.py+29-19