Skip to main content
`Ctrl`+`K`

# ragoon.web_rag.WebRAG

class ragoon.web_rag.WebRAG(google_api_key: str, google_cx: str, completion_client, user_agent: str | None = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36')

  Bases: `object`

  __init__(google_api_key: str, google_cx: str, completion_client, user_agent: str | None = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36') → None

    WebRAG class.

    This class facilitates retrieval-based querying and completion using various APIs.

    Parameters:

      - google_api_key (str) – The API key for Google services.

      - google_cx (str) – The custom search engine ID for Google Custom Search.

      - completion_client (str) – The API client for the completion service (e.g., OpenAI’s GPT-3).

      - user_agent (str, optional) – The user agent string to be used in web requests. Default is a Chrome user agent.

    web_scraper

      An instance of the WebScraper class for web scraping.

      Type:

        WebScraper

    retriever

      An instance of the Retriever class for data retrieval.

      Type:

        Retriever

    google_search

      An instance of the GoogleSearch class for Google searches.

      Type:

        GoogleSearch

    Examples

    # Initialize RAGoon instance >>> ragoon = RAGoon( >>> google_api_key=”your_google_api_key”, >>> google_cx=”your_google_cx”, >>> completion_client=Groq(api_key=”your_groq_api_key”) >>> )

        >>> # Search and get results
        >>> query = "I want to do a left join in python polars"
        >>> results = ragoon.search(
        >>>    query=query,
        >>>    completion_model="Llama3-70b-8192",
        >>>    max_tokens=512,
        >>>    temperature=1,
        >>> )

  Methods

  `__init__`(google_api_key, google_cx, ...[, ...]) | WebRAG class.
  `search`(query, completion_model[, system_prompt]) | Search for information and perform completion.

  __init__(google_api_key: str, google_cx: str, completion_client, user_agent: str | None = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36') → None

    WebRAG class.

    This class facilitates retrieval-based querying and completion using various APIs.

    Parameters:

      - google_api_key (str) – The API key for Google services.

      - google_cx (str) – The custom search engine ID for Google Custom Search.

      - completion_client (str) – The API client for the completion service (e.g., OpenAI’s GPT-3).

      - user_agent (str, optional) – The user agent string to be used in web requests. Default is a Chrome user agent.

    web_scraper

      An instance of the WebScraper class for web scraping.

      Type:

        WebScraper

    retriever

      An instance of the Retriever class for data retrieval.

      Type:

        Retriever

    google_search

      An instance of the GoogleSearch class for Google searches.

      Type:

        GoogleSearch

    Examples

    # Initialize RAGoon instance >>> ragoon = RAGoon( >>> google_api_key=”your_google_api_key”, >>> google_cx=”your_google_cx”, >>> completion_client=Groq(api_key=”your_groq_api_key”) >>> )

        >>> # Search and get results
        >>> query = "I want to do a left join in python polars"
        >>> results = ragoon.search(
        >>>    query=query,
        >>>    completion_model="Llama3-70b-8192",
        >>>    max_tokens=512,
        >>>    temperature=1,
        >>> )

  search(query: str, completion_model: str, system_prompt: str | None = "\n Given the user's input query, generate a concise and relevant Google search\n query that directly addresses the main intent of the user's question. The search query must\n be specifically tailored to retrieve results that can significantly enhance the context for a\n subsequent dialogue with an LLM. This approach will facilitate few-shot learning by providing\n rich, specific, and contextually relevant information. Please ensure that the response is\n well-formed and format it as a JSON object with a key named 'search_query'. This\n structured approach will help in assimilating the fetched results into an enhanced conversational\n model, contributing to a more nuanced and informed interaction.\n ", *args, **kargs)

    Search for information and perform completion.

    This method searches for information related to the given query and performs completion using the specified model. Additional parameters can be passed to the completion method.

    Parameters:

      - query (str) – The search query.

      - completion_model (str) – The name or identifier of the completion model to be used.

      - *args – Additional positional arguments to be passed to the completion method.

      - **kwargs – Additional keyword arguments to be passed to the completion method.

    Returns:

      completion_data – A dictionary containing the generated completion data.

    Return type:

      dict