From 7d211f3658762ee5b11eb6c0254f7d94c2d8976c Mon Sep 17 00:00:00 2001 From: Sophia Date: Sun, 2 Mar 2025 10:28:23 -0500 Subject: [PATCH 1/2] feat:second endpoint working --- backend/app.py | 12 ++++++++---- backend/scripts/search.py | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/backend/app.py b/backend/app.py index 6597314..76ea710 100644 --- a/backend/app.py +++ b/backend/app.py @@ -1,7 +1,7 @@ from flask import Flask, jsonify, request import json from scripts import search -from scripts.search import search_dif_languages +from scripts.search import search_dif_languages, change_top_descriptions from scripts.rank import add_embeddings, get_score, get_top_results # create main flask app (no templates) @@ -13,9 +13,13 @@ def index(): return "hello, codefest" -@app.route("/search", methods=["GET", "POST"]) -def search_page(): - return "main page" +@app.route("/api/get-enhanced-descriptions", methods=["GET", "POST"]) +def get_enhanced_descriptions(): + input = request.get_json() + links = list(input['links']) + # gets enhanced descriptions as a list in the order the links were sent in + return jsonify({'new-desc':change_top_descriptions(links)}) + # takes the text prompt and returns json of top search reslts @app.route("/api/get-search-result", methods=["GET", "POST"]) diff --git a/backend/scripts/search.py b/backend/scripts/search.py index 532bab3..6ff1c46 100644 --- a/backend/scripts/search.py +++ b/backend/scripts/search.py @@ -237,24 +237,34 @@ def search_dif_languages(user_search: str, languages: list) -> dict: get_score(search_data) multilang_top_hits = get_top_results(search_data, 3) - - + + return multilang_top_hits + +def change_top_descriptions(top_hits: list): + """ + ### Returns possible changed descriptions in top 3 hits + across all languages + - Returns new descriptions as list of strings from gpt api + + #### args: + top_hits: list of strings (the links) + """ # try to change the description of top 3 best results to revised summary - for hit in multilang_top_hits: - web_url = hit["link"] + enhanced = {} + for i, hit in enumerate(top_hits): + enhanced[hit] = "" # try changing the snippet description for each entry in list try: - page_description = get_website_description(web_url) + page_description = get_website_description(hit) if page_description is not None: - hit["snippet"] = page_description + enhanced[hit] = page_description # if it doesn't work just do nothing to snippet except: - pass - - return multilang_top_hits + enhanced[hit] = "" + return enhanced # Debugging main functions code: From 2b36d38286b2c01365532533a210e3b9c07cdf5d Mon Sep 17 00:00:00 2001 From: Sophia Date: Sun, 2 Mar 2025 10:33:19 -0500 Subject: [PATCH 2/2] fix:modified return format --- backend/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app.py b/backend/app.py index 76ea710..891604e 100644 --- a/backend/app.py +++ b/backend/app.py @@ -18,7 +18,7 @@ def get_enhanced_descriptions(): input = request.get_json() links = list(input['links']) # gets enhanced descriptions as a list in the order the links were sent in - return jsonify({'new-desc':change_top_descriptions(links)}) + return jsonify(change_top_descriptions(links)) # takes the text prompt and returns json of top search reslts