onairos 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/README.md +196 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,196 @@
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
+ "interestModel": {
22
+ "title":"Interest",
23
+ "descriptions":"Insight into your Interests",
24
+ "reward":"10% Discount"
25
+ },
26
+ "personalityModel":{
27
+ "title":"Personality",
28
+ "descriptions":"Insight into your Interests",
29
+ "reward":"2 USDC"
30
+ },
31
+ "intelectModel":{
32
+ "title":"Intellect",
33
+ "descriptions":"Insight into your Interests",
34
+ "reward":"2 USDC"
35
+ }
36
+ }
37
+
38
+ ```
39
+ Only the personalityModel request object is valid at this time
40
+
41
+ Then instantiate the Onairos object from the Onairos package - passing in your Onairos Developer ID and your Request Object
42
+ ```jsx
43
+ <Onairos sendData={sendData} onairosID={onairosID} />
44
+ ```
45
+
46
+ That is all for the initial setup
47
+
48
+ ### 4. Recieving the Inference API
49
+
50
+ 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:
51
+ ```jsx
52
+ event.data.source === 'content-script'
53
+ &&
54
+ event.data.type === 'API_URL_RESPONSE'
55
+ ```
56
+
57
+ ## Using the Inference API
58
+
59
+ 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.
60
+
61
+ ### 5. Input Format
62
+
63
+ 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:
64
+
65
+ - `title`: The title of the content (String).
66
+ - `category`: The category to which the content belongs (String).
67
+ - `img_url`: The URL of an image associated with the content (String).
68
+
69
+ Example JSON body for the POST request:
70
+
71
+ ```json
72
+
73
+ "Input": {
74
+ "input1": {
75
+ "title": "Example Title 1",
76
+ "category": "Example Category 1",
77
+ "img_url": "http://example.com/image1.jpg"
78
+ },
79
+ "input2": {
80
+ "title": "Example Title 2",
81
+ "category": "Example Category 2",
82
+ "img_url": "http://example.com/image2.jpg"
83
+ },
84
+ "input3": {
85
+ "title": "Example Title 3",
86
+ "category": "Example Category 3",
87
+ "img_url": "http://example.com/image3.jpg"
88
+ }
89
+ }
90
+ // Additional entries can be added here
91
+
92
+
93
+ ```
94
+
95
+ You can then call the Inference API with the Inference object created above
96
+
97
+ ```jsx
98
+ export default async function UseAPIURL(event){
99
+ if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
100
+ const apiUrl = event.data.APIurl;
101
+ await fetch(apiUrl, {
102
+ method: 'POST',
103
+ headers: {
104
+ 'Content-Type': 'application/json',
105
+ },
106
+ body: JSON.stringify(InputData),
107
+ }).then(async (data)=>{
108
+ // process Onairos Data
109
+ })
110
+ .catch(error => console.error(error));
111
+
112
+ }}
113
+ ```
114
+
115
+ ### 6. Output Format
116
+
117
+ 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.
118
+
119
+ Example of the output format:
120
+
121
+ ```json
122
+ {
123
+ "output": [
124
+ [[0.9998]],
125
+ [[0.9999]],
126
+ [[0.9922]],
127
+ [[0.0013]],
128
+ // Additional scores for more entries
129
+ ]
130
+ }
131
+ ```
132
+
133
+ Each score is deeply nested within two arrays to maintain compatibility with batch processing systems that may require this format.
134
+
135
+ ### Interpretation of Output
136
+
137
+ - A score close to `1` indicates a high confidence level in the prediction.
138
+ - A score close to `0` indicates a low confidence level in the prediction.
139
+ - The sequence of scores corresponds to the order of the input entries.
140
+
141
+ ### Example Usage in a React Application
142
+
143
+ The following React component demonstrates how to send a prediction request to the API and display the results:
144
+
145
+ ```jsx
146
+ import React, { useState } from 'react';
147
+
148
+ function App() {
149
+
150
+ async function UseAPIURL(event){
151
+ if (event.data && event.data.source === 'content-script' && event.data.type === 'API_URL_RESPONSE') {
152
+ const apiUrl = event.data.APIurl;
153
+ await fetch(apiUrl, {
154
+ method: 'POST',
155
+ headers: {
156
+ 'Content-Type': 'application/json',
157
+ },
158
+ body: JSON.stringify(InputData),
159
+ }).then(async (data)=>{
160
+ // process Onairos Data
161
+ })
162
+ .catch(error => console.error(error));
163
+
164
+ }}
165
+
166
+ const sendData = {
167
+ interestModel: {
168
+ title:'Interest',
169
+ descriptions:"Insight into your Interests",
170
+ reward:"10% Discount"
171
+ },
172
+ personalityModel:{
173
+ title:'Personality',
174
+ descriptions:"Insight into your Interests",
175
+ reward:"2 USDC"
176
+ },
177
+ intelectModel:{
178
+ title:'Intellect',
179
+ descriptions:"Insight into your Interests",
180
+ reward:"2 USDC"
181
+ },
182
+ };
183
+ useEffect(() => {
184
+ window.addEventListener('message', UseAPIURL);
185
+ return () => {
186
+ window.removeEventListener('message', UseAPIURL);
187
+ };
188
+ }, []);
189
+
190
+ const onairosID = 'test';
191
+ return (
192
+ <Onairos sendData={sendData} onairosID={onairosID} />
193
+ );
194
+ }
195
+ export default InferenceComponent;
196
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onairos",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "dependencies": {
5
5
  "@testing-library/jest-dom": "^5.17.0",
6
6
  "@testing-library/react": "^13.4.0",