Skip to content

Commit

Permalink
Add AI App Framework (#563)
Browse files Browse the repository at this point in the history
* WIP AI framework docs

* Add details on overriding config

* Add RagTool and embedding model

* Prettier

* Tweaks and improvements

* CSS

* Add more marketing content

* Notes about publish not yet supported

* Update cli install command

* RAG file

* Minor typos

* Add features image

* Update docs/ai/build/app.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/app.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/app.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/app.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/app.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/function_tools.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/function_tools.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/function_tools.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/rag.md

Co-authored-by: Jim Counter <[email protected]>

* Update docs/ai/build/rag.md

Co-authored-by: Jim Counter <[email protected]>

* Start work on guide

* Add guide

* Update fancy greeter example code

* Update example code

* Update homepage and fix links

* Typos

---------

Co-authored-by: Scott Twiname <[email protected]>
Co-authored-by: Jim Counter <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent 148065e commit d768dda
Show file tree
Hide file tree
Showing 22 changed files with 2,100 additions and 799 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This is the home of SubQuery documentation. All updates to docs should be added

We welcome any contributions or improvements from our community, if you're looking for support we suggest starting by going to the technical support channel in SubQuery's official [Discord server](https://discord.com/invite/subquery).

**Note you should really use `pnpm` package manager when editing docs.**

## Contributing To SubQuery

Welcome and a big thank you for considering contributing to this SubQuery project! Together we can pave the way to a more decentralised future.
Expand Down
18 changes: 11 additions & 7 deletions docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default defineUserConfig({
text: "SubQuery Indexer SDK",
link: "/indexer/welcome.md",
},
{
text: "SubQuery AI Apps Framework",
link: "/ai/welcome.md",
},
{
text: "SubQuery Network",
link: "/subquery_network/welcome.md",
Expand Down Expand Up @@ -193,40 +197,40 @@ export default defineUserConfig({
app.pages.map(({ path }) => [
path.replace(
"/subquery_network/node_operators/indexers/",
"/subquery_network/indexers/",
"/subquery_network/indexers/"
),
path,
]),
])
),
...Object.fromEntries(
app.pages.map(({ path }) => [
path.replace("/indexer/academy/", "/academy/"),
path,
]),
])
),
...Object.fromEntries(
app.pages.map(({ path }) => [
path.replace("/indexer/build/", "/build/"),
path,
]),
])
),
...Object.fromEntries(
app.pages.map(({ path }) => [
path.replace("/indexer/miscellaneous/", "/miscellaneous/"),
path,
]),
])
),
...Object.fromEntries(
app.pages.map(({ path }) => [
path.replace("/indexer/quickstart/", "/quickstart/"),
path,
]),
])
),
...Object.fromEntries(
app.pages.map(({ path }) => [
path.replace("/indexer/run_publish/", "/run_publish/"),
path,
]),
])
),
};
},
Expand Down
Binary file added docs/.vuepress/public/assets/img/ai/features.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/.vuepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,43 @@ export const getSidebar = (locale: string) =>
`${locale}/subquery_network/community.md`,
`${locale}/subquery_network/glossary.md`,
],
"/ai/": [
{
text: "Welcome",
link: `${locale}/ai/welcome.md`,
},
{
text: "Guides",
link: `${locale}/ai/guides/fancy-greeter.md`,
children: [`${locale}/ai/guides/fancy-greeter.md`],
},
{
text: "Build",
link: `${locale}/ai/build/app.md`,
children: [
`${locale}/ai/build/app.md`,
`${locale}/ai/build/function_tools.md`,
`${locale}/ai/build/rag.md`,
],
},
{
text: "Run",
link: `${locale}/ai/run/local.md`,
children: [
`${locale}/ai/run/local.md`,
`${locale}/ai/run/cli.md`,
`${locale}/ai/run/docker.md`,
],
},
{
text: "Query",
link: `${locale}/ai/query/query.md`,
},
{
text: "Publish",
link: `${locale}/ai/publish/publish.md`,
},
],
"/miscellaneous/": [
`${locale}/miscellaneous/contributing.md`,
`${locale}/miscellaneous/social_media.md`,
Expand Down
11 changes: 4 additions & 7 deletions docs/.vuepress/styles/index.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
// place your custom styles here
@font-face {
font-family: "Inter";
src:
local("Inter-Regular"),
src: local("Inter-Regular"),
url("https://static.subquery.network/design/fonts/Inter-Regular.ttf")
format("truetype");
font-display: swap;
}

@font-face {
font-family: "Inter-SemiBold";
src:
local("Inter-SemiBold"),
src: local("Inter-SemiBold"),
url("https://static.subquery.network/design/fonts/Inter-SemiBold.ttf")
format("truetype");
font-display: swap;
}

@font-face {
font-family: "Inter-Bold";
src:
local("Inter-Bold"),
src: local("Inter-Bold"),
url("https://static.subquery.network/design/fonts/Inter-Bold.ttf")
format("truetype");
font-display: swap;
Expand Down Expand Up @@ -147,7 +144,7 @@ iframe {
.vp-sidebar-link {
transition: all 0.2s linear;
margin: 0;
padding: 12px 24px;
padding: 12px 16px;
border-radius: 0;
}

Expand Down
32 changes: 27 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ photoSwipe: false
<Typography tag="h4" center maxWidth="687" family="body">
The SubQuery Data Indexer is a open-source data indexer that provides
you with custom APIs for your web3 project across all of our supported
chains.</Typography
>
chains.
</Typography>
<Typography tag="h4" center maxWidth="687" family="body">
SubQuery AI Apps framework makes building decentralised AI Applications
fast and easy.
</Typography>
</div>
</div>
<div class="layout flex mt80 gp24 flexColMobile">
Expand All @@ -51,6 +55,23 @@ photoSwipe: false
</div>
</router-link>
</BaseCard>
<BaseCard>
<router-link
class="flexCol gp24"
:to="{ path: '/ai/welcome.html' }"
>
<div class="flexCenter gp16">
<img src="/assets/img/home/indexer-sdk.png" />
<Typography tag="h4" family="body">AI Apps Framework</Typography>
</div>
<Typography tag="h3">Intelligent apps with SubQuery's AI Apps</Typography>
<Typography tag="h5" type="secondary"
>The AI App Framework allows you to build, deploy, and run production AI apps on the SubQuery Network in a trusted and decentralised environment.</Typography>
<div>
<Button class="mt40">Learn more</Button>
</div>
</router-link>
</BaseCard>
<BaseCard>
<router-link
class="flexCol gp24"
Expand All @@ -73,6 +94,7 @@ photoSwipe: false
</div>
</router-link>
</BaseCard>

</div>
<div class="layout mt140">
<Typography tag="h3"> Our Most Popular Guides </Typography>
Expand Down Expand Up @@ -154,9 +176,9 @@ const polularGuides = computed(() => {
"description": "The SubQuery Token (SQT) is a utility token that powers the SubQuery Network. Learn how to get SQT and the tokenomics of it."
},
{
"path": "/indexer/run_publish/publish.html",
"title": "How to host and run your project",
"description": "SubQuery is open-source and gives a number of different options, including self-hosting, our managed service, and our decentralised network."
"path": "/ai/welcome.html",
"title": "Build and deploy AI Apps with SubQuery",
"description": "Anyone can build intelligent dApps with the SubQuery AI App framework, providing a shortcut for developers to start incorporating decentralised AI into their applications."
}
]})

Expand Down
160 changes: 160 additions & 0 deletions docs/ai/build/app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# AI Apps

The SubQuery AI App framework is designed with user-friendliness in mind, providing intuitive wrappers around core features. This lowers the barrier to entry for developers of all skill levels, making it easier to create, run, and deploy AI Apps.

Building an AI application is a straightforward process that takes minutes. The SubQuery AI App framework simplifies most of this development, while allowing you to build complex applications that are ready to run on a decentralised network.

There are a few components to an application, to get started, create a project manifest and entrypoint.

## Project Manifest

The project manifest is the start point for your project. It defines a set of options and references your [tools](./tools) and [rag data](./rag). The format of this file can either be in JSON or TypeScript format. It is recommended to use TypeScript as it can easily provide extra build time functionality and type safety.

::: info Note
When you publish your app, the TypeScript manifest will be converted to JSON.
:::

::: code-tabs

@tab:active typescript

```typescript
import type { ProjectManifest } from "jsr:@subql/ai-app-framework";

const project: ProjectManifest = {
// The version of the manifest spec, this is always 0.0.1.
specVersion: "0.0.1",
// For security reasons you must provide a list of allowed domains that your project will use
endpoints: ["gateway.subquery.network"],
// (Optional) Vector db storage for RAG data, currently only lance DB is supported
vectorStorage: {
type: "lancedb",
path: "./.db",
},
// (Optional) Runtime configuration options, this will get passed into your project entrypoint.
// It needs to be in the JSON Schema format. We recommend using @sinclair/typebox to make this easy and provide runtime type checking.
config: {
type: "object",
properties: {
GRAPHQL_ENDPOINT: {
default:
"https://gateway.subquery.network/query/QmcoJLxSeBnGwtmtNmWFCRusXVTGjYWCK1LoujthZ2NyGP",
type: "string",
},
BASE_RPC: {
default: "https://gateway.subquery.network/rpc/base-full",
type: "string",
},
BASE_SQT_ADDR: {
default: "0x858c50C3AF1913b0E849aFDB74617388a1a5340d",
type: "string",
},
},
required: ["GRAPHQL_ENDPOINT", "BASE_RPC", "BASE_SQT_ADDR"],
},
// The LLM model you wish to use. Currently any Ollama model is supported
model: "llama3.1",
// (Optional) The LLM model for generating vectors from text.
embeddingsModel: "nomic-embed-text",
// The path to your project entrypoint
entry: "./index.ts",
};

// The manifest must be the default export
export default project;
```

@tab json

```json
{
"specVersion": "0.0.1",
"endpoints": ["gateway.subquery.network"],
"vectorStorage": {
"type": "lancedb",
"path": "./.db"
},
"config": {
"type": "object",
"properties": {
"GRAPHQL_ENDPOINT": {
"default": "https://gateway.subquery.network/query/QmcoJLxSeBnGwtmtNmWFCRusXVTGjYWCK1LoujthZ2NyGP",
"type": "string"
},
"BASE_RPC": {
"default": "https://gateway.subquery.network/rpc/base-full",
"type": "string"
},
"BASE_SQT_ADDR": {
"default": "0x858c50C3AF1913b0E849aFDB74617388a1a5340d",
"type": "string"
}
},
"required": ["GRAPHQL_ENDPOINT", "BASE_RPC", "BASE_SQT_ADDR"]
},
"model": "llama3.1",
"entry": "./index.ts"
}
```

:::

### Config

To specify or override default config values when running, you can provide them with environment variables.

Example:

```shell
GRAPHQL_ENDPOINT=https://some.other.endpoint subql-ai -p ./path/to/project.ts
```

## Project Entrypoint

The project entrypoint is how your tools and system prompt are initialised, unlike the project manifest this is not static so you can change the behaviour based on your config spec.

Example entrypoint:

```typescript
import type { ProjectEntry, Project } from "jsr:@subql/ai-app-framework";

// This is your system prompt. It gives broad information to the LLM about what your application should to and how it should respond.
const SYSTEM_PROMPT = `
You are an agent designed to help a user with their token delegation on the SubQuery Network.
Given an input question, use the available tools to answer the users question quickly and concisely.
Your answer must use the result of the tools available.
Do not mention that you used a tool or the name of a tool.
If you need more information to answer the question, ask the user for more details.
All token amounts are in SQT.
If the question seems to be unrelated to the API, just return "I don't know" as the answer.
`;

const entrypoint: ProjectEntry = async (config: Config): Promise<Project> => {
return {
// Initialise any tools you wish to provided with your app
tools: [
new TotalDelegation(config.GRAPHQL_ENDPOINT),
new DelegatedIndexers(config.GRAPHQL_ENDPOINT),
new UnclaimedDelegatorRewards(config.GRAPHQL_ENDPOINT),
new CurrentDelegatorApy(config.GRAPHQL_ENDPOINT),
new BetterIndexerApy(config.GRAPHQL_ENDPOINT),
new TokenBalance(
new JsonRpcProvider(config.BASE_RPC),
config.BASE_SQT_ADDR
),
new SubqueryDocs(),
],
systemPrompt: SYSTEM_PROMPT,
};
};

// The project entry must be a default export
export default entrypoint;
```

## Next Steps

- [Define any additional function tools](./function_tools)
- [Add RAG data](./rag)
- Optimise your System Prompt and Tool descriptions.
Loading

0 comments on commit d768dda

Please sign in to comment.