Skip to content

Commit

Permalink
Merge pull request #68 from JoinTheAlliance/custom-fetch
Browse files Browse the repository at this point in the history
Custom fetch
  • Loading branch information
lalalune authored Mar 21, 2024
2 parents e679b8f + 49e326a commit 6cdf398
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 6 deletions.
60 changes: 60 additions & 0 deletions docs/docs/classes/BgentRuntime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/classes/SupabaseDatabaseAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ custom_edit_url: null

[DatabaseAdapter](DatabaseAdapter.md).[constructor](DatabaseAdapter.md#constructor)

## Properties

### supabase

**supabase**: `default`\<`any`, ``"public"``, `any`\>

## Methods

### addParticipantToRoom
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/functions/formatGoalsAsString.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sidebar_position: 0
custom_edit_url: null
---

**formatGoalsAsString**(`«destructured»`): `Promise`\<`string`\>
**formatGoalsAsString**(`«destructured»`): `string`

#### Parameters

Expand All @@ -17,4 +17,4 @@ custom_edit_url: null

#### Returns

`Promise`\<`string`\>
`string`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bgent",
"version": "0.1.8",
"version": "0.1.9",
"private": false,
"description": "bgent. because agent was taken.",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adapters/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 11 additions & 2 deletions src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export class BgentRuntime {
*/
embeddingModel = "text-embedding-3-small";

/**
* Fetch function to use
* Some environments may not have access to the global fetch function and need a custom fetch override.
*/
fetch = fetch;

/**
* Store messages that are sent and received by the agent.
*/
Expand Down Expand Up @@ -142,6 +148,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
Expand All @@ -155,12 +162,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");
Expand Down Expand Up @@ -257,7 +266,7 @@ export class BgentRuntime {
};

try {
const response = await fetch(
const response = await this.fetch(
`${this.serverUrl}/chat/completions`,
requestOptions,
);
Expand Down Expand Up @@ -312,7 +321,7 @@ export class BgentRuntime {
}),
};
try {
const response = await fetch(
const response = await this.fetch(
`${this.serverUrl}/embeddings`,
requestOptions,
);
Expand Down

0 comments on commit 6cdf398

Please sign in to comment.