| |
|
| | from flask import Flask, request,jsonify |
| | import os |
| | import google.generativeai as genai |
| | import utils as ut |
| | |
| |
|
| | app = Flask(__name__) |
| |
|
| | @app.route('/', methods=['GET']) |
| | def test(): |
| | print("Inside test") |
| | return jsonify({"message":"Application is Working!!"}) |
| |
|
| |
|
| | @app.route('/query', methods=['POST']) |
| | def query(): |
| | """ |
| | Handles the POST request to '/query'. Extracts the query from the request, |
| | processes it through the search, concatenate, and generate functions, |
| | and returns the generated answer. |
| | """ |
| | if request.is_json: |
| | |
| | query = request.json.get('query') |
| | |
| | print("Received query: ", query) |
| | |
| | |
| | print("Step 1: searching articles") |
| | articles=ut.search_articles(query) |
| | |
| | print("Step 2: concatenating content") |
| | extracted_content = ut.fetch_article_content(articles) |
| | |
| | print("Step 3: generating answer") |
| | llm_response = ut.generate_answer(extracted_content,query) |
| | |
| | return jsonify({"answer": llm_response}) |
| |
|