Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Integrate OpenAPI client into data connector #206

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions data-connector/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ INFERABLE_API_SECRET=your_api_secret_here # Get one from https://app.inferable.a
#
POSTGRES_URL=postgresql://postgres:postgres@db:5432/postgres
POSTGRES_SCHEMA=public

#
# OpenAPI config example.
#
# OPENAPI_SPEC_URL=https://api.inferable.ai/public/oas.json
# SERVER_URL=https://api.inferable.ai
# SERVER_AUTH_HEADER=Authorization: Bearer your_api_key_here
37 changes: 27 additions & 10 deletions data-connector/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Inferable Data Connector
![Inferable Data Connector](./assets/hero.png)

Inferable Data Connector is a bridge between your data systems and Inferable. Configure your data sources in a json file and start conversing with your data in natural language.

Works locally, and in any dockerized environment without exposing your database to the public internet.
Inferable Data Connector is a bridge between your data systems and Inferable. Configure your data sources in a json file and start conversing with your data in natural language. Works locally, and in any dockerized environment without exposing your credentials (database credentials, API keys, etc.) to the public internet.

nadeesha marked this conversation as resolved.
Show resolved Hide resolved
## Features

Expand All @@ -13,6 +11,14 @@ Works locally, and in any dockerized environment without exposing your database
- 🤿 **Optional Privacy Mode**: Query outputs are never sent to the model. Instead, the function returns results directly to the end user without any model involvement.
- 🔍 **Optional Paranoid Mode**: Adds an additional safety layer by requiring manual approval before executing any query so you can review the query and data before it is executed.

## Connectors

- [x] [Postgres](./src/postgres.ts)
- [x] [OpenAPI](./src/open-api.ts)
- [ ] [GraphQL](./src/graphql.ts)
- [ ] [MySQL](./src/mysql.ts)
- [ ] [SQLite](./src/sqlite.ts)

## Quick Start

### Running with your own Postgres DB
Expand Down Expand Up @@ -88,14 +94,25 @@ Example configuration:

Each connector is defined in the `config.connectors` array.

- `type`: The type of connector. Currently only `postgres` is supported.
- `name`: The name of the connector. This is the Inferable service name. One will be generated if not provided.
- `config.connectors[].type`: The type of connector. Currently only `postgres` is supported.
- `config.connectors[].name`: The name of the connector. This is the Inferable service name. One will be generated if not provided.

<details>
<summary>Postgres Connector Configuration</summary>

- `config.connectors[].connectionString`: The connection string to your database. (e.g. `postgresql://postgres:postgres@localhost:5432/postgres`)
- `config.connectors[].schema`: The schema to use. (e.g. `public`)

</details>

<details>
<summary>OpenAPI Connector Configuration</summary>

### Connector-specific configuration
- `config.connectors[].specUrl`: The URL to your OpenAPI spec. Must be publicly accessible.
- `config.connectors[].endpoint`: The endpoint to use. (e.g. `https://api.inferable.ai`)
- `config.connectors[].defaultHeaders`: The default headers to use. (e.g. `{"Authorization": "Bearer <token>"}`)

| Connector | Configuration |
| --------- | ------------------------------- |
| Postgres | `connectionString` and `schema` |
</details>

### config.privacyMode

Expand Down
Binary file added data-connector/assets/hero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion data-connector/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"name": "myPostgres",
"connectionString": "process.env.POSTGRES_URL",
"schema": "process.env.POSTGRES_SCHEMA"
},
{
"type": "open-api",
"specUrl": "process.env.OPENAPI_SPEC_URL",
"endpoint": "process.env.SERVER_URL",
"defaultHeaders": {
"Authorization": "process.env.SERVER_AUTH_HEADER"
}
}
]
}
}
2 changes: 1 addition & 1 deletion data-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "src/index.ts",
"scripts": {
"start": "tsx src/index.ts",
"dev": "nodemon src/index.ts",
"dev": "tsx --watch -r dotenv/config src/index.ts",
"docker": "docker-compose up --build",
"docker:push": "docker build . -t inferable/data-connector && docker push inferable/data-connector:latest",
"seed": "tsx example_data/seed-postgres.ts"
Expand Down
11 changes: 11 additions & 0 deletions data-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "dotenv/config";
import { Inferable } from "inferable";
import { PostgresClient } from "./postgres";
import { RegisteredService } from "inferable/bin/types";
import { OpenAPIClient } from "./open-api";

const parseConfig = () => {
const config = require("../config.json");
Expand Down Expand Up @@ -41,8 +42,18 @@ const parseConfig = () => {
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
await postgresClient.initialize();
const service = postgresClient.createService(client);
services.push(service);
} else if (connector.type === "open-api") {
const openAPIClient = new OpenAPIClient({
...connector,
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
await openAPIClient.initialize();
const service = openAPIClient.createService(client);
services.push(service);
}
}

Expand Down
Loading
Loading