ChainBrainApp / ChainBrain

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

Add support for Solana blockchain #10

Open marissaposner opened 1 year ago

marissaposner commented 1 year ago

Create a new flow for pulling data from Solana instead of a subgraph. 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].

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)

Do not call the SubgraphService function and instead call the API above.

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. Create SolanaExamples.py
    • Create a new file in the directory backend/backend/services/openAI/prompts called SolanaExamples.py. This file should contain a list of examples with a structure of [question, query].
  2. Modify OpenAIService in service.py
    • In the OpenAIService class of the backend/backend/services/openAI/service.py file, create a new method that will handle Solana blockchain data source. This method should use the Bitquery API to fetch data instead of the GraphService. Use the provided Python code to call the Bitquery API. Make sure to replace 'YOUR API KEY' with the actual API key. The method should take in an example document from SolanaExamples.py and parse the data accordingly.

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

marissaposner commented 1 year ago

LGTM