Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
813 B
1
Indexable
Never
from flask import Flask, request, jsonify
from transformers import pipeline
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import FAISS
from langchain.chains import RetrievalQAChain

app = Flask(__name__)

# Load AI models
nlp_model = pipeline("text2text-generation", model="gpt-3.5-turbo")
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
vectorstore = FAISS.from_embeddings(documents, embeddings)
qa_chain = RetrievalQAChain(
    vectorstore=vectorstore,
    combine_docs=True,
    question_generator=nlp_model,
    llm=nlp_model,
)

@app.route('/ask', methods=['POST'])
def ask_question():
  query = request.json['query']
  response = qa_chain.run(query)
  return jsonify({'response': response})

if __name__ == '__main__':
  app.run()
Leave a Comment