For this guide, we will make an agent that works against the OpenAPI spec for https://jsonplaceholder.typicode.com/guide/.
You can download the OpenAPI spec here: https://arnu515.github.io/jsonplaceholder-api-docs/
Steps
- Go to https://apitoagent.com/
- Upload the JSON OpenAPI spec
- Download the zip / unzip
- Open it in an editor of your choice
Setting Up
- Add your OpenAI key to the
.env
file - Run
pnpm install
,yarn install
, ornpm install
- Edit the
index.ts
file and add your API URL (https://jsonplaceholder.typicode.com
)
import { createApiClient, getGraphAndRun } from './core';
import dotenv from 'dotenv';
dotenv.config();
const client = createApiClient("https://jsonplaceholder.typicode.com", {
axiosConfig: {
}
});
(async () => {
const out = await getGraphAndRun(client, 'list posts');
})();
Running the Script
Run ts-node src/index.ts
Explore the Core
When you are done, head over to src/core.ts
to see how the magic happens. :) Happy building!