0.1.399 • Published 9 months ago

onairos v0.1.399

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

Onairos Developer Documentation v0.0.0

1. Create a Developer Account

Create a Developer account to access Onairos services. Register your domain to ensure secure API access.

https://Onairos.uk/dev-board

2. Download the Onairos NPM package

npm install onairos

Import the package as a default import

import Onairos from 'onairos';

3. Setup the Onairos Connection Object

First create the Request Object which Users will Authorize (or not) in the extension popup

"RequestObject":{ 
    "Small": {
      "type":"Personality",
      "descriptions":"Insight into your Interests",
      "reward":"10% Discount"
    },
    "Medium":{
      "type":"Personality",
      "descriptions":"Insight into your Interests",
      "reward":"2 USDC"
    },
    "Large":{
      "type":"Personality",
      "descriptions":"Insight into your Interests",
      "reward":"2 USDC"
    }
  }

RequestObject.size key:

  • Small - Upto 16 inference items
  • Medium - Upto 32 inference items
  • Large - Upto 64 inference items

Individual Request Information:

  • type: Only the Personality key is valid at this time (represents the users Onairos Personality)
  • description: Description to display to users about your request
  • reward: Reward Given to User for granting Data Request

Then instantiate the Onairos object from the Onairos package - passing in your Request Object and other meta info

<Onairos requestData={requestData} webpageName={webpageName} proofMode={proofMode} />

Onairos Object fields:

  • requestData - Request Object - Json
  • webpageName - App Display Name - String
  • proofMode - Wish to recieve ZK proof after recieving Data , default FALSE - boolean

That is all for the initial setup

4. Recieving the Inference API

Once the user has clicked to Connect their Onairos account and authroized their data, you will recieve the Inference API via window.sendMessage with the following event types:

event.data.source === 'content-script'
&&
event.data.type === 'API_URL_RESPONSE'
&&
event.data.unique ==='Onairos-Response'

You will also be given an ACCESS TOKEN which you must use in any API requests from that specific client.

This is a short lived token, for usage on your developer registered domain only, and lasts for 1 hour from issue.

For example:

export default async function UseAPIURL(event){
    if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
      const { APIurl, accessToken } = event.data;
      //Fetch Onairos Data from Returned API url
  }
}
useEffect(() => {
  window.addEventListener('message', UseAPIURL);
  return () => {
    window.removeEventListener('message', UseAPIURL);
  };
}, []);

Using the Inference API

The Inference API provides a machine learning model that can generate predictions based on the provided data. This documentation will guide you on how to properly format your input for the API and interpret the results received from the API.

5. Input Format

Send a POST request to the API endpoint with a JSON payload containing a set of entries for prediction. Each entry should include the following information:

  • text: The text input for the inference result (String) - required
  • category: The category to which the content belongs (String) - required
  • img_url: The URL of an image associated with the content (String) - optional

Example JSON body for the POST request:

  "Input": {
    "input1": {
      "text": "Example text input 1",
      "category": "Example Category 1",
      "img_url": "http://example.com/image1.jpg"
    },
    "input2": {
      "text": "Example text input 2",
      "category": "Example Category 2",
      "img_url": "http://example.com/image2.jpg"
    },
    "input3": {
      "text": "Example text input 3",
      "category": "Example Category 3",
      "img_url": "http://example.com/image3.jpg"
    },
  }
    // Additional entries can be added here
  

You can then call the Inference API with the Inference object created above.

Remember to include the access token in the Authorization header of your API request.

export default async function UseAPIURL(event){
    if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
      const { apiUrl, accessToken } = event.data;
      await fetch(apiUrl, {
          method: 'POST',
          headers: {
              'Content-Type': 'application/json',
              'Authorization': `Bearer ${accessToken}` // Include the access token in the Authorization header
          },
          body: JSON.stringify(InputData),
      }).then(async (data)=>{
            // process Onairos Data
      })
      .catch(error => console.error(error));
      
    }}
  

6. Output Format

The API responds with a JSON object containing an output field. This field is an array of arrays, where each sub-array contains a single element representing the prediction score from the model. This score is a floating-point number reflecting the model's confidence for the input provided.

Example of the output format:

{
  "output": [
    [[0.9998]],
    [[0.9999]],
    [[0.9922]],
    [[0.0013]],
    // Additional scores for more entries
  ]
}

Each score is deeply nested within two arrays to maintain compatibility with batch processing systems that may require this format.

Errors and Debugging

All Errors and Debugging from the Inference API will be of the form

    res.status(statusCode).send({ error: message }); 

Statuses of 200 are valid, and all others indicate potential issues

Integrating the onairos Package into Your Application

When integrating the onairos package into your application, please ensure the following steps are taken to correctly handle dynamically loaded modules:

Webpack Configuration:

Your application's Webpack configuration needs to be set up to handle dynamic imports. Specifically, the output.publicPath in your webpack.config.js should be configured to reflect the URL path from which your application will serve its assets. If your application is served from a subdirectory, make sure to include the subdirectory path in the publicPath.

Serving Chunks:

Ensure that your server is configured to serve the necessary chunk files located within the node_modules/onairos/dist directory. These files are essential for the dynamic modules to load correctly at runtime.

Include Chunks in Your Deployment: When deploying your application, include the dist directory of the onairos package in your deployment artifacts. This directory contains the chunk files generated by Webpack and is necessary for the proper functioning of the package.

Version Management:

The onairos package uses semantic versioning. Please note that major version changes may introduce breaking changes and require additional steps to integrate. Always refer to the release notes for guidance on upgrading.

Local Testing:

Prior to deployment, you can link the onairos package locally to ensure that dynamic imports work as expected. Use the npm link command for this purpose and verify that the application behaves correctly and loads all necessary modules.

If you encounter any issues while integrating the onairos package, please refer to the troubleshooting guide provided in our documentation, or reach out to our support team for assistance.

Interpretation of Output

  • A score close to 1 indicates a high confidence level in the prediction.
  • A score close to 0 indicates a low confidence level in the prediction.
  • The sequence of scores corresponds to the order of the input entries.

Example Usage in a React Application

The following React component demonstrates how to send a prediction request to the API and display the results:

import React, { useState } from 'react';

function App() {

    async function UseAPIURL(event){
     if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
      const { apiUrl, accessToken } = event.data;
       await fetch(apiUrl, {
           method: 'POST',
           headers: {
               'Content-Type': 'application/json',
               'Authorization': `Bearer ${accessToken}` // Include the access token in the Authorization header
           },
           body: JSON.stringify(InputData),
       }).then(async (data)=>{
             // process Onairos Data
       })
       .catch(error => console.error(error));
      
    }}

  const requestData = { 
    Small: {
      type:"Personality",
      descriptions:"Insight into your Interests",
      reward:"10% Discount"
    },
    Medium:{
      type:"Personality",
      descriptions:"Insight into your Interests",
      reward:"2 USDC"
    },
    Large:{
      type:"Personality",
      descriptions:"Insight into your Interests",
      reward:"2 USDC"
    },
  };
  useEffect(() => {
    window.addEventListener('message', UseAPIURL);
    return () => {
      window.removeEventListener('message', UseAPIURL);
    };
    }, []);

  const onairosID = 'test';
  return (
      <Onairos requestData={requestData} webpageName={webpageName} proofMode={proofMode} />

  );
}
export default InferenceComponent;
0.1.239

11 months ago

0.1.359

11 months ago

0.1.238

11 months ago

0.1.235

11 months ago

0.1.355

11 months ago

0.1.234

11 months ago

0.1.237

11 months ago

0.1.357

11 months ago

0.1.236

11 months ago

0.1.352

11 months ago

0.1.231

11 months ago

0.1.351

11 months ago

0.1.230

11 months ago

0.1.354

11 months ago

0.1.233

11 months ago

0.1.353

11 months ago

0.1.232

11 months ago

0.1.350

11 months ago

0.1.249

11 months ago

0.1.367

10 months ago

0.1.246

11 months ago

0.1.366

10 months ago

0.1.369

10 months ago

0.1.248

11 months ago

0.1.368

10 months ago

0.1.247

11 months ago

0.1.363

10 months ago

0.1.242

11 months ago

0.1.241

11 months ago

0.1.365

10 months ago

0.1.244

11 months ago

0.1.364

10 months ago

0.1.243

11 months ago

0.1.361

10 months ago

0.1.240

11 months ago

0.1.360

11 months ago

0.1.378

10 months ago

0.1.377

10 months ago

0.1.256

11 months ago

0.1.259

11 months ago

0.1.379

10 months ago

0.1.258

11 months ago

0.1.374

10 months ago

0.1.253

11 months ago

0.1.373

10 months ago

0.1.252

11 months ago

0.1.376

10 months ago

0.1.255

11 months ago

0.1.375

10 months ago

0.1.254

11 months ago

0.1.370

10 months ago

0.1.372

10 months ago

0.1.251

11 months ago

0.1.371

10 months ago

0.1.250

11 months ago

0.1.389

10 months ago

0.1.268

11 months ago

0.1.267

11 months ago

0.1.385

10 months ago

0.1.264

11 months ago

0.1.384

10 months ago

0.1.263

11 months ago

0.1.387

10 months ago

0.1.266

11 months ago

0.1.386

10 months ago

0.1.265

11 months ago

0.1.381

10 months ago

0.1.260

11 months ago

0.1.380

10 months ago

0.1.383

10 months ago

0.1.262

11 months ago

0.1.382

10 months ago

0.1.261

11 months ago

0.1.309

11 months ago

0.1.308

11 months ago

0.1.316

11 months ago

0.1.315

11 months ago

0.1.318

11 months ago

0.1.317

11 months ago

0.1.312

11 months ago

0.1.311

11 months ago

0.1.314

11 months ago

0.1.313

11 months ago

0.1.310

11 months ago

0.1.319

11 months ago

0.1.327

11 months ago

0.1.206

11 months ago

0.1.326

11 months ago

0.1.205

11 months ago

0.1.329

11 months ago

0.1.208

11 months ago

0.1.328

11 months ago

0.1.207

11 months ago

0.1.323

11 months ago

0.1.202

11 months ago

0.1.322

11 months ago

0.1.201

11 months ago

0.1.325

11 months ago

0.1.204

11 months ago

0.1.324

11 months ago

0.1.203

11 months ago

0.1.321

11 months ago

0.1.200

11 months ago

0.1.320

11 months ago

0.1.209

11 months ago

0.1.338

11 months ago

0.1.217

11 months ago

0.1.337

11 months ago

0.1.216

11 months ago

0.1.219

11 months ago

0.1.339

11 months ago

0.1.218

11 months ago

0.1.334

11 months ago

0.1.213

11 months ago

0.1.333

11 months ago

0.1.212

11 months ago

0.1.336

11 months ago

0.1.215

11 months ago

0.1.335

11 months ago

0.1.214

11 months ago

0.1.330

11 months ago

0.1.332

11 months ago

0.1.211

11 months ago

0.1.210

11 months ago

0.1.349

11 months ago

0.1.228

11 months ago

0.1.348

11 months ago

0.1.227

11 months ago

0.1.229

11 months ago

0.1.345

11 months ago

0.1.224

11 months ago

0.1.344

11 months ago

0.1.223

11 months ago

0.1.347

11 months ago

0.1.226

11 months ago

0.1.346

11 months ago

0.1.225

11 months ago

0.1.341

11 months ago

0.1.220

11 months ago

0.1.340

11 months ago

0.1.222

11 months ago

0.1.342

11 months ago

0.1.221

11 months ago

0.1.305

11 months ago

0.1.304

11 months ago

0.1.307

11 months ago

0.1.306

11 months ago

0.1.301

11 months ago

0.1.303

11 months ago

0.1.302

11 months ago

0.1.190

12 months ago

0.1.192

11 months ago

0.1.191

11 months ago

0.1.198

11 months ago

0.1.197

11 months ago

0.1.199

11 months ago

0.1.194

11 months ago

0.1.193

11 months ago

0.1.196

11 months ago

0.1.195

11 months ago

0.1.390

10 months ago

0.1.279

11 months ago

0.1.399

9 months ago

0.1.278

11 months ago

0.1.396

10 months ago

0.1.275

11 months ago

0.1.395

10 months ago

0.1.274

11 months ago

0.1.398

10 months ago

0.1.277

11 months ago

0.1.397

10 months ago

0.1.276

11 months ago

0.1.392

10 months ago

0.1.271

11 months ago

0.1.391

10 months ago

0.1.270

11 months ago

0.1.394

10 months ago

0.1.273

11 months ago

0.1.393

10 months ago

0.1.272

11 months ago

0.1.280

11 months ago

0.1.289

11 months ago

0.1.286

11 months ago

0.1.285

11 months ago

0.1.288

11 months ago

0.1.287

11 months ago

0.1.282

11 months ago

0.1.281

11 months ago

0.1.284

11 months ago

0.1.283

11 months ago

0.1.291

11 months ago

0.1.290

11 months ago

0.1.297

11 months ago

0.1.296

11 months ago

0.1.299

11 months ago

0.1.298

11 months ago

0.1.293

11 months ago

0.1.292

11 months ago

0.1.295

11 months ago

0.1.294

11 months ago

0.1.187

1 year ago

0.1.186

1 year ago

0.1.189

1 year ago

0.1.188

1 year ago

0.1.185

1 year ago

0.1.184

1 year ago

0.1.147

1 year ago

0.1.146

1 year ago

0.1.149

1 year ago

0.1.148

1 year ago

0.1.143

1 year ago

0.1.142

1 year ago

0.1.145

1 year ago

0.1.144

1 year ago

0.1.141

1 year ago

0.1.158

1 year ago

0.1.157

1 year ago

0.1.159

1 year ago

0.1.154

1 year ago

0.1.153

1 year ago

0.1.156

1 year ago

0.1.155

1 year ago

0.1.150

1 year ago

0.1.152

1 year ago

0.1.151

1 year ago

0.1.169

1 year ago

0.1.168

1 year ago

0.1.165

1 year ago

0.1.167

1 year ago

0.1.166

1 year ago

0.1.161

1 year ago

0.1.160

1 year ago

0.1.163

1 year ago

0.1.162

1 year ago

0.1.170

1 year ago

0.1.179

1 year ago

0.1.175

1 year ago

0.1.178

1 year ago

0.1.177

1 year ago

0.1.172

1 year ago

0.1.171

1 year ago

0.1.174

1 year ago

0.1.173

1 year ago

0.1.181

1 year ago

0.1.180

1 year ago

0.1.183

1 year ago

0.1.182

1 year ago

0.1.140

2 years ago

0.1.139

2 years ago

0.1.136

2 years ago

0.1.138

2 years ago

0.1.137

2 years ago

0.1.135

2 years ago

0.1.132

2 years ago

0.1.131

2 years ago

0.1.134

2 years ago

0.1.133

2 years ago

0.1.130

2 years ago

0.1.118

2 years ago

0.1.117

2 years ago

0.1.119

2 years ago

0.1.114

2 years ago

0.1.113

2 years ago

0.1.116

2 years ago

0.1.115

2 years ago

0.1.110

2 years ago

0.1.112

2 years ago

0.1.111

2 years ago

0.1.129

2 years ago

0.1.128

2 years ago

0.1.125

2 years ago

0.1.124

2 years ago

0.1.127

2 years ago

0.1.126

2 years ago

0.1.121

2 years ago

0.1.120

2 years ago

0.1.123

2 years ago

0.1.122

2 years ago

0.1.99

2 years ago

0.1.107

2 years ago

0.1.106

2 years ago

0.1.109

2 years ago

0.1.108

2 years ago

0.1.103

2 years ago

0.1.102

2 years ago

0.1.105

2 years ago

0.1.104

2 years ago

0.1.101

2 years ago

0.1.100

2 years ago

0.1.96

2 years ago

0.1.97

2 years ago

0.1.98

2 years ago

0.1.90

2 years ago

0.1.91

2 years ago

0.1.92

2 years ago

0.1.93

2 years ago

0.1.94

2 years ago

0.1.95

2 years ago

0.1.85

2 years ago

0.1.86

2 years ago

0.1.87

2 years ago

0.1.88

2 years ago

0.1.89

2 years ago

0.1.81

2 years ago

0.1.82

2 years ago

0.1.83

2 years ago

0.1.84

2 years ago

0.1.80

2 years ago

0.1.77

2 years ago

0.1.78

2 years ago

0.1.79

2 years ago

0.1.74

2 years ago

0.1.75

2 years ago

0.1.76

2 years ago

0.1.71

2 years ago

0.1.72

2 years ago

0.1.73

2 years ago

0.1.52

2 years ago

0.1.53

2 years ago

0.1.54

2 years ago

0.1.55

2 years ago

0.1.56

2 years ago

0.1.57

2 years ago

0.1.58

2 years ago

0.1.59

2 years ago

0.1.50

2 years ago

0.1.51

2 years ago

0.1.49

2 years ago

0.1.41

2 years ago

0.1.42

2 years ago

0.1.43

2 years ago

0.1.44

2 years ago

0.1.45

2 years ago

0.1.46

2 years ago

0.1.47

2 years ago

0.1.48

2 years ago

0.1.40

2 years ago

0.1.70

2 years ago

0.1.63

2 years ago

0.1.64

2 years ago

0.1.65

2 years ago

0.1.66

2 years ago

0.1.67

2 years ago

0.1.68

2 years ago

0.1.69

2 years ago

0.1.60

2 years ago

0.1.61

2 years ago

0.1.62

2 years ago

0.1.38

2 years ago

0.1.39

2 years ago

0.1.37

2 years ago

0.1.30

2 years ago

0.1.31

2 years ago

0.1.32

2 years ago

0.1.33

2 years ago

0.1.34

2 years ago

0.1.35

2 years ago

0.1.36

2 years ago

0.1.27

2 years ago

0.1.28

2 years ago

0.1.29

2 years ago

0.1.24

2 years ago

0.1.25

2 years ago

0.1.26

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.23

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.13

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago