Spaces:
Runtime error
Runtime error
metadata
title: Haystack-7-wonders
emoji: π
colorFrom: indigo
colorTo: red
sdk: docker
app_file: app.py
pinned: false
Welcome!
This chatbot uses RAG to answer questions about the Seven Wonders of the Ancient World.
Here are sample questions you can ask it:
- What is the Great Pyramid of Giza?
- What is the Hanging Gardens of Babylon?
- What is the Temple of Artemis at Ephesus?
- What is the Statue of Zeus at Olympia?
- What is the Mausoleum at Halicarnassus?
- Where is Gardens of Babylon?
- Why did people build Great Pyramid of Giza?
- What does Rhodes Statue look like?
- Why did people visit the Temple of Artemis?
- What is the importance of Colossus of Rhodes?
- What happened to the Tomb of Mausolus?
- How did Colossus of Rhodes collapse?
How is it built?
Poetry package management
This project uses Poetry for package management.
It uses this pyproject.toml
file
To install dependencies:
pip install poetry
poetry install
Data source:
The data is from the [Seven Wonders dataset][1] on Hugging Face. https://huggingface.co/datasets/bilgeyucel/seven-wonders
Method
The chatbots retrieval mechanism is developed using Retrieval Augmented Generation (RAG) with Haystack and its user interface is built with Chainlit. It is using OpenAI GPT-3.5-turbo.
Pipeline steps (Haystack) - check the full script here: app.py
- Initialize in-memory Document store
# Initialize Haystack's QA system
document_store = InMemoryDocumentStore(use_bm25=True)
- Load dataset from HF
dataset = load_dataset("bilgeyucel/seven-wonders", split="train")
- Transform documents and load into document store
document_store.write_documents(dataset)
- Initialize a RAG prompt
rag_prompt = PromptTemplate(
prompt="""Synthesize a brief answer from the following text for the given question.
Provide a clear and concise response that summarizes the key points and information presented in the text.
Your answer should be in your own words and be no longer than 50 words.
\n\n Related text: {join(documents)} \n\n Question: {query} \n\n Answer:""",
output_parser=AnswerParser(),
)
- Set the nodes using GPT-3.5-turbo
Set up nodes
retriever = BM25Retriever(document_store=document_store, top_k=2)
pn = PromptNode("gpt-3.5-turbo",
api_key=MY_API_KEY,
model_kwargs={"stream":False},
default_prompt_template=rag_prompt)
- Build the pipeline
# Set up pipeline
pipe = Pipeline()
pipe.add_node(component=retriever, name="retriever", inputs=["Query"])
pipe.add_node(component=pn, name="prompt_node", inputs=["retriever"])
Connecting the pipeline to Chainlit
@cl.on_message
async def main(message: str):
# Use the pipeline to get a response
output = pipe.run(query=message)
# Create a Chainlit message with the response
response = output['answers'][0].answer
msg = cl.Message(content=response)
# Send the message to the user
await msg.send()
Run application
poetry run chainlit run app.py --port 7860