Skip to content

Commit

Permalink
Merge pull request #61 from lalalune/sqlite
Browse files Browse the repository at this point in the history
Sqlite
  • Loading branch information
lalalune authored Mar 20, 2024
2 parents 16dbdc0 + 8e78f37 commit acf5fc3
Show file tree
Hide file tree
Showing 63 changed files with 4,338 additions and 2,257 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
- uses: actions/setup-node@v2

- run: npm ci
- run: npm run test
- run: npm run test
- run: npm run test:sqlite
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ npx bgent
Currently bgent is dependent on Supabase for local development. You can install it with the following command:

```bash
npm install bgent @supabase/supabase-js
npm install bgent

# Select your database adapter
npm install sqlite-vss better-sqlite3 # for sqlite (simple, for local development)
npm install @supabase/supabase-js # for supabase (more complicated but can be deployed at scale)
```

### Set up environment variables
Expand All @@ -60,6 +64,23 @@ SUPABASE_SERVICE_API_KEY="your-supabase-service-api-key"
OPENAI_API_KEY="your-openai-api-key"
```

### SQLite Local Setup (Easiest)

You can use SQLite for local development. This is the easiest way to get started with bgent.

```typescript
import { BgentRuntime, SqliteDatabaseAdapter } from "bgent";
import { Database } from "sqlite3";
const sqliteDatabaseAdapter = new SqliteDatabaseAdapter(new Database(":memory:"));

const runtime = new BgentRuntime({
serverUrl: "https://api.openai.com/v1",
token: process.env.OPENAI_API_KEY, // Can be an API key or JWT token for your AI services
databaseAdapter: sqliteDatabaseAdapter,
// ... other options
});
```

### Supabase Local Setup

First, you will need to install the Supabase CLI. You can install it using the instructions [here](https://supabase.com/docs/guides/cli/getting-started).
Expand Down Expand Up @@ -115,17 +136,20 @@ npm run shell # start the shell in another terminal to talk to the default agent
## Usage

```typescript
import { BgentRuntime, SupabaseDatabaseAdapter } from "bgent";
import { BgentRuntime, SupabaseDatabaseAdapter, SqliteDatabaseAdapter } from "bgent";

const sqliteDatabaseAdapter = new SqliteDatabaseAdapter(new Database(":memory:"));

const databaseAdapter = new SupabaseDatabaseAdapter(
process.env.SUPABASE_URL,
process.env.SUPABASE_SERVICE_API_KEY)
;
// You can also use Supabase like this
// const supabaseDatabaseAdapter = new SupabaseDatabaseAdapter(
// process.env.SUPABASE_URL,
// process.env.SUPABASE_SERVICE_API_KEY)
// ;

const runtime = new BgentRuntime({
serverUrl: "https://api.openai.com/v1",
token: process.env.OPENAI_API_KEY, // Can be an API key or JWT token for your AI services
databaseAdapter,
databaseAdapter: sqliteDatabaseAdapter,
actions: [
/* your custom actions */
],
Expand Down Expand Up @@ -184,13 +208,11 @@ const runtime = new BgentRuntime({

The BgentRuntime instance has a `handleMessage` method that can be used to handle user input. The method returns a promise that resolves to the agent's response.

You will need to make sure that the userIds and room_id already exist in the database. You can use the Supabase client to create new users and rooms if necessary.
You will need to make sure that the room_id already exists in the database. You can use the Supabase client to create new users and rooms if necessary.

```typescript
const message = {
agentId: "agent-uuid", // Replace with your agent's UUID
senderId: "user-uuid", // Replace with the sender's UUID
userIds: ["user-uuid"], // List of user UUIDs involved in the conversation
userId: "user-uuid", // Replace with the sender's UUID
content: { content: content }, // The message content
room_id: "room-uuid", // Replace with the room's UUID
};
Expand Down
17 changes: 13 additions & 4 deletions docs/docs/classes/BgentRuntime.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Creates an instance of BgentRuntime.
| :------ | :------ | :------ |
| `opts` | `Object` | The options for configuring the BgentRuntime. |
| `opts.actions?` | [`Action`](../interfaces/Action.md)[] | Optional custom actions. |
| `opts.agentId?` | \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` | Optional ID of the agent. |
| `opts.databaseAdapter` | [`DatabaseAdapter`](DatabaseAdapter.md) | The database adapter used for interacting with the database. |
| `opts.debugMode?` | `boolean` | If true, debug messages will be logged. |
| `opts.embeddingModel?` | `string` | The model to use for embedding. |
Expand All @@ -47,6 +48,14 @@ Custom actions that the agent can perform.

___

### agentId

**agentId**: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` = `zeroUuid`

The ID of the agent

___

### databaseAdapter

**databaseAdapter**: [`DatabaseAdapter`](DatabaseAdapter.md)
Expand Down Expand Up @@ -170,7 +179,7 @@ ___

### composeState

▸ **composeState**(`message`): `Promise`\<\{ `actionConditions`: `string` ; `actionExamples`: `string` ; `actionNames`: `string` ; `actions`: `string` ; `actors`: `string` ; `actorsData`: [`Actor`](../interfaces/Actor.md)[] ; `agentId`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `agentName`: `undefined` \| `string` ; `evaluatorConditions`: `string` ; `evaluatorExamples`: `string` ; `evaluatorNames`: `string` ; `evaluators`: `string` ; `evaluatorsData`: [`Evaluator`](../interfaces/Evaluator.md)[] ; `goals`: `string` ; `goalsData`: [`Goal`](../interfaces/Goal.md)[] ; `lore`: `string` ; `loreData`: [`Memory`](../interfaces/Memory.md)[] ; `providers`: `string` ; `recentFacts`: `string` ; `recentFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `recentMessages`: `string` ; `recentMessagesData`: [`Memory`](../interfaces/Memory.md)[] ; `relevantFacts`: `string` ; `relevantFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `room_id`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `senderName`: `undefined` \| `string` ; `userIds`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] }\>
▸ **composeState**(`message`): `Promise`\<\{ `actionConditions`: `string` ; `actionExamples`: `string` ; `actionNames`: `string` ; `actions`: `string` ; `actors`: `string` ; `actorsData`: [`Actor`](../interfaces/Actor.md)[] ; `agentId`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `agentName`: `undefined` \| `string` ; `evaluatorConditions`: `string` ; `evaluatorExamples`: `string` ; `evaluatorNames`: `string` ; `evaluators`: `string` ; `evaluatorsData`: [`Evaluator`](../interfaces/Evaluator.md)[] ; `goals`: `string` ; `goalsData`: [`Goal`](../interfaces/Goal.md)[] ; `lore`: `string` ; `loreData`: [`Memory`](../interfaces/Memory.md)[] ; `providers`: `string` ; `recentFacts`: `string` ; `recentFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `recentMessages`: `string` ; `recentMessagesData`: [`Memory`](../interfaces/Memory.md)[] ; `relevantFacts`: `string` ; `relevantFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `room_id`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `senderName`: `undefined` \| `string` }\>

Compose the state of the agent into an object that can be passed or used for response generation.

Expand All @@ -182,7 +191,7 @@ Compose the state of the agent into an object that can be passed or used for res

#### Returns

`Promise`\<\{ `actionConditions`: `string` ; `actionExamples`: `string` ; `actionNames`: `string` ; `actions`: `string` ; `actors`: `string` ; `actorsData`: [`Actor`](../interfaces/Actor.md)[] ; `agentId`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `agentName`: `undefined` \| `string` ; `evaluatorConditions`: `string` ; `evaluatorExamples`: `string` ; `evaluatorNames`: `string` ; `evaluators`: `string` ; `evaluatorsData`: [`Evaluator`](../interfaces/Evaluator.md)[] ; `goals`: `string` ; `goalsData`: [`Goal`](../interfaces/Goal.md)[] ; `lore`: `string` ; `loreData`: [`Memory`](../interfaces/Memory.md)[] ; `providers`: `string` ; `recentFacts`: `string` ; `recentFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `recentMessages`: `string` ; `recentMessagesData`: [`Memory`](../interfaces/Memory.md)[] ; `relevantFacts`: `string` ; `relevantFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `room_id`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `senderName`: `undefined` \| `string` ; `userIds`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\`[] }\>
`Promise`\<\{ `actionConditions`: `string` ; `actionExamples`: `string` ; `actionNames`: `string` ; `actions`: `string` ; `actors`: `string` ; `actorsData`: [`Actor`](../interfaces/Actor.md)[] ; `agentId`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `agentName`: `undefined` \| `string` ; `evaluatorConditions`: `string` ; `evaluatorExamples`: `string` ; `evaluatorNames`: `string` ; `evaluators`: `string` ; `evaluatorsData`: [`Evaluator`](../interfaces/Evaluator.md)[] ; `goals`: `string` ; `goalsData`: [`Goal`](../interfaces/Goal.md)[] ; `lore`: `string` ; `loreData`: [`Memory`](../interfaces/Memory.md)[] ; `providers`: `string` ; `recentFacts`: `string` ; `recentFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `recentMessages`: `string` ; `recentMessagesData`: [`Memory`](../interfaces/Memory.md)[] ; `relevantFacts`: `string` ; `relevantFactsData`: [`Memory`](../interfaces/Memory.md)[] ; `room_id`: \`$\{string}-$\{string}-$\{string}-$\{string}-$\{string}\` ; `senderName`: `undefined` \| `string` }\>

The state of the agent.

Expand Down Expand Up @@ -317,9 +326,9 @@ Register an evaluator to assess and guide the agent's responses.

___

### retriveCachedEmbedding
### retrieveCachedEmbedding

**retriveCachedEmbedding**(`input`): `Promise`\<``null`` \| `number`[]\>
**retrieveCachedEmbedding**(`input`): `Promise`\<``null`` \| `number`[]\>

#### Parameters

Expand Down
Loading

0 comments on commit acf5fc3

Please sign in to comment.