Find answers from the community

Updated 2 years ago

Custom

At a glance

The community member is encountering an AttributeError related to the callbacks attribute in their custom LLM class. They have provided the full code for their CustomLLM and CustomServiceContext classes. A comment from another community member suggests that the code is a little outdated and provides a link to the up-to-date guide for using a custom LLM in the GPT-Index library.

Useful resources
Hello can anyone help with this error :
AttributeError: 'CustomLLM' object has no attribute 'callbacks'
And my entire code is this :


class CustomServiceContext(ServiceContext):
def init(self, args, kwargs): super().init(args, kwargs)
self.callbacks = None

class CustomLLM(LLM):
def init(self):
# Set the model name
model_name = "google/flan-t5-large"
# Set the callbacks attribute to an empty list or None
callbacks = []

def _call(self, prompt, stop=None):
pipeline_obj = pipeline("text2text-generation", model=self.model_name, device=torch.device('cuda' if torch.cuda.is_available() else 'cpu'), model_kwargs={"torch_dtype": torch.bfloat16})
return pipeline_obj(prompt, max_length=9999)[0]["generated_text"]

def _identifying_params(self):
return {"name_of_model": "google/flan-t5-large"}

def _llm_type(self):
return "custom"
Create the predictor using the custom model
llm_predictor = LLMPredictor(llm=CustomLLM())

text_list = [text1]

documents = [Document(text=text1)]

hfemb = HuggingFaceEmbeddings()
embed_model = LangchainEmbedding(hfemb)

service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embed_model)
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)


query_engine = index.as_query_engine()
response = query_engine.query("what are the articles about?")
print(response)
Add a reply
Sign up and join the conversation on Discord