Skip to content

Instantly share code, notes, and snippets.

@YazzyYaz
Created March 16, 2023 19:07
Show Gist options
  • Save YazzyYaz/035a08118ce221b1f7e3045ffb707e3d to your computer and use it in GitHub Desktop.
Save YazzyYaz/035a08118ce221b1f7e3045ffb707e3d to your computer and use it in GitHub Desktop.
# Note: you need to be using OpenAI Python v0.27.0 for the code below to work
import openai
import os
import requests
import base64
from pprint import pprint
import json
# Load your API key from an environment variable or secret management service
openai.api_key = ''
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role":"system", "content":"Explain Devrel to me"}
]
)
#gpt_output = response["choices"][0]["message"]["content"]
gpt_output = json.dumps(response)
def get_data(namespace_id:str, height:int):
r = requests.get(f'http://localhost:26659/namespaced_data/{namespace_id}/height/{height}')
pprint(r)
pprint(dict(r.json()))
data = r.json()['data'][0]
print(base64.b64decode(data).decode('utf-8'))
return data
#n_id = '756f60cbe7bf5401'
n_id = '0000000cOfeebabe'
def post_data(namespace_id, data, gas_limit=6000):
data = data.encode('utf-8')
d = data.hex()
r = requests.post(f'http://localhost:26659/submit_pfb', json={"namespace_id":namespace_id,"data":d,"gas_limit":gas_limit, "fee":2000})
pprint(r)
pprint(r.json())
print(get_data(n_id,r.json()['height']))
pprint(gpt_output)
post_data(n_id, gpt_output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment