Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment #13

Merged
merged 6 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions adapter/worker_reputer_rest_api_l1_loss/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package worker_reputer_rest_api_l1_loss
import (
"allora_offchain_node/lib"
"fmt"
"io"
// "io"
"math"
"net/http"
// "net/http"
"strconv"
"math/rand"
"time"

"github.com/rs/zerolog/log"
)
Expand All @@ -21,26 +23,30 @@ func (a *AlloraAdapter) Name() string {

func requestLocalEndpoint(url string) (string, error) {
// make request to url
resp, err := http.Get(url)
if err != nil {
return "", fmt.Errorf("failed to make request to %s: %w", url, err)
}
defer resp.Body.Close()

// Check if the response status is OK
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("received non-OK HTTP status %d", resp.StatusCode)
}

// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("failed to read response body: %w", err)
}

log.Debug().Bytes("body", body).Msg("Inference")
// resp, err := http.Get(url)
// if err != nil {
// return "", fmt.Errorf("failed to make request to %s: %w", url, err)
// }
// defer resp.Body.Close()

// // Check if the response status is OK
// if resp.StatusCode != http.StatusOK {
// return "", fmt.Errorf("received non-OK HTTP status %d", resp.StatusCode)
// }

// // Read the response body
// body, err := io.ReadAll(resp.Body)
// if err != nil {
// return "", fmt.Errorf("failed to read response body: %w", err)
// }

// log.Debug().Bytes("body", body).Msg("Inference")
// convert bytes to string
return string(body), nil
// return string(body), nil
rand.Seed(time.Now().UnixNano())
f := rand.Float64()
s := fmt.Sprintf("%f", f)
return string(s), nil
}

func (a *AlloraAdapter) CalcInference(node lib.WorkerConfig, blockHeight int64) (string, error) {
Expand Down
25 changes: 25 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ var UserConfig = lib.UserConfig{
"forecastEndpoint": os.Getenv("FORECAST_URL"),
},
},
{
TopicId: 1,
InferenceEntrypoint: apiAdapter.NewAlloraAdapter(),
ForecastEntrypoint: nil,
LoopSeconds: 5,
Parameters: map[string]string{
//// These communicate with local Python Flask server
"inferenceEndpoint": os.Getenv("INFERENCE_URL"),
"token": "ETH",
"forecastEndpoint": os.Getenv("FORECAST_URL"),
},
},
},
Reputer: []lib.ReputerConfig{
{
Expand All @@ -52,6 +64,19 @@ var UserConfig = lib.UserConfig{
// "apiKey": os.Getenv("CG_API_KEY"),
},
},
{
TopicId: 1,
ReputerEntrypoint: apiAdapter.NewAlloraAdapter(),
LoopSeconds: 30,
MinStake: 100000,
Parameters: map[string]string{
"truthEndpoint": os.Getenv("TRUTH_URL"),
"token": "ethereum",
//// Could put this in Python Flask server as well
// "cgSimpleEndpoint": "https://api.coingecko.com/api/v3/simple/price?vs_currencies=usd&ids=",
// "apiKey": os.Getenv("CG_API_KEY"),
},
},
},
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- ALLORA_NODE_RPC=https://allora-rpc.testnet-1.testnet.allora.network
- INFERENCE_URL=http://inference:8000/inference
- FORECAST_URL=http://inference:8000/forecast
- TRUTH_URL=http://localhost:8000/truth # this is external independent service where you pull the source truth from
- TRUTH_URL=http://inference:8000/truth # this is external independent service where you pull the source truth from
volumes:
- ./data:/data
depends_on:
Expand Down
5 changes: 5 additions & 0 deletions inference/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ def get_forecast():
]
return jsonify([nv.__dict__ for nv in node_values])

@app.route('/truth', methods=['GET'])
def get_truth():
random_float = str(random.uniform(0.0, 100.0))
return random_float

if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=8000)
Loading