Text Summarization Workflow
Text Summarization Workflow
The Eternity library is designed to streamline the process of gathering real-time web context for Large Language Models (LLMs) or automated reporting. By aggregating search results into a structured text format, it eliminates the manual overhead of parsing raw API responses.
Aggregating Search Context
To prepare data for summarization, the primary method used is get_combined_text. This function performs a live search and concatenates the top results into a single, human-readable string optimized for prompt injection.
get_combined_text(query)
Retrieves the top 5 search results and formats them into a serialized string including titles, snippets, and source URLs.
- Parameters:
query(str): The search term or question you want to research.
- Returns:
str: A formatted string containing aggregated metadata from the web.
Usage Example
The following example demonstrates how to initialize the library and retrieve a cleaned dataset ready for an LLM summarization prompt.
from eternity import Eternity
# Initialize the client
eternity = Eternity(api_key="YOUR_GOOGLE_API_KEY", engine_id="YOUR_ENGINE_ID")
# Generate aggregated text for a specific topic
search_query = "Recent advancements in quantum computing 2024"
context = eternity.get_combined_text(search_query)
# The output is now ready to be sent to an LLM provider (e.g., OpenAI, Anthropic)
print(context)
Example Output Structure:
Result 1:
Title: Quantum Computing Progress in 2024
Snippet: Detailed overview of new topological qubits...
URL: https://example.com/article1
Result 2:
...
Feeding Data to LLMs
Once the combined text is retrieved, it can be wrapped in a prompt template. This workflow ensures that the LLM receives grounded, real-time information rather than relying solely on its internal training data.
prompt = f"""
Use the following search results to provide a 3-sentence summary:
{context}
Summary:
"""
# Pass this prompt to your preferred LLM
Manual Data Processing
For users who require more granular control over the data (e.g., filtering by specific domains or custom formatting), the search method provides access to the raw result objects.
search(query)
- Parameters:
query(str). - Returns:
list[dict]. A list of dictionaries containing the raw response items from the search engine. - Role: While used internally by the aggregation workflow, this is public for developers building custom cleaning pipelines.