text stringlengths 1 93.6k |
|---|
print("LLM Initialized...")
|
prompt_template = """Use the following pieces of information to answer the user's question.
|
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
Context: {context}
|
Question: {question}
|
Only return the helpful answer below and nothing else.
|
Helpful answer:
|
"""
|
model_name = "BAAI/bge-large-en"
|
model_kwargs = {'device': 'cpu'}
|
encode_kwargs = {'normalize_embeddings': False}
|
embeddings = HuggingFaceBgeEmbeddings(
|
model_name=model_name,
|
model_kwargs=model_kwargs,
|
encode_kwargs=encode_kwargs
|
)
|
prompt = PromptTemplate(template=prompt_template, input_variables=['context', 'question'])
|
load_vector_store = Chroma(persist_directory="stores/pet_cosine", embedding_function=embeddings)
|
retriever = load_vector_store.as_retriever(search_kwargs={"k":1})
|
# query = "what is the fastest speed for a greyhound dog?"
|
# semantic_search = retriever.get_relevant_documents(query)
|
# print(semantic_search)
|
print("######################################################################")
|
chain_type_kwargs = {"prompt": prompt}
|
# qa = RetrievalQA.from_chain_type(
|
# llm=llm,
|
# chain_type="stuff",
|
# retriever=retriever,
|
# return_source_documents = True,
|
# chain_type_kwargs= chain_type_kwargs,
|
# verbose=True
|
# )
|
# response = qa(query)
|
# print(response)
|
sample_prompts = ["what is the fastest speed for a greyhound dog?", "Why should we not feed chocolates to the dogs?", "Name two factors which might contribute to why some dogs might get scared?"]
|
def get_response(input):
|
query = input
|
chain_type_kwargs = {"prompt": prompt}
|
qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever, return_source_documents=True, chain_type_kwargs=chain_type_kwargs, verbose=True)
|
response = qa(query)
|
return response
|
input = gr.Text(
|
label="Prompt",
|
show_label=False,
|
max_lines=1,
|
placeholder="Enter your prompt",
|
container=False,
|
)
|
iface = gr.Interface(fn=get_response,
|
inputs=input,
|
outputs="text",
|
title="My Dog PetCare Bot",
|
description="This is a RAG implementation based on Zephyr 7B Beta LLM.",
|
examples=sample_prompts,
|
allow_screenshot=False,
|
allow_flagging=False
|
)
|
iface.launch()
|
# <FILESEP>
|
import moviepy.video.io.ImageSequenceClip
|
# import imageio
|
#
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.