You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git clone https://github.com/holoviz/lumen.git
mkdir data
cp lumen/doc/**/*.md data
cp lumen/doc/*.md data
"""
fromtransformersimportAutoTokenizerfromllama_indeximport (
SimpleDirectoryReader,
VectorStoreIndex,
ServiceContext,
)
fromllama_index.llmsimportLlamaCPPfromllama_index.llms.llama_utilsimport (
messages_to_prompt,
completion_to_prompt,
)
fromllama_index.embeddingsimportHuggingFaceEmbeddingfrompanel.chatimportChatInterfaceBASE_REPO="HuggingFaceH4/zephyr-7b-beta"QUANTIZED_REPO="TheBloke/zephyr-7B-beta-GGUF"QUANTIZED_FILE="zephyr-7b-beta.Q5_K_S.gguf"DATA_DIR="data"defload_llm():
model_url=f"https://huggingface.co/{QUANTIZED_REPO}/resolve/main/{QUANTIZED_FILE}"llm=LlamaCPP(
# You can pass in the URL to a GGML model to download it automaticallymodel_url=model_url,
# optionally, you can set the path to a pre-downloaded model instead of model_urlmodel_path=None,
temperature=0.1,
max_new_tokens=256,
context_window=3900,
# kwargs to pass to __call__()generate_kwargs={},
# kwargs to pass to __init__()# set to at least 1 to use GPUmodel_kwargs={"n_gpu_layers": 1},
messages_to_prompt=messages_to_prompt,
completion_to_prompt=completion_to_prompt,
verbose=True,
)
returnllmdefload_tokenizer():
returnAutoTokenizer.from_pretrained(BASE_REPO)
defcreate_query_engine(llm):
embed_model=HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
service_context=ServiceContext.from_defaults(
llm=llm,
embed_model=embed_model,
)
documents=SimpleDirectoryReader(DATA_DIR, required_exts=[".md"]).load_data()
index=VectorStoreIndex.from_documents(documents, service_context=service_context)
query_engine=index.as_query_engine(streaming=True)
returnquery_engineasyncdefrespond(contents, user, instance):
conversation= [
{
"role": "system",
"content": "You are a friendly chatbot who will help the user.",
},
{"role": "user", "content": contents},
]
formatted_contents=tokenizer.apply_chat_template(
conversation, tokenize=False, add_generation_prompt=True
)
response=query_engine.query(formatted_contents)
message=Noneforchunkinresponse.response_gen:
message=instance.stream(chunk, message=message, user="Assistant")
llm=load_llm()
tokenizer=load_tokenizer()
query_engine=create_query_engine(llm)
chat_interface=ChatInterface(callback=respond, callback_exception="verbose")
chat_interface.send(
"This uses Llama Index to search through Lumen docs. Try asking a question, ""like: 'How do I add a hvplot view to penguins.csv?'",
user="System",
respond=False,
)
chat_interface.servable()
The text was updated successfully, but these errors were encountered:
"""
In the same directory:
"""
The text was updated successfully, but these errors were encountered: