Here is a fully functioning code that will allow you to run LLM (large language model) on your device locally. Think of it as GPT that works without an internet connection and protects your privacy.
Feel free to use it for your own AI projects!
Check out other tutorials:LLMs - Resources & Tutorials
Code base: Python
Framework: GPT4All
Model: GPT4All Falcon
from gpt4all import GPT4All
model = GPT4All(model_name="ggml-model-gpt4all-falcon-q4_0.bin", model_path="./")
output = model.generate("write me a short story about lonely koala", max_tokens=500)
print(output)
If you wish to use it with Langchain framework, use the following code:
from langchain.llms import GPT4All
from langchain import ConversationChain, LLMChain, PromptTemplate
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
callbacks = [StreamingStdOutCallbackHandler()]
model = GPT4All(model="./ggml-model-gpt4all-falcon-q4_0.bin", max_tokens=500, temp=1.5)
template = "Aswer the following question: {question}"
prompt = PromptTemplate(input_variables=["question"], template=template)
localgpt_chain = LLMChain(
llm=model,
prompt=prompt,
verbose=True
)
question = "write me a rhyming poem about a quiet night"
localgpt_chain.run(question = question, callbacks=callbacks)
pip install gpt4all