From da1f06928e0eebe658abbd15b907bd643dc2dd67 Mon Sep 17 00:00:00 2001 From: ajaysi Date: Sun, 6 Apr 2025 17:20:38 +0530 Subject: [PATCH] AI Content planning and competitor analysis. Tight integration with Alwrity, tavily and metaphor. --- .../metaphor_basic_neural_web_search.py | 53 +------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/lib/ai_web_researcher/metaphor_basic_neural_web_search.py b/lib/ai_web_researcher/metaphor_basic_neural_web_search.py index 698bd3ea..75fe8eb8 100644 --- a/lib/ai_web_researcher/metaphor_basic_neural_web_search.py +++ b/lib/ai_web_researcher/metaphor_basic_neural_web_search.py @@ -40,8 +40,6 @@ def get_metaphor_client(): """ METAPHOR_API_KEY = os.environ.get('METAPHOR_API_KEY') if not METAPHOR_API_KEY: - logger.error("METAPHOR_API_KEY environment variable not set!") - st.error("METAPHOR_API_KEY environment variable not set!") logger.error("METAPHOR_API_KEY environment variable not set!") st.error("METAPHOR_API_KEY environment variable not set!") raise ValueError("METAPHOR_API_KEY environment variable not set!") @@ -50,6 +48,7 @@ def get_metaphor_client(): def metaphor_rag_search(): """ Mainly used for researching blog sections. """ + # FIXME: Implement this. metaphor = get_metaphor_client() query = "blog research" # Example query, this can be parameterized as needed results = metaphor.search(query) @@ -66,6 +65,7 @@ def metaphor_rag_search(): st.write(processed_results) return processed_results + def metaphor_find_similar(similar_url, usecase, num_results=5, start_published_date=None, end_published_date=None, include_domains=None, exclude_domains=None, include_text=None, exclude_text=None, summary_query=None): @@ -82,19 +82,8 @@ def metaphor_find_similar(similar_url, usecase, num_results=5, start_published_d include_text (str): Text that must be included in the results. exclude_text (str): Text that must be excluded from the results. summary_query (dict): Custom query for summarization. - similar_url (str): The URL to find similar content. - usecase (str): The use case for the search (e.g., "similar companies", "listicles"). - num_results (int): Number of results to return (default: 5). - start_published_date (str): Start date for filtering results in ISO format. - end_published_date (str): End date for filtering results in ISO format. - include_domains (list): List of domains to include in the search. - exclude_domains (list): List of domains to exclude from the search. - include_text (str): Text that must be included in the results. - exclude_text (str): Text that must be excluded from the results. - summary_query (dict): Custom query for summarization. Returns: tuple: (DataFrame, MetaphorResponse) - The DataFrame contains the results and the MetaphorResponse contains the raw API response. - tuple: (DataFrame, MetaphorResponse) - The DataFrame contains the results and the MetaphorResponse contains the raw API response. """ metaphor = get_metaphor_client() try: @@ -106,39 +95,6 @@ def metaphor_find_similar(similar_url, usecase, num_results=5, start_published_d "num_results": num_results, } - # Add date parameters if provided - if start_published_date: - search_params["start_published_date"] = start_published_date - if end_published_date: - search_params["end_published_date"] = end_published_date - - # Add domain filters if provided - if include_domains: - search_params["include_domains"] = include_domains - if exclude_domains: - search_params["exclude_domains"] = exclude_domains - - # Add text filters if provided - if include_text: - search_params["include_text"] = include_text - if exclude_text: - search_params["exclude_text"] = exclude_text - - # Add summary query if provided - if summary_query: - search_params["summary"] = summary_query - else: - # Default summary query based on usecase - search_params["summary"] = {"query": f"Find {usecase} similar to the given URL."} - - # Execute the search - - # Prepare search parameters - search_params = { - "highlights": True, - "num_results": num_results, - } - # Add date parameters if provided if start_published_date: search_params["start_published_date"] = start_published_date @@ -169,8 +125,6 @@ def metaphor_find_similar(similar_url, usecase, num_results=5, start_published_d similar_url, **search_params ) - **search_params - ) except Exception as e: logger.error(f"Metaphor: Error in finding similar content: {e}") raise @@ -247,9 +201,6 @@ def metaphor_find_similar(similar_url, usecase, num_results=5, start_published_d # Return the DataFrame and the search response return df, search_response - - # Return the DataFrame and the search response - return df, search_response def calculate_date_range(time_range: str) -> tuple: