Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:effectai/effect-js into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisses committed May 17, 2024
2 parents f61732a + bb176a2 commit fbef4b6
Show file tree
Hide file tree
Showing 35 changed files with 658 additions and 121 deletions.
6 changes: 6 additions & 0 deletions .changeset/new-chairs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@effectai/sdk": patch
---

- add symlinks for license and README
- fix createBatch types
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
28 changes: 0 additions & 28 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
},
"dependencies": {},
"devDependencies": {
"@wharfkit/wallet-plugin-anchor": "^1.0.0",
"@wharfkit/web-renderer": "^1.0.3",
"@wharfkit/wallet-plugin-privatekey": "1.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vocs": "^1.0.0-alpha.46",
Expand Down
62 changes: 62 additions & 0 deletions docs/pages/docs/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Authentication
Some functions in the Effect AI SDK require authentication with the EOS blockchain. This is done by passing a session object to the createClient function.
A session can be established by either [private key](https://github.com/wharfkit/wallet-plugin-privatekey) or [wallet plugins](https://wharfkit.com/plugins?tag=wallet-plugin).

### Private Key
To authenticate using a private key we recommend using the [wallet-plugin-privatekey](https://github.com/wharfkit/wallet-plugin-privatekey)
And passing it through a session to the `createClient` function.

```ts twoslash
import {
createClient,
eos,
Session
} from "@effectai/sdk";

import { WalletPluginPrivateKey } from '@wharfkit/wallet-plugin-privatekey'

const session = new Session({
chain: eos,
walletPlugin: new WalletPluginPrivateKey(
'5Jtoxgny5tT7NiNFp1MLogviuPJ9NniWjnU4wKzaX4t7pL4kJ8s',
),
})

const client = await createClient({ session })
```

### Wallet Plugin
It's also possible to authenticate using a wallet plugin, for example using the [wallet-plugin-anchor](https://github.com/wharfkit/wallet-plugin-anchor)
This one is a bit more complicated and requires two additional packages: [`@wharfkit/session`](https://github.com/wharfkit/session) and [`@wharfkit/web-renderer`](https://github.com/wharfkit/web-renderer)

```ts twoslash
import {
createClient,
eos,
} from "@effectai/sdk";

import { SessionKit } from "@wharfkit/session";
import { WebRenderer } from "@wharfkit/web-renderer";
import { WalletPluginAnchor } from "@wharfkit/wallet-plugin-anchor";

const webRenderer = new WebRenderer();

const sessionKit = new SessionKit(
{
appName: "Effect Network",
chains: [eos],
ui: webRenderer,
walletPlugins: [
new WalletPluginAnchor(),
],
},
)

const session = await sessionKit.restore();

if(!session) {
throw new Error('Session not found')
}

const client = await createClient({ session })
```
44 changes: 29 additions & 15 deletions docs/pages/docs/collecting-data/adding-tasks.mdx
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
## Adding tasks

Adding tasks to a campaign is done through <u>batches</u> batches are a collection of tasks that are added to a campaign. Each batch can contain multiple tasks.
Let's start by creating a batch with 3 tasks to our newly created image classification campaign.
Adding tasks to a campaign is done through adding <u>batches</u>.

```ts [example.ts]
import { createBatch } from '@effectai/effect-js'
Batches are a collection of tasks that are added to a campaign. Each batch can contain multiple tasks.
Let's start by creating a batch with 3 tasks to our newly created image classification campaign.

```ts twoslash
// [!include ~/snippets/getting-started/getting-started-auth.ts]
if(!client.session) {
throw new Error('No session found')
}
const { actor } = client.session

if(!actor) {
throw new Error('No actor found')
}
//---cut---
import { createBatch } from '@effectai/sdk'

const batch = await createBatch({
client,
batch: {
campaign_id: '<..>', // the id of the campaign
repetitions: 1 // number of times each task should be repeated
payer: actor // the actor that will pay the workers for the tasks
}
data: [
// The campaign id to which the batch should be added
campaignId : 1,
// The number of times each task in the batch should be repeated
repetitions: 1,
// The reward for each task in the batch
reward: 3,
// The template placeholders for each task in the batch
taskData : [
{
image: 'https://example.com/image.jpg', //task 1 image placeholder
ipfs_url: 'https://example.com/image.jpg', //task 1 image placeholder
},
{
image: 'https://example.com/image2.jpg', //task 2 image placeholder
ipfs_url: 'https://example.com/image2.jpg', //task 2 image placeholder
},
{
image: 'https://example.com/image3.jpg', // task 3 image placeholder
ipfs_url: 'https://example.com/image3.jpg', // task 3 image placeholder
}
]
],
})
```

```

3 changes: 3 additions & 0 deletions docs/pages/docs/collecting-data/collecting-results.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Collecting Results

TODO::
1 change: 0 additions & 1 deletion docs/pages/docs/compatibility.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

The Effect AI SDK is compatible with all Node.js environments, including browsers and React Native.
It might be necessary to use a particular `fetch` polyfill in some environments.
You can read more about it [here](./glossary/client_options.mdx)
9 changes: 6 additions & 3 deletions docs/pages/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
jungle4
} from "@effectai/sdk";

// Create client
const client = await createClient({ network: jungle4 });
```

Expand All @@ -44,10 +43,10 @@ import {

const client = await createClient({ network: eos });
```
:::

:::

### 2. Use the client
### 2. Using the client
```ts twoslash
import {
createClient,
Expand All @@ -62,6 +61,10 @@ import {
const campaigns = await getCampaigns({ client });
```

### 3. Authentication

Depending on your use case, you might need some sort of authentication with the EOS blockchain. Authentication is done through passing a [Wharfkit Session](https://wharfkit.com/kits/session). Read our guide on how to Authentication depending on your environment.


## What's next ?

Expand Down
3 changes: 1 addition & 2 deletions docs/pages/docs/glossary/client-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ As we can see, the ClientOpts interface has three optional properties:
This property is used to set the cache duration for the IPFS data.
The default value is 600_000 milliseconds; 10 minutes.

## `fetchProfider`
## `fetchProvider`

This property is used to set the fetch provider.
This is needed because of the different runtimes availalbe to Java Script.
Expand Down Expand Up @@ -45,6 +45,5 @@ const client = createClient({
})
```

# TODO: This needs to be changed when the `dev` branch is merged into main.
[See Type](https://github.com/effectai/effect-js/blob/main/src/client.ts)

8 changes: 4 additions & 4 deletions docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ style={{
:::code-group

```bash [npm]
npm i @effectai/effect-js
npm i @effectai/sdk
```

```bash [pnpm]
pnpm i @effectai/effect-js
pnpm i @effectai/sdk
```

```bash [bun]
bun i @effectai/effect-js
bun i @effectai/sdk
```

:::
Expand All @@ -69,7 +69,7 @@ style={{
<span className="font-medium text-[15px] leading-none opacity-80 w-full text-center">coverage</span>
</div>
<div className="flex items-center h-full px-2">
<span className="font-medium text-[15px] leading-none text-center w-full text-green-400">0%</span>
<span className="font-medium text-[15px] leading-none text-center w-full text-green-400">63.34%</span>
</div>
</div>
<div className="absolute left-0 right-0 top-0 bottom-0 bg-green-400 opacity-10 z-[0]" />
Expand Down
Empty file added docs/public/.nojekyll
Empty file.
1 change: 1 addition & 0 deletions docs/public/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs.effect.ai
49 changes: 27 additions & 22 deletions docs/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const sidebar = {
items: [
{ text: "Why Effect AI", link: "/docs/introduction" },
{ text: "Getting Started", link: "/docs/getting-started" },
{ text: "Authentication", link: "/docs/authentication" },
],
},
{
Expand All @@ -25,6 +26,10 @@ export const sidebar = {
text: "Adding Tasks to a Campaign",
link: "/docs/collecting-data/adding-tasks",
},
{
text: "Collecting results",
link: "/docs/collecting-data/collecting-results",
},
],
},
{
Expand All @@ -35,28 +40,20 @@ export const sidebar = {
text: "SDK API",
items: [
{
text: "vAccount",
text: "Tasks",
items: [
{ text: "claim", link: "/docs/vaccount/claim" },
{
text: "createAccount",
link: "/docs/vaccount/create-account",
text: "createCampaign",
link: "/docs/tasks/campaigns/create-campaign",
},
{ text: "deposit", link: "/docs/vaccount/deposit" },
{
text: "getVAccounts",
link: "/docs/vaccount/get-accounts",
text: "getCampaigns",
link: "/docs/tasks/campaigns/get-campaigns",
},
// {
// text: "TODO: getAvatar",
// link: "/docs/vaccount/get-avatar",
// },
{
text: "getPendingPayments",
link: "/docs/vaccount/get-pending-payments",
text: "getCampaignById",
link: "/docs/tasks/campaigns/get-campaign-by-id",
},
{ text: "payout", link: "/docs/vaccount/payout" },
{ text: "withdraw", link: "/docs/vaccount/withdraw" },
],
},
{
Expand All @@ -69,20 +66,28 @@ export const sidebar = {
],
},
{
text: "Tasks",
text: "vAccount",
items: [
{ text: "claim", link: "/docs/vaccount/claim" },
{
text: "createCampaign",
link: "/docs/tasks/campaigns/create-campaign",
text: "createAccount",
link: "/docs/vaccount/create-account",
},
{ text: "deposit", link: "/docs/vaccount/deposit" },
{
text: "getCampaigns",
link: "/docs/tasks/campaigns/get-campaigns",
text: "getVAccounts",
link: "/docs/vaccount/get-accounts",
},
// {
// text: "TODO: getAvatar",
// link: "/docs/vaccount/get-avatar",
// },
{
text: "getCampaignById",
link: "/docs/tasks/campaigns/get-campaign-by-id",
text: "getPendingPayments",
link: "/docs/vaccount/get-pending-payments",
},
{ text: "payout", link: "/docs/vaccount/payout" },
{ text: "withdraw", link: "/docs/vaccount/withdraw" },
],
},
// {
Expand Down
7 changes: 1 addition & 6 deletions docs/snippets/getting-started/getting-started-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ const session = new Session({
});

// Create client to make authenticated transactions
const authClient = await createClient({ session });

// Create a new Effect Account
const account = "efxforce1112";
const response = await createVAccount({ client: authClient, account });
console.log(response); // => Transaction Details
const client = await createClient({ session });
Loading

0 comments on commit fbef4b6

Please sign in to comment.