Update app.py
Browse files254 unmodified lines25525625725825926026126226326412 unmodified lines277278279276280281282283284285286281287288289132 unmodified lines422423424425426427421422423424425426427428429430431428429430431432433434435436437438439440441433442443444445446447254 unmodified lines return summary
def rank_search_results(titles, summaries, model): if not titles or not summaries: print("No titles or summaries to rank.") return list(range(1, len(titles) + 1))
ranking_prompt = ( "Rank the following search results from a financial analyst perspective. " f"Assign a rank from 1 to {len(titles)} based on relevance, with 1 being the most relevant. "12 unmodified lines # Check if we have the correct number of ranks if len(ranks) != len(titles): raise ValueError("Number of ranks does not match number of titles") print(f"Warning: Number of ranks ({len(ranks)}) does not match number of titles ({len(titles)})") print(f"Model output: {ranks_str}") return list(range(1, len(titles) + 1)) return ranks except Exception as e: print(f"Error in ranking: {str(e)}. Using fallback ranking method.") # Fallback: assign ranks based on original order return list(range(1, len(titles) + 1))
def ask_question(question, temperature, top_p, repetition_penalty, web_search):132 unmodified lines current_date = datetime.now().strftime("%Y-%m-%d") documents = [] for result, summary, rank in zip(search_results, summaries, ranks): if summary: # Only create a document if there's a summary doc = Document( page_content=summary, metadata={ "search_date": current_date, "search_title": result["title"], "search_content": result["text"], "search_summary": summary, "rank": rank } ) database.add_documents([doc]) doc = Document( page_content=summary, metadata={ "search_date": current_date, "search_title": result["title"], "search_content": result["text"], "search_summary": summary, "rank": rank } ) documents.append(doc) if documents: # Only update the database if there are documents to add database.add_documents(documents) database.save_local("faiss_database") database.save_local("faiss_database") else: print("No valid documents to add to the database.")
def export_vector_db_to_excel(): embed = get_embeddings()app.py+25-14