koishi-plugin-chatluna 1.0.0-beta.77 → 1.0.0-beta.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/chains/chain.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare class ChainMiddleware {
|
|
|
39
39
|
constructor(name: string, execute: ChainMiddlewareFunction, graph: ChatChainDependencyGraph);
|
|
40
40
|
before<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
41
41
|
after<T extends keyof ChainMiddlewareName>(name: T): this;
|
|
42
|
-
run(session: Session, options: ChainMiddlewareContext): Promise<string |
|
|
42
|
+
run(session: Session, options: ChainMiddlewareContext): Promise<string | h[] | ChainMiddlewareRunStatus | h[][]>;
|
|
43
43
|
}
|
|
44
44
|
export interface ChainMiddlewareContext {
|
|
45
45
|
config: Config;
|
|
@@ -25,7 +25,7 @@ export declare class OpenAIFunctionsAgentOutputParser extends AgentActionOutputP
|
|
|
25
25
|
lc_namespace: string[];
|
|
26
26
|
static lc_name(): string;
|
|
27
27
|
parse(text: string): Promise<AgentAction | AgentFinish>;
|
|
28
|
-
parseResult(generations: ChatGeneration[]): Promise<
|
|
28
|
+
parseResult(generations: ChatGeneration[]): Promise<AgentFinish | FunctionsAgentAction>;
|
|
29
29
|
/**
|
|
30
30
|
* Parses the output message into a FunctionsAgentAction or AgentFinish
|
|
31
31
|
* object.
|
|
@@ -346,7 +346,7 @@ var ChatInterface = class {
|
|
|
346
346
|
_vectorStoreRetrieverMemory;
|
|
347
347
|
_chatHistory;
|
|
348
348
|
_chains = {};
|
|
349
|
-
|
|
349
|
+
_errorCountsMap = {};
|
|
350
350
|
_chatCount = 0;
|
|
351
351
|
_random = new import_koishi.Random();
|
|
352
352
|
async chat(arg) {
|
|
@@ -361,11 +361,16 @@ var ChatInterface = class {
|
|
|
361
361
|
}
|
|
362
362
|
return response;
|
|
363
363
|
} catch (e) {
|
|
364
|
-
this.
|
|
365
|
-
this.
|
|
366
|
-
|
|
364
|
+
this._errorCountsMap[configMD5] = this._errorCountsMap[configMD5] ?? [];
|
|
365
|
+
const errorCountsArray = this._errorCountsMap[configMD5];
|
|
366
|
+
errorCountsArray.push(Date.now());
|
|
367
|
+
if (errorCountsArray.length > config.value.maxRetries && // 20 mins
|
|
368
|
+
checkRange(
|
|
369
|
+
errorCountsArray.splice(-config.value.maxRetries),
|
|
370
|
+
1e3 * 60 * 20
|
|
371
|
+
)) {
|
|
367
372
|
delete this._chains[configMD5];
|
|
368
|
-
delete this.
|
|
373
|
+
delete this._errorCountsMap[configMD5];
|
|
369
374
|
const service = this.ctx.chatluna.platform;
|
|
370
375
|
await service.makeConfigStatus(config.value, false);
|
|
371
376
|
}
|
|
@@ -691,6 +696,12 @@ var ChatInterface = class {
|
|
|
691
696
|
});
|
|
692
697
|
}
|
|
693
698
|
};
|
|
699
|
+
function checkRange(times, delayTime) {
|
|
700
|
+
const first = times[0];
|
|
701
|
+
const last = times[times.length - 1];
|
|
702
|
+
return last - first < delayTime;
|
|
703
|
+
}
|
|
704
|
+
__name(checkRange, "checkRange");
|
|
694
705
|
// Annotate the CommonJS export names for ESM import in node:
|
|
695
706
|
0 && (module.exports = {
|
|
696
707
|
ChatInterface
|
|
@@ -11,7 +11,7 @@ export declare class ChatInterface {
|
|
|
11
11
|
private _vectorStoreRetrieverMemory;
|
|
12
12
|
private _chatHistory;
|
|
13
13
|
private _chains;
|
|
14
|
-
private
|
|
14
|
+
private _errorCountsMap;
|
|
15
15
|
private _chatCount;
|
|
16
16
|
private _random;
|
|
17
17
|
constructor(ctx: Context, input: ChatInterfaceInput);
|
|
@@ -349,7 +349,7 @@ var ChatInterface = class {
|
|
|
349
349
|
_vectorStoreRetrieverMemory;
|
|
350
350
|
_chatHistory;
|
|
351
351
|
_chains = {};
|
|
352
|
-
|
|
352
|
+
_errorCountsMap = {};
|
|
353
353
|
_chatCount = 0;
|
|
354
354
|
_random = new Random();
|
|
355
355
|
async chat(arg) {
|
|
@@ -364,11 +364,16 @@ var ChatInterface = class {
|
|
|
364
364
|
}
|
|
365
365
|
return response;
|
|
366
366
|
} catch (e) {
|
|
367
|
-
this.
|
|
368
|
-
this.
|
|
369
|
-
|
|
367
|
+
this._errorCountsMap[configMD5] = this._errorCountsMap[configMD5] ?? [];
|
|
368
|
+
const errorCountsArray = this._errorCountsMap[configMD5];
|
|
369
|
+
errorCountsArray.push(Date.now());
|
|
370
|
+
if (errorCountsArray.length > config.value.maxRetries && // 20 mins
|
|
371
|
+
checkRange(
|
|
372
|
+
errorCountsArray.splice(-config.value.maxRetries),
|
|
373
|
+
1e3 * 60 * 20
|
|
374
|
+
)) {
|
|
370
375
|
delete this._chains[configMD5];
|
|
371
|
-
delete this.
|
|
376
|
+
delete this._errorCountsMap[configMD5];
|
|
372
377
|
const service = this.ctx.chatluna.platform;
|
|
373
378
|
await service.makeConfigStatus(config.value, false);
|
|
374
379
|
}
|
|
@@ -694,6 +699,12 @@ var ChatInterface = class {
|
|
|
694
699
|
});
|
|
695
700
|
}
|
|
696
701
|
};
|
|
702
|
+
function checkRange(times, delayTime) {
|
|
703
|
+
const first = times[0];
|
|
704
|
+
const last = times[times.length - 1];
|
|
705
|
+
return last - first < delayTime;
|
|
706
|
+
}
|
|
707
|
+
__name(checkRange, "checkRange");
|
|
697
708
|
export {
|
|
698
709
|
ChatInterface
|
|
699
710
|
};
|