0.1.140 • Published 3 months ago

onairos v0.1.140

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 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.140

3 months ago

0.1.139

3 months ago

0.1.136

3 months ago

0.1.138

3 months ago

0.1.137

3 months ago

0.1.135

3 months ago

0.1.132

3 months ago

0.1.131

3 months ago

0.1.134

3 months ago

0.1.133

3 months ago

0.1.130

3 months ago

0.1.118

3 months ago

0.1.117

3 months ago

0.1.119

3 months ago

0.1.114

3 months ago

0.1.113

3 months ago

0.1.116

3 months ago

0.1.115

3 months ago

0.1.110

3 months ago

0.1.112

3 months ago

0.1.111

3 months ago

0.1.129

3 months ago

0.1.128

3 months ago

0.1.125

3 months ago

0.1.124

3 months ago

0.1.127

3 months ago

0.1.126

3 months ago

0.1.121

3 months ago

0.1.120

3 months ago

0.1.123

3 months ago

0.1.122

3 months ago

0.1.99

3 months ago

0.1.107

3 months ago

0.1.106

3 months ago

0.1.109

3 months ago

0.1.108

3 months ago

0.1.103

3 months ago

0.1.102

3 months ago

0.1.105

3 months ago

0.1.104

3 months ago

0.1.101

3 months ago

0.1.100

3 months ago

0.1.96

3 months ago

0.1.97

3 months ago

0.1.98

3 months ago

0.1.90

3 months ago

0.1.91

3 months ago

0.1.92

3 months ago

0.1.93

3 months ago

0.1.94

3 months ago

0.1.95

3 months ago

0.1.85

3 months ago

0.1.86

3 months ago

0.1.87

3 months ago

0.1.88

3 months ago

0.1.89

3 months ago

0.1.81

3 months ago

0.1.82

3 months ago

0.1.83

3 months ago

0.1.84

3 months ago

0.1.80

3 months ago

0.1.77

3 months ago

0.1.78

3 months ago

0.1.79

3 months ago

0.1.74

3 months ago

0.1.75

3 months ago

0.1.76

3 months ago

0.1.71

3 months ago

0.1.72

3 months ago

0.1.73

3 months ago

0.1.52

3 months ago

0.1.53

3 months ago

0.1.54

3 months ago

0.1.55

3 months ago

0.1.56

3 months ago

0.1.57

3 months ago

0.1.58

3 months ago

0.1.59

3 months ago

0.1.50

3 months ago

0.1.51

3 months ago

0.1.49

3 months ago

0.1.41

3 months ago

0.1.42

3 months ago

0.1.43

3 months ago

0.1.44

3 months ago

0.1.45

3 months ago

0.1.46

3 months ago

0.1.47

3 months ago

0.1.48

3 months ago

0.1.40

3 months ago

0.1.70

3 months ago

0.1.63

3 months ago

0.1.64

3 months ago

0.1.65

3 months ago

0.1.66

3 months ago

0.1.67

3 months ago

0.1.68

3 months ago

0.1.69

3 months ago

0.1.60

3 months ago

0.1.61

3 months ago

0.1.62

3 months ago

0.1.38

4 months ago

0.1.39

4 months ago

0.1.37

4 months ago

0.1.30

4 months ago

0.1.31

4 months ago

0.1.32

4 months ago

0.1.33

4 months ago

0.1.34

4 months ago

0.1.35

4 months ago

0.1.36

4 months ago

0.1.27

4 months ago

0.1.28

4 months ago

0.1.29

4 months ago

0.1.24

4 months ago

0.1.25

4 months ago

0.1.26

4 months ago

0.1.20

4 months ago

0.1.21

4 months ago

0.1.23

4 months ago

0.1.18

4 months ago

0.1.19

4 months ago

0.1.14

4 months ago

0.1.15

4 months ago

0.1.16

4 months ago

0.1.17

4 months ago

0.1.13

4 months ago

0.1.11

5 months ago

0.1.12

5 months ago

0.1.10

5 months ago

0.1.9

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.6

5 months ago

0.1.5

5 months ago

0.1.4

5 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.8

6 months ago

0.0.7

6 months ago

0.0.6

6 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago

0.0.0

6 months ago