Skip to main content

llama-index tools playgrounds integration

Project description

Playgrounds Tool Specs

playgrounds_subgraph_connector

pip install llama-index-tools-playgrounds

Playgrounds API is a service provided by Playgrounds Analytics to streamline interfacing with decentralized subgraphs (indexed blockchain datasets).

The PlaygroundsSubgraphConnector is a tool designed for LLM agents to seamlessly interface with and query subgraphs on The Graph's decentralized network via Playgrounds API.

This tool is specifically designed to be used alongside Llama index or langchain

Advantages of this tool:

  • Easy access to Decentralized Subgraphs (Datasets): No need for wallet or GRT management.
  • LLM x Blockchain data: Develop Ai applications that leverage blockchain data seamlessly.

Basic Usage:

To utilize the tool, simply initialize it with the appropriate identifier (Subgraph ID or Deployment ID) and api_key. Optionally, specify if you're using a deployment ID.

import openai
from llama_index.agent.openai import OpenAIAgent
from llama_index.tools.playgrounds import PlaygroundsSubgraphConnectorToolSpec


def simple_test():
    """
    Run a simple test querying the financialsDailySnapshots from Uniswap V3 subgraph using OpenAIAgent and Playgrounds API.
    """
    # Set the OpenAI API key
    openai.api_key = "YOUR_OPENAI_API_KEY"

    # Initialize the tool specification with the subgraph's identifier and the Playgrounds API key
    connector_spec = PlaygroundsSubgraphConnectorToolSpec(
        identifier="YOUR_SUBGRAPH_OR_DEPLOYMENT_IDENTIFIER",
        api_key="YOUR_PLAYGROUNDS_API_KEY",
        use_deployment_id=False,  # Set to True if using Deployment ID
    )

    # Setup agent with the tool
    agent = OpenAIAgent.from_tools(connector_spec.to_tool_list())

    # Make a query using the agent
    response = agent.chat(
        "query the financialsDailySnapshots for id, timestamp, totalValueLockedUSD, and dailyVolumeUSD. only give me the first 2 rows"
    )
    print(response)


if __name__ == "__main__":
    simple_test()

Visit here for more in-depth Examples.

This loader is designed to be used as a way to load data into LlamaIndex and/or subsequently used as a Tool in a LangChain Agent.

playgrounds_subgraph_inspector

Playgrounds API is a service provided by Playgrounds Analytics to facilitate interactions with decentralized subgraphs (indexed blockchain datasets).

The PlaygroundsSubgraphInspectorToolSpec is a tool designed for LLM agents to introspect and understand the schema of subgraphs on The Graph's decentralized network via the Playgrounds API.

This tool is specifically designed to be used alongside Llama index or langchain.

  • To learn more about Playgrounds API, please visit our website: Playgrounds Network
  • Obtain your Playgrounds API Key and get started for free here.
  • Discover any Subgraph (dataset) you need here.

Advantages of this tool:

  • Introspection of Decentralized Subgraphs (Datasets): Understand the schema of any subgraph without hassle.
  • LLM x Blockchain Data: Develop AI applications that leverage introspective insights from blockchain data.

Basic Usage:

To utilize the tool, initialize it with the appropriate identifier (Subgraph ID or Deployment ID), api_key, and specify if you're using a deployment ID.

import openai
from llama_index.agent.openai import OpenAIAgent
from llama_index.tools.playgrounds import PlaygroundsSubgraphInspectorToolSpec


def inspect_subgraph(
    openai_api_key: str,
    playgrounds_api_key: str,
    identifier: str,
    use_deployment_id: bool,
    user_prompt: str,
):
    """
    Introspect a subgraph using OpenAIAgent and Playgrounds API with the provided parameters.

    Args:
        openai_api_key (str): API key for OpenAI.
        playgrounds_api_key (str): API key for Playgrounds.
        identifier (str): Identifier for the subgraph or deployment.
        use_deployment_id (bool): If True, uses deployment ID in the URL.
        user_prompt (str): User's question or prompt for the agent.

    Returns:
        str: Agent's response.
    """
    # Set the OpenAI API key
    openai.api_key = openai_api_key

    # Initialize the inspector with the provided parameters
    inspector_spec = PlaygroundsSubgraphInspectorToolSpec(
        identifier=identifier,
        api_key=playgrounds_api_key,
        use_deployment_id=use_deployment_id,
    )

    # Integrate the tool with the agent
    agent = OpenAIAgent.from_tools(inspector_spec.to_tool_list())

    # Send the user prompt to the agent
    response = agent.chat(user_prompt)
    return response


if __name__ == "__main__":
    query = inspect_subgraph(
        openai_api_key="YOUR_OPENAI_API_KEY",
        playgrounds_api_key="YOUR_PLAYGROUNDS_API_KEY",
        identifier="YOUR_SUBGRAPH_OR_DEPLOYMENT_IDENTIFIER",
        use_deployment_id=False,
        user_prompt="Which entities will help me understand the usage of Uniswap V3?",
    )

Visit here for more in-depth Examples.

This inspector is designed to be used as a way to understand the schema of subgraphs and subgraph data being loaded into LlamaIndex.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_tools_playgrounds-0.2.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file llama_index_tools_playgrounds-0.2.0.tar.gz.

File metadata

File hashes

Hashes for llama_index_tools_playgrounds-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e6cdc2ba3d9082c650c200355258e844ca1efde898ecc0843b07d346a1900a06
MD5 eda9ddf9326ff1fdad7e57ece4a4e698
BLAKE2b-256 361fef25a9dcad381f3f43566df3504605dac02301533f4320ec82f33d9d6b2c

See more details on using hashes here.

File details

Details for the file llama_index_tools_playgrounds-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_tools_playgrounds-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da0b0e250584e7568dcbd47427cdace03cb416aaf3686856a800d6875aa32fc2
MD5 96ace92a7b091e0fd19321212f6d10c1
BLAKE2b-256 6ff6cbe502c154e684d7eb3ad5ccb50bdfc124658a9b0f90af9ab6e3a0c1962e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page