Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into nadeesha/data-connect…
Browse files Browse the repository at this point in the history
…or-mysql
  • Loading branch information
nadeesha committed Dec 3, 2024
2 parents 77f8252 + 523d21c commit 40f71de
Show file tree
Hide file tree
Showing 13 changed files with 863 additions and 53 deletions.
Binary file modified archives/bootstrap-dotnet.zip
Binary file not shown.
Binary file modified archives/bootstrap-go.zip
Binary file not shown.
Binary file modified archives/bootstrap-node.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion bootstrap-dotnet/bootstrap-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Inferable" Version="0.0.17" />
<PackageReference Include="Inferable" Version="0.0.18" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion control-plane/src/modules/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export const definition = {
.describe("Enable reasoning traces"),
callSummarization: z
.boolean()
.default(true)
.default(false)
.optional()
.describe("Enable summarization of oversized call results"),
interactive: z
Expand Down
2 changes: 1 addition & 1 deletion data-connector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ docker run -e INFERABLE_API_SECRET="sk_xxxx" \
2. Rename `.env.example` to `.env` and set your Inferable API secret:

```bash
INFERABLE_SECRET=your_secret_here
INFERABLE_API_SECRET=your_secret_here

# DEMO POSTGRES CONFIG
POSTGRES_URL=postgresql://postgres:postgres@db:5432/postgres
Expand Down
36 changes: 0 additions & 36 deletions data-connector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions data-connector/src/postgres/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { approvalRequest, blob, ContextInput, Inferable } from "inferable";
import pg from "pg";
import { z } from "zod";
import crypto from "crypto";
import type { DataConnector } from "../types";
import type { DataConnector } from "./types";

export class PostgresClient implements DataConnector {
private client: pg.Client | null = null;
private initialized = false;
private initialized: Promise<void>;

constructor(
private params: {
Expand All @@ -34,7 +34,6 @@ export class PostgresClient implements DataConnector {

process.removeListener("SIGTERM", this.handleSigterm);
process.on("SIGTERM", this.handleSigterm);
this.initialized = true;
} catch (error) {
console.error("Failed to initialize database connection:", error);
throw error;
Expand Down Expand Up @@ -71,8 +70,8 @@ export class PostgresClient implements DataConnector {
return res.rows;
};

getPostgresContext = async () => {
if (!this.initialized) throw new Error("Database not initialized");
getContext = async () => {
await this.initialized;
const client = await this.getClient();
const tables = await this.getAllTables();

Expand Down Expand Up @@ -109,10 +108,7 @@ export class PostgresClient implements DataConnector {
return context;
};

executePostgresQuery = async (
input: { query: string },
ctx: ContextInput,
) => {
executeQuery = async (input: { query: string }, ctx: ContextInput) => {
if (this.params.paranoidMode) {
if (!ctx.approved) {
console.log("Query requires approval");
Expand All @@ -122,7 +118,7 @@ export class PostgresClient implements DataConnector {
}
}

if (!this.initialized) throw new Error("Database not initialized");
await this.initialized;
const client = await this.getClient();
const res = await client.query(input.query);

Expand Down Expand Up @@ -156,14 +152,14 @@ export class PostgresClient implements DataConnector {
});

service.register({
name: "getPostgresContext",
func: this.getPostgresContext,
name: "getContext",
func: this.getContext,
description: "Gets the schema of the database.",
});

service.register({
name: "executePostgresQuery",
func: this.executePostgresQuery,
name: "executeQuery",
func: this.executeQuery,
description:
"Executes a raw SQL query. If this fails, you need to getContext to learn the schema first.",
schema: {
Expand Down
1 change: 1 addition & 0 deletions examples/pg-stat-analysis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
history.json
54 changes: 54 additions & 0 deletions examples/pg-stat-analysis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<p align="center">
<img src="https://a.inferable.ai/logo-hex.png" width="200" style="border-radius: 10px" />
</p>

# @inferable/pg-stat-analysis

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

## Overview

`@inferable/pg-stat-analysis` is an analytical agent designed to evaluate and improve the performance of your PostgreSQL database through recommendations based on access patterns. The agent provides suggestions such as creating indexes or other optimization strategies to enhance query performance. It makes use of the `pg_stat_statements` extension to provide data-driven recommendations.

## Prerequisites

- **Node.js** - Ensure you have Node.js installed.
- **PostgreSQL** - A running PostgreSQL instance with the `pg_stat_statements` [extension enabled](https://www.postgresql.org/docs/current/pgstatstatements.html).
- **Data Connector** - This projects assumes you are runnign the [Inferable Data Connector](https://github.com/inferablehq/inferable/tree/main/data-connector) which provides the connection to your database.

## Installation

1. **Install Dependencies:**

```bash
npm install
```

2. **Environment Setup:**

Create a `.env` file in the project root with the following variable:

```
INFERABLE_API_SECRET=your_inferable_api_secret
```

Replace `your_inferable_api_secret` with your Cluster's [API secret](https://docs.inferable.ai/pages/auth#cluster-api-keys).

## Usage

Once the environment is set up, you can run the project in development mode using the following command:

```bash
npm run dev
```

This will initiate the agent, which will analyze your database and provide performance-enhancing recommendations stored in `history.json`.
Multiple runs will append to the existing data in `history.json`.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## Support

If you have any questions or issues, please open an issue on this repository.
Loading

0 comments on commit 40f71de

Please sign in to comment.