onairos 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,227 @@
1
+
2
+ ## Onairos Developer Documentation v0.0.0
3
+
4
+ ### 1. Create a Developer Account
5
+
6
+ Create a Developer account and retrieve your Onairos developer ID and access token
7
+
8
+ https://Onairos.uk/dev-board
9
+
10
+ ### 2. Download the Onairos NPM package
11
+
12
+ ```bash
13
+ npm install onairos
14
+ ```
15
+
16
+ ### 3. Setup the Onairos Connection Object
17
+
18
+ First create the Request Object which Users will Authorize (or not) in the extension popup
19
+ ```json
20
+ "RequestObject":{
21
+ "Small": {
22
+ "type":"Personality",
23
+ "descriptions":"Insight into your Interests",
24
+ "reward":"10% Discount"
25
+ },
26
+ "Medium":{
27
+ "type":"Personality",
28
+ "descriptions":"Insight into your Interests",
29
+ "reward":"2 USDC"
30
+ },
31
+ "Large":{
32
+ "type":"Personality",
33
+ "descriptions":"Insight into your Interests",
34
+ "reward":"2 USDC"
35
+ }
36
+ }
37
+
38
+ ```
39
+ RequestObject.size key:
40
+ Small - Upto 16 inference items
41
+ Medium - Upto 32 inference items
42
+ Large - Upto 64 inference items
43
+
44
+ type: Only the Personality key is valid at this time (represents the users Onairos Personality)
45
+ description: Description to display to users about your request
46
+ reward: Reward Given to User for granting Data Request
47
+
48
+ Then instantiate the Onairos object from the Onairos package - passing in your Onairos Developer ID and your Request Object
49
+ ```jsx
50
+ <Onairos requestData={requestData} onairosID={onairosID} access_token={access_token} webpageName={webpageName} proofMode={proofMode} />
51
+ ```
52
+
53
+ Onairos Object fields:
54
+ requestData - Request Object - Json
55
+ onairosID - App Assigned Onairos ID - String
56
+ access_token - App Assigned Access Token - String
57
+ webpageName - App Display Name - String
58
+ proofMode - Wish to recieve ZK proof after recieving Data , default FALSE - boolean
59
+
60
+ That is all for the initial setup
61
+
62
+ ### 4. Recieving the Inference API
63
+
64
+ 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:
65
+ ```jsx
66
+ event.data.source === 'content-script'
67
+ &&
68
+ event.data.type === 'API_URL_RESPONSE'
69
+ ```
70
+
71
+ For example:
72
+
73
+ ``` jsx
74
+ export default async function UseAPIURL(event){
75
+ if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
76
+ //Fetch Onairos Data from Returned API url
77
+ }
78
+ }
79
+ useEffect(() => {
80
+ window.addEventListener('message', UseAPIURL);
81
+ return () => {
82
+ window.removeEventListener('message', UseAPIURL);
83
+ };
84
+ }, []);
85
+ ```
86
+
87
+ ## Using the Inference API
88
+
89
+ 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.
90
+
91
+ ### 5. Input Format
92
+
93
+ 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:
94
+
95
+ - `text`: The text input for the inference result (String) - required
96
+ - `category`: The category to which the content belongs (String) - required
97
+ - `img_url`: The URL of an image associated with the content (String) - optional
98
+
99
+ Example JSON body for the POST request:
100
+
101
+ ```json
102
+
103
+ "Input": {
104
+ "input1": {
105
+ "text": "Example text input 1",
106
+ "category": "Example Category 1",
107
+ "img_url": "http://example.com/image1.jpg"
108
+ },
109
+ "input2": {
110
+ "text": "Example text input 2",
111
+ "category": "Example Category 2",
112
+ "img_url": "http://example.com/image2.jpg"
113
+ },
114
+ "input3": {
115
+ "text": "Example text input 3",
116
+ "category": "Example Category 3",
117
+ "img_url": "http://example.com/image3.jpg"
118
+ }
119
+ }
120
+ // Additional entries can be added here
121
+
122
+
123
+ ```
124
+
125
+ You can then call the Inference API with the Inference object created above
126
+
127
+ ```jsx
128
+ export default async function UseAPIURL(event){
129
+ if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
130
+ const apiUrl = event.data.APIurl;
131
+ await fetch(apiUrl, {
132
+ method: 'POST',
133
+ headers: {
134
+ 'Content-Type': 'application/json',
135
+ },
136
+ body: JSON.stringify(InputData),
137
+ }).then(async (data)=>{
138
+ // process Onairos Data
139
+ })
140
+ .catch(error => console.error(error));
141
+
142
+ }}
143
+
144
+ ```
145
+
146
+ ### 6. Output Format
147
+
148
+ 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.
149
+
150
+ Example of the output format:
151
+
152
+ ```json
153
+ {
154
+ "output": [
155
+ [[0.9998]],
156
+ [[0.9999]],
157
+ [[0.9922]],
158
+ [[0.0013]],
159
+ // Additional scores for more entries
160
+ ]
161
+ }
162
+ ```
163
+
164
+ Each score is deeply nested within two arrays to maintain compatibility with batch processing systems that may require this format.
165
+
166
+ ### Interpretation of Output
167
+
168
+ - A score close to `1` indicates a high confidence level in the prediction.
169
+ - A score close to `0` indicates a low confidence level in the prediction.
170
+ - The sequence of scores corresponds to the order of the input entries.
171
+
172
+ ### Example Usage in a React Application
173
+
174
+ The following React component demonstrates how to send a prediction request to the API and display the results:
175
+
176
+ ```jsx
177
+ import React, { useState } from 'react';
178
+
179
+ function App() {
180
+
181
+ async function UseAPIURL(event){
182
+ if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
183
+ const apiUrl = event.data.APIurl;
184
+ await fetch(apiUrl, {
185
+ method: 'POST',
186
+ headers: {
187
+ 'Content-Type': 'application/json',
188
+ },
189
+ body: JSON.stringify(InputData),
190
+ }).then(async (data)=>{
191
+ // process Onairos Data
192
+ })
193
+ .catch(error => console.error(error));
194
+
195
+ }}
196
+
197
+ const sendData = {
198
+ interestModel: {
199
+ title:'Interest',
200
+ descriptions:"Insight into your Interests",
201
+ reward:"10% Discount"
202
+ },
203
+ personalityModel:{
204
+ title:'Personality',
205
+ descriptions:"Insight into your Interests",
206
+ reward:"2 USDC"
207
+ },
208
+ intelectModel:{
209
+ title:'Intellect',
210
+ descriptions:"Insight into your Interests",
211
+ reward:"2 USDC"
212
+ },
213
+ };
214
+ useEffect(() => {
215
+ window.addEventListener('message', UseAPIURL);
216
+ return () => {
217
+ window.removeEventListener('message', UseAPIURL);
218
+ };
219
+ }, []);
220
+
221
+ const onairosID = 'test';
222
+ return (
223
+ <Onairos sendData={sendData} onairosID={onairosID} />
224
+ );
225
+ }
226
+ export default InferenceComponent;
227
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onairos",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "dependencies": {
5
5
  "@testing-library/jest-dom": "^5.17.0",
6
6
  "@testing-library/react": "^13.4.0",
package/src/onairos.jsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import onairosLogo from "./OnairosBlack.png";
3
3
 
4
- function Onairos( {sendData, onairosID, access_token}) {
4
+ function Onairos( {requestData, onairosID, access_token, proofMode=false,webpageName}) {
5
5
  const OnairosAnime = async () => {
6
6
  try {
7
7
  console.log("Clicked Onairos Connect")
@@ -19,11 +19,12 @@ function Onairos( {sendData, onairosID, access_token}) {
19
19
  window.postMessage({
20
20
  source: 'webpage',
21
21
  type: 'GET_API_URL',
22
- webpage: 'proxy book store',
22
+ webpageName: webpageName,
23
23
  onairosID:onairosID,
24
24
  access_token:access_token,
25
25
  account:"ConnectedAccountRef.current", //No Longer needed, REMOVE
26
- requestData: sendData,
26
+ requestData: requestData,
27
+ proofMode:proofMode
27
28
  });
28
29
  };
29
30