AI Provider Integration
This tutorial allows AI service providers to integrate their AI APIs onto the Oraichain's AI Oracle service.

1. Write a deno script

The deno script will help you process the input & output of your service dynamically when being executed by AI executors. Since all services is different, the executors cannot run a program that contains a particular application's logic.
A simple example of a deno script that takes IPFS hashes as inputs, and call POST requests to a flower classification service:
1
import _ from "https://deno.land/[email protected]/node/module.ts";
2
3
const httpPost = async (hash) => {
4
const url = "https://100api.orai.dev/cv010";
5
// Build formData object.
6
let formData = new FormData();
7
formData.append('input_source_hash', hash);
8
9
const data = await fetch(url, {
10
method: 'POST',
11
body: formData
12
}).then(data => data.json());
13
return data;
14
}
15
16
const main = async (data) => {
17
const params = JSON.parse(data);
18
const responses = [];
19
for (let i = 0; i < params.length; i++) {
20
try {
21
let result = await httpPost(params[i]);
22
if (result.data && result.data.length > 0) {
23
result.data = result.data.map(data => ({ ...data, score: Math.floor(data.score) }))
24
responses.push(result);
25
}
26
} catch (error) {
27
continue;
28
}
29
}
30
console.log(JSON.stringify(responses))
31
};
32
33
main(...process.argv.slice(2))
Copied!
You will see later that by creating a data source smart contract, you'll be able to pass an array of string parameters into this deno script.
After writing your deno script, please upload it to a public file hosting, which has a public URL that the AI executors can read from. In this case, we have uploaded it to a public github repository called deno-scripts

2. Deploy a data source contract

The data source contract is the trusted source for the executors to collect AI APIs & execute them. It stores the deno script's programming language, URL (which is the deno script's URL), and input parameters. These input parameters will be fed into your script as mentioned above and you can access them by using JSON parsing.
The simplest way to have a data source contract is to deploy an empty contract (without custom business logic). Click here for more information on how to deploy a CosmWasm contract. You can also customize the data source to suit your need, but it must follow the same template as provided by the Oraichain. Otherwise, the executors won't be able to run your service.

3. Deploy an oracle script contract

The oracle script is used to aggregate your data source result after it is called multiple times by the AI executors. When writing an oracle script, you need to have at least one Aggregate query message. Please take a look at a simple example of the oracle script classification here
After deploying the oracle script, please send us the two addresses & your service name (in string) so we can add them in the list of services. At the moment, only chosen services are added due to security & simplicity purposes.