@@ -96,6 +96,11 @@ export class BgentRuntime {
96
96
*/
97
97
embeddingModel = "text-embedding-3-small" ;
98
98
99
+ /**
100
+ * Use a custom fetch
101
+ */
102
+ fetch = fetch ;
103
+
99
104
/**
100
105
* Store messages that are sent and received by the agent.
101
106
*/
@@ -142,6 +147,7 @@ export class BgentRuntime {
142
147
* @param opts.embeddingModel - The model to use for embedding.
143
148
* @param opts.agentId - Optional ID of the agent.
144
149
* @param opts.databaseAdapter - The database adapter used for interacting with the database.
150
+ * @param opts.fetch - Custom fetch function to use for making requests.
145
151
*/
146
152
constructor ( opts : {
147
153
recentMessageCount ?: number ; // number of messages to hold in the recent message cache
@@ -155,12 +161,14 @@ export class BgentRuntime {
155
161
model ?: string ; // The model to use for completion
156
162
embeddingModel ?: string ; // The model to use for embedding
157
163
databaseAdapter : DatabaseAdapter ; // The database adapter used for interacting with the database
164
+ fetch ?: typeof fetch | unknown ;
158
165
} ) {
159
166
this . #recentMessageCount =
160
167
opts . recentMessageCount ?? this . #recentMessageCount;
161
168
this . debugMode = opts . debugMode ?? false ;
162
169
this . databaseAdapter = opts . databaseAdapter ;
163
170
this . agentId = opts . agentId ?? zeroUuid ;
171
+ this . fetch = ( opts . fetch as typeof fetch ) ?? this . fetch ;
164
172
165
173
if ( ! opts . databaseAdapter ) {
166
174
throw new Error ( "No database adapter provided" ) ;
@@ -257,7 +265,7 @@ export class BgentRuntime {
257
265
} ;
258
266
259
267
try {
260
- const response = await fetch (
268
+ const response = await this . fetch (
261
269
`${ this . serverUrl } /chat/completions` ,
262
270
requestOptions ,
263
271
) ;
@@ -312,7 +320,7 @@ export class BgentRuntime {
312
320
} ) ,
313
321
} ;
314
322
try {
315
- const response = await fetch (
323
+ const response = await this . fetch (
316
324
`${ this . serverUrl } /embeddings` ,
317
325
requestOptions ,
318
326
) ;
0 commit comments