Quick Start
Quick Start
Get up and running with rtrapy in under five minutes. This library allows you to perform Google Custom Searches and use the results as context for generating detailed, AI-driven responses via Hugging Face models.
1. Installation
Install the package directly from PyPI using pip:
pip install rtrapy
2. Prerequisites
To use rtrapy, you will need:
- Google Custom Search API Key: Obtainable from the Google Cloud Console.
- Search Engine ID (CX): Created via the Google Programmable Search Engine dashboard.
3. Basic Usage
The following example demonstrates how to initialize the connector and generate a search-augmented response.
from rtrapy.rtra_connector import RTRAConnector
# Initialize the connector with your Google credentials
api_key = "YOUR_GOOGLE_API_KEY"
engine_id = "YOUR_CUSTOM_SEARCH_ENGINE_ID"
connector = RTRAConnector(api_key=api_key, engine_id=engine_id)
# Generate a detailed response based on live search data
query = "What are the latest developments in quantum computing?"
response = connector.generate_detailed_response(query)
print(response)
Core Methods Reference
RTRAConnector(api_key, engine_id)
Initializes the connection to the Google Search API.
- api_key (str): Your Google Custom Search API Key.
- engine_id (str): Your Google Search Engine ID (CX).
search(query)
Performs a raw search and returns the metadata from Google.
- Input:
query(str) - The search term. - Output:
list- A list of result items (dictionaries) containing snippets, links, and titles.
generate_detailed_response(query)
The primary method for RAG (Retrieval-Augmented Generation). It fetches the top 5 search snippets and sends them to a Mistral-7B model to generate a synthesized answer.
- Input:
query(str) - The question or topic. - Output:
str- The AI-generated text based on the search context.
combine_search_results(query)
A utility method used internally to prepare context, but accessible if you only need the concatenated snippets.
- Input:
query(str) - Output:
str- A single string containing the top 5 search snippets separated by newlines.