AI Content planning and competitor analysis.
Tight integration with Alwrity, tavily and metaphor.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user