awakenai's picture
Update main.py
5c594c3
raw
history blame
1.7 kB
#from transformers import pipeline
from fastapi import FastAPI
app = FastAPI()
#generator = pipeline('text-generation',model='Open-Orca/Mistral-7B-OpenOrca')
from haystack.document_stores import InMemoryDocumentStore
from haystack.utils import build_pipeline, add_example_data, print_answers
# We are model agnostic :) Here, you can choose from: "anthropic", "cohere", "huggingface", and "openai".
provider = "openai"
API_KEY = "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" # ADD YOUR KEY HERE
# We support many different databases. Here we load a simple and lightweight in-memory database.
document_store = InMemoryDocumentStore(use_bm25=True)
# Download and add Game of Thrones TXT articles to Haystack DocumentStore.
# You can also provide a folder with your local documents.
#add_example_data(document_store, "data/GoT_getting_started")
add_example_data(document_store, "/content/Books")
# Build a pipeline with a Retriever to get relevant documents to the query and a PromptNode interacting with LLMs using a custom prompt.
pipeline = build_pipeline(provider, API_KEY, document_store)
# Ask a question on the data you just added.
result = pipeline.run(query="What is job yoga?")
# For details, like which documents were used to generate the answer, look into the <result> object
#print_answers(result, details="medium")
@app.get("/")
async def root():
#return {"message": "Hello World"}
#return generator('What is love',max_length=100, num_return_sequences=1)
return print_answers(result, details="medium")
@app.post("/predict")
async def root(text):
#return {"message": "Hello World"}
return generator(text,max_length=100, num_return_sequences=1)