Merge pull request #7 from allora-network/major-upgrade

Major upgrade
This commit is contained in:
Cristian Conache 2024-06-19 19:39:06 +03:00 committed by GitHub
commit 27d559e8fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 16 deletions

10
app.py
View File

@ -34,17 +34,13 @@ def generate_inference(token):
"""Generate inference for given token."""
if not token or token != "ETH":
error_msg = "Token is required" if not token else "Token not supported"
return Response(
json.dumps({"error": error_msg}), status=400, mimetype="application/json"
)
return Response(json.dumps({"error": error_msg}), status=400, mimetype='application/json')
try:
inference = get_eth_inference()
return jsonify({"value": str(inference)})
return Response(str(inference), status=200)
except Exception as e:
return Response(
json.dumps({"error": str(e)}), status=500, mimetype="application/json"
)
return Response(json.dumps({"error": str(e)}), status=500, mimetype='application/json')
@app.route("/update")

22
main.py
View File

@ -9,19 +9,23 @@ INFERENCE_ADDRESS = os.environ["INFERENCE_API_ADDRESS"]
def process(token_name):
response = requests.get(f"{INFERENCE_ADDRESS}/inference/{token_name}")
content = response.text
print(content)
return content
if __name__ == "__main__":
# Your code logic with the parsed argument goes here
try:
if len(sys.argv) >= 3:
# Not using to discriminate by topicId for simplicity.
# topic_id = sys.argv[1]
token_name = sys.argv[2]
if len(sys.argv) < 5:
value = json.dumps({"error": f"Not enough arguments provided: {len(sys.argv)}, expected 4 arguments: topic_id, blockHeight, blockHeightEval, default_arg"})
else:
token_name = "ETH"
process(token_name=token_name)
topic_id = sys.argv[1]
blockHeight = sys.argv[2]
blockHeightEval = sys.argv[3]
default_arg = sys.argv[4]
response_inference = process(token_name=default_arg)
response_dict = {"infererValue": response_inference}
value = json.dumps(response_dict)
except Exception as e:
response = json.dumps({"error": {str(e)}})
print(response)
value = json.dumps({"error": {str(e)}})
print(value)