From afaf14781b02a09085a44f8a8071cd3385ab784c Mon Sep 17 00:00:00 2001 From: moon Date: Thu, 21 Mar 2024 02:22:37 -0700 Subject: [PATCH 1/3] expose supabase --- src/lib/adapters/supabase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/adapters/supabase.ts b/src/lib/adapters/supabase.ts index 01bcbe5..9dbebb8 100644 --- a/src/lib/adapters/supabase.ts +++ b/src/lib/adapters/supabase.ts @@ -12,7 +12,7 @@ import { import { DatabaseAdapter } from "../database"; export class SupabaseDatabaseAdapter extends DatabaseAdapter { - private supabase: SupabaseClient; + supabase: SupabaseClient; constructor(supabaseUrl: string, supabaseKey: string) { super(); From 56bf8237aff5365cc6f213dfa070d032cf7b7110 Mon Sep 17 00:00:00 2001 From: moon Date: Thu, 21 Mar 2024 14:21:20 -0700 Subject: [PATCH 2/3] Add custom fetch --- package.json | 2 +- src/lib/runtime.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bb17d20..874df05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bgent", - "version": "0.1.8", + "version": "0.1.9", "private": false, "description": "bgent. because agent was taken.", "type": "module", diff --git a/src/lib/runtime.ts b/src/lib/runtime.ts index fdc22e6..3ae6781 100644 --- a/src/lib/runtime.ts +++ b/src/lib/runtime.ts @@ -96,6 +96,11 @@ export class BgentRuntime { */ embeddingModel = "text-embedding-3-small"; + /** + * Use a custom fetch + */ + fetch = fetch; + /** * Store messages that are sent and received by the agent. */ @@ -142,6 +147,7 @@ export class BgentRuntime { * @param opts.embeddingModel - The model to use for embedding. * @param opts.agentId - Optional ID of the agent. * @param opts.databaseAdapter - The database adapter used for interacting with the database. + * @param opts.fetch - Custom fetch function to use for making requests. */ constructor(opts: { recentMessageCount?: number; // number of messages to hold in the recent message cache @@ -155,12 +161,14 @@ export class BgentRuntime { model?: string; // The model to use for completion embeddingModel?: string; // The model to use for embedding databaseAdapter: DatabaseAdapter; // The database adapter used for interacting with the database + fetch?: typeof fetch | unknown; }) { this.#recentMessageCount = opts.recentMessageCount ?? this.#recentMessageCount; this.debugMode = opts.debugMode ?? false; this.databaseAdapter = opts.databaseAdapter; this.agentId = opts.agentId ?? zeroUuid; + this.fetch = (opts.fetch as typeof fetch) ?? this.fetch; if (!opts.databaseAdapter) { throw new Error("No database adapter provided"); @@ -257,7 +265,7 @@ export class BgentRuntime { }; try { - const response = await fetch( + const response = await this.fetch( `${this.serverUrl}/chat/completions`, requestOptions, ); @@ -312,7 +320,7 @@ export class BgentRuntime { }), }; try { - const response = await fetch( + const response = await this.fetch( `${this.serverUrl}/embeddings`, requestOptions, ); From 49e326a14f8cecb8f10f2fa17943d6291648d239 Mon Sep 17 00:00:00 2001 From: moon Date: Thu, 21 Mar 2024 14:22:36 -0700 Subject: [PATCH 3/3] Update documentation --- docs/docs/classes/BgentRuntime.md | 60 ++++++++++++++++++++ docs/docs/classes/SupabaseDatabaseAdapter.md | 6 ++ docs/docs/functions/formatGoalsAsString.md | 4 +- src/lib/runtime.ts | 3 +- 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/docs/docs/classes/BgentRuntime.md b/docs/docs/classes/BgentRuntime.md index 738c943..e1073f1 100644 --- a/docs/docs/classes/BgentRuntime.md +++ b/docs/docs/classes/BgentRuntime.md @@ -28,6 +28,7 @@ Creates an instance of BgentRuntime. | `opts.debugMode?` | `boolean` | If true, debug messages will be logged. | | `opts.embeddingModel?` | `string` | The model to use for embedding. | | `opts.evaluators?` | [`Evaluator`](../interfaces/Evaluator.md)[] | Optional custom evaluators. | +| `opts.fetch?` | `unknown` | Custom fetch function to use for making requests. | | `opts.model?` | `string` | The model to use for completion. | | `opts.providers?` | [`Provider`](../interfaces/Provider.md)[] | Optional context providers. | | `opts.recentMessageCount?` | `number` | The number of messages to hold in the recent message cache. | @@ -104,6 +105,65 @@ Manage the fact and recall of facts. ___ +### fetch + +• **fetch**: (`input`: `RequestInfo` \| `URL`, `init?`: `RequestInit`\<`CfProperties`\<`unknown`\>\>) => `Promise`\<`Response`\>(`input`: `RequestInfo`, `init?`: `RequestInit`\<`CfProperties`\<`unknown`\>\>) => `Promise`\<`Response`\>(`input`: `RequestInfo`, `init?`: `RequestInit`\<`RequestInitCfProperties`\>) => `Promise`\<`Response`\> = `fetch` + +Fetch function to use +Some environments may not have access to the global fetch function and need a custom fetch override. + +#### Type declaration + +▸ (`input`, `init?`): `Promise`\<`Response`\> + +Fetch function to use +Some environments may not have access to the global fetch function and need a custom fetch override. + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `input` | `RequestInfo` \| `URL` | +| `init?` | `RequestInit`\<`CfProperties`\<`unknown`\>\> | + +##### Returns + +`Promise`\<`Response`\> + +▸ (`input`, `init?`): `Promise`\<`Response`\> + +Fetch function to use +Some environments may not have access to the global fetch function and need a custom fetch override. + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `input` | `RequestInfo` | +| `init?` | `RequestInit`\<`CfProperties`\<`unknown`\>\> | + +##### Returns + +`Promise`\<`Response`\> + +▸ (`input`, `init?`): `Promise`\<`Response`\> + +Fetch function to use +Some environments may not have access to the global fetch function and need a custom fetch override. + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `input` | `RequestInfo` | +| `init?` | `RequestInit`\<`RequestInitCfProperties`\> | + +##### Returns + +`Promise`\<`Response`\> + +___ + ### loreManager • **loreManager**: [`MemoryManager`](MemoryManager.md) diff --git a/docs/docs/classes/SupabaseDatabaseAdapter.md b/docs/docs/classes/SupabaseDatabaseAdapter.md index d0a7d1c..88e8982 100644 --- a/docs/docs/classes/SupabaseDatabaseAdapter.md +++ b/docs/docs/classes/SupabaseDatabaseAdapter.md @@ -33,6 +33,12 @@ custom_edit_url: null [DatabaseAdapter](DatabaseAdapter.md).[constructor](DatabaseAdapter.md#constructor) +## Properties + +### supabase + +• **supabase**: `default`\<`any`, ``"public"``, `any`\> + ## Methods ### addParticipantToRoom diff --git a/docs/docs/functions/formatGoalsAsString.md b/docs/docs/functions/formatGoalsAsString.md index 84f0bbc..dd1c2da 100644 --- a/docs/docs/functions/formatGoalsAsString.md +++ b/docs/docs/functions/formatGoalsAsString.md @@ -6,7 +6,7 @@ sidebar_position: 0 custom_edit_url: null --- -▸ **formatGoalsAsString**(`«destructured»`): `Promise`\<`string`\> +▸ **formatGoalsAsString**(`«destructured»`): `string` #### Parameters @@ -17,4 +17,4 @@ custom_edit_url: null #### Returns -`Promise`\<`string`\> +`string` diff --git a/src/lib/runtime.ts b/src/lib/runtime.ts index 3ae6781..f0a54c7 100644 --- a/src/lib/runtime.ts +++ b/src/lib/runtime.ts @@ -97,7 +97,8 @@ export class BgentRuntime { embeddingModel = "text-embedding-3-small"; /** - * Use a custom fetch + * Fetch function to use + * Some environments may not have access to the global fetch function and need a custom fetch override. */ fetch = fetch;