koishi-plugin-chatluna 1.1.1 → 1.1.2
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.
|
@@ -2,8 +2,8 @@ import { BaseMessage } from '@langchain/core/messages';
|
|
|
2
2
|
import { RunnableSequence } from '@langchain/core/runnables';
|
|
3
3
|
import { StructuredTool } from '@langchain/core/tools';
|
|
4
4
|
import { AgentAction, AgentFinish, AgentStep } from '@langchain/core/agents';
|
|
5
|
-
import { ChatLunaChatPrompt } from 'koishi-plugin-chatluna/llm-core/chain/prompt';
|
|
6
5
|
import type { ChatLunaChatModel } from '../../platform/model';
|
|
6
|
+
import { BaseChatPromptTemplate } from '@langchain/core/prompts';
|
|
7
7
|
export declare function _formatIntermediateSteps(intermediateSteps: AgentStep[]): BaseMessage[];
|
|
8
8
|
/**
|
|
9
9
|
* Params used by the createOpenAIFunctionsAgent function.
|
|
@@ -18,8 +18,8 @@ export type CreateOpenAIAgentParams = {
|
|
|
18
18
|
/** Tools this agent has access to. */
|
|
19
19
|
tools: StructuredTool[];
|
|
20
20
|
/** The prompt to use, must have an input key for `agent_scratchpad`. */
|
|
21
|
-
prompt:
|
|
21
|
+
prompt: BaseChatPromptTemplate;
|
|
22
22
|
};
|
|
23
23
|
export declare function createOpenAIAgent({ llm, tools, prompt }: CreateOpenAIAgentParams): RunnableSequence<{
|
|
24
24
|
steps: AgentStep[];
|
|
25
|
-
}, AgentAction |
|
|
25
|
+
}, AgentAction | AgentAction[] | AgentFinish>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ToolInterface } from '@langchain/core/tools';
|
|
2
|
+
import { BasePromptTemplate } from '@langchain/core/prompts';
|
|
2
3
|
import { AgentStep } from '@langchain/core/agents';
|
|
3
4
|
import { AgentRunnableSequence } from 'koishi-plugin-chatluna/llm-core/agent';
|
|
4
|
-
import { ChatLunaChatPrompt } from 'koishi-plugin-chatluna/llm-core/chain/prompt';
|
|
5
5
|
import type { ChatLunaChatModel } from '../../platform/model';
|
|
6
6
|
/**
|
|
7
7
|
* Params used by the createXmlAgent function.
|
|
@@ -15,7 +15,7 @@ export type CreateReactAgentParams = {
|
|
|
15
15
|
* The prompt to use. Must have input keys for
|
|
16
16
|
* `tools`, `tool_names`, and `agent_scratchpad`.
|
|
17
17
|
*/
|
|
18
|
-
prompt:
|
|
18
|
+
prompt: BasePromptTemplate;
|
|
19
19
|
/**
|
|
20
20
|
* Whether to invoke the underlying model in streaming mode,
|
|
21
21
|
* allowing streaming of intermediate steps. Defaults to true.
|
|
@@ -574,49 +574,60 @@ var ChatLunaEmbeddings = class extends ChatHubBaseEmbeddings {
|
|
|
574
574
|
}
|
|
575
575
|
return data;
|
|
576
576
|
}
|
|
577
|
-
_embeddingWithRetry(request) {
|
|
577
|
+
async _embeddingWithRetry(request) {
|
|
578
578
|
request.timeout = request.timeout ?? this.timeout;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
579
|
+
try {
|
|
580
|
+
return await this.caller.call(
|
|
581
|
+
(request2) => {
|
|
582
|
+
return Promise.race([
|
|
583
|
+
new Promise((resolve, reject) => {
|
|
584
|
+
setTimeout(() => {
|
|
585
|
+
reject(
|
|
586
|
+
Error(
|
|
587
|
+
`timeout when calling ${this.modelName} embeddings`
|
|
588
|
+
)
|
|
589
|
+
);
|
|
590
|
+
}, request2.timeout);
|
|
591
|
+
}),
|
|
592
|
+
new Promise(
|
|
593
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
594
|
+
async (resolve, reject) => {
|
|
595
|
+
let data;
|
|
596
|
+
try {
|
|
597
|
+
data = await this._client.embeddings(request2);
|
|
598
|
+
} catch (e) {
|
|
599
|
+
if (e instanceof import_error.ChatLunaError) {
|
|
600
|
+
reject(e);
|
|
601
|
+
} else {
|
|
602
|
+
reject(
|
|
603
|
+
new import_error.ChatLunaError(
|
|
604
|
+
import_error.ChatLunaErrorCode.API_REQUEST_FAILED,
|
|
605
|
+
e
|
|
606
|
+
)
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
if (data) {
|
|
611
|
+
resolve(data);
|
|
612
|
+
}
|
|
613
|
+
reject(
|
|
614
|
+
Error(
|
|
615
|
+
`error when calling ${this.modelName} embeddings, Result: ` + JSON.stringify(data)
|
|
616
|
+
)
|
|
617
|
+
);
|
|
618
|
+
}
|
|
586
619
|
)
|
|
587
|
-
);
|
|
620
|
+
]);
|
|
588
621
|
},
|
|
589
|
-
|
|
622
|
+
request
|
|
590
623
|
);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
} else {
|
|
599
|
-
reject(
|
|
600
|
-
new import_error.ChatLunaError(
|
|
601
|
-
import_error.ChatLunaErrorCode.API_REQUEST_FAILED,
|
|
602
|
-
e
|
|
603
|
-
)
|
|
604
|
-
);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
clearTimeout(timeout);
|
|
608
|
-
if (data) {
|
|
609
|
-
resolve(data);
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
reject(
|
|
613
|
-
Error(
|
|
614
|
-
`error when calling ${this.modelName} embeddings, Result: ` + JSON.stringify(data)
|
|
615
|
-
)
|
|
616
|
-
);
|
|
617
|
-
});
|
|
618
|
-
return promise;
|
|
619
|
-
}, request);
|
|
624
|
+
} catch (e) {
|
|
625
|
+
if (e instanceof import_error.ChatLunaError) {
|
|
626
|
+
throw new import_error.ChatLunaError(import_error.ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
627
|
+
} else {
|
|
628
|
+
throw new import_error.ChatLunaError(import_error.ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
620
631
|
}
|
|
621
632
|
};
|
|
622
633
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -556,49 +556,60 @@ var ChatLunaEmbeddings = class extends ChatHubBaseEmbeddings {
|
|
|
556
556
|
}
|
|
557
557
|
return data;
|
|
558
558
|
}
|
|
559
|
-
_embeddingWithRetry(request) {
|
|
559
|
+
async _embeddingWithRetry(request) {
|
|
560
560
|
request.timeout = request.timeout ?? this.timeout;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
561
|
+
try {
|
|
562
|
+
return await this.caller.call(
|
|
563
|
+
(request2) => {
|
|
564
|
+
return Promise.race([
|
|
565
|
+
new Promise((resolve, reject) => {
|
|
566
|
+
setTimeout(() => {
|
|
567
|
+
reject(
|
|
568
|
+
Error(
|
|
569
|
+
`timeout when calling ${this.modelName} embeddings`
|
|
570
|
+
)
|
|
571
|
+
);
|
|
572
|
+
}, request2.timeout);
|
|
573
|
+
}),
|
|
574
|
+
new Promise(
|
|
575
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
576
|
+
async (resolve, reject) => {
|
|
577
|
+
let data;
|
|
578
|
+
try {
|
|
579
|
+
data = await this._client.embeddings(request2);
|
|
580
|
+
} catch (e) {
|
|
581
|
+
if (e instanceof ChatLunaError) {
|
|
582
|
+
reject(e);
|
|
583
|
+
} else {
|
|
584
|
+
reject(
|
|
585
|
+
new ChatLunaError(
|
|
586
|
+
ChatLunaErrorCode.API_REQUEST_FAILED,
|
|
587
|
+
e
|
|
588
|
+
)
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (data) {
|
|
593
|
+
resolve(data);
|
|
594
|
+
}
|
|
595
|
+
reject(
|
|
596
|
+
Error(
|
|
597
|
+
`error when calling ${this.modelName} embeddings, Result: ` + JSON.stringify(data)
|
|
598
|
+
)
|
|
599
|
+
);
|
|
600
|
+
}
|
|
568
601
|
)
|
|
569
|
-
);
|
|
602
|
+
]);
|
|
570
603
|
},
|
|
571
|
-
|
|
604
|
+
request
|
|
572
605
|
);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
} else {
|
|
581
|
-
reject(
|
|
582
|
-
new ChatLunaError(
|
|
583
|
-
ChatLunaErrorCode.API_REQUEST_FAILED,
|
|
584
|
-
e
|
|
585
|
-
)
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
clearTimeout(timeout);
|
|
590
|
-
if (data) {
|
|
591
|
-
resolve(data);
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
reject(
|
|
595
|
-
Error(
|
|
596
|
-
`error when calling ${this.modelName} embeddings, Result: ` + JSON.stringify(data)
|
|
597
|
-
)
|
|
598
|
-
);
|
|
599
|
-
});
|
|
600
|
-
return promise;
|
|
601
|
-
}, request);
|
|
606
|
+
} catch (e) {
|
|
607
|
+
if (e instanceof ChatLunaError) {
|
|
608
|
+
throw new ChatLunaError(ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
609
|
+
} else {
|
|
610
|
+
throw new ChatLunaError(ChatLunaErrorCode.API_REQUEST_FAILED, e);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
602
613
|
}
|
|
603
614
|
};
|
|
604
615
|
export {
|