ChainBrainApp / ChainBrain

No-code, blockchain data analytics platform
https://ethdenver-buidlathon-2023.vercel.app
MIT License
8 stars 0 forks source link

Add support to query Solana data through Bitquery #6

Open marissaposner opened 1 year ago

marissaposner commented 1 year ago
  1. Update the frontend dropdown to include "Solana Blockchain" as an option. When this line is called you can also have "Solana Blockchain" as an option: subgraph = request.get_json().get("subgraph")
  2. In backend/backend/services/openAI/service.py, create a different logic structure for the Solana Blockchain data source. Instead of calling GraphService or parsing the documents in a SimpleDirectoryReader, take in an example document from backend/backend/services/openAI/prompts called SolanaExamples.py that is a list of examples with a structure of [question, query]. Call the LLM with the same flow as exists in backend/backend/services/openAI/service.py:
llm_predictor = LLMPredictor(
            llm=OpenAI(temperature=0, model_name="text-davinci-003")
        )
  1. Instead of calling GraphService, use the logic in backend/backend.services/graph/service.py under GraphService to parse the data. However, instead of querying from a subgraph you will query the Bitquery API.
    Use the following structure to call the GraphQL API for bitquery:
import requests
def run_query(query):  # A simple function to use requests.post to make the API call.
    headers = {'X-API-KEY': 'YOUR API KEY'}
    request = requests.post('https://graphql.bitquery.io/',
                            json={'query': query}, headers=headers)
    if request.status_code == 200:
        return request.json()
    else:
        raise Exception('Query failed and return code is {}.      {}'.format(request.status_code,
                        query))

# The GraphQL query
query = """
query{
  bitcoin{
    blocks{
      count
    }
   }
}
"""
result = run_query(query)  # Execute the query
print 'Result - {}'.format(result)
ellipsis-dev[bot] commented 1 year ago

To have BitBuilder create a Pull Request with the implementation, the user who created the issue (@marissaposner) can comment below with "LGTM".


Implementation Steps

  1. Update Frontend Dropdown
    • Update the frontend dropdown to include 'Solana Blockchain' as an option. This can be done by modifying the frontend code where the dropdown options are defined. Add a new option with the value and display text as 'Solana Blockchain'.
  2. Create SolanaExamples.py
    • Create a new file in the backend/backend/services/openAI/prompts directory called SolanaExamples.py. This file should contain a list of examples with a structure of [question, query]. These examples will be used to train the language model for Solana Blockchain data.
  3. Update OpenAIService
    • In the backend/backend/services/openAI/service.py file, create a different logic structure for the Solana Blockchain data source. Instead of calling GraphService or parsing the documents in a SimpleDirectoryReader, take in an example document from backend/backend/services/openAI/prompts called SolanaExamples.py that is a list of examples with a structure of [question, query]. Call the LLM with the same flow as exists in backend/backend/services/openAI/service.py.
  4. Update GraphService
    • In the backend/backend/services/graph/service.py file, update the logic to parse the data for Solana Blockchain. Instead of querying from a subgraph you will query the Bitquery API. Use the provided structure to call the GraphQL API for bitquery. Replace 'YOUR API KEY' with the actual API key.

Generated with :heart: by www.bitbuilder.ai. Questions? Check out our the documentation.

marissaposner commented 1 year ago

LGTM