ctod 0.1.5 → 0.2.0
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/README-TW.md +11 -5
- package/README.md +11 -5
- package/dist/index.js +1 -1
- package/examples/applications/bbc-news-reader.ts +1 -1
- package/examples/applications/cosplay.ts +6 -3
- package/examples/applications/story-generations.ts +2 -2
- package/lib/broker/3.ts +1 -1
- package/lib/broker/35.ts +1 -1
- package/lib/broker/4.ts +207 -0
- package/lib/broker/index.ts +10 -7
- package/lib/core/plugin.ts +45 -3
- package/lib/index.ts +10 -0
- package/lib/plugins/limiter.ts +53 -1
- package/lib/plugins/print-log.ts +40 -1
- package/lib/plugins/retry.ts +30 -1
- package/lib/plugins/role.ts +32 -3
- package/lib/service/chatgpt35.ts +3 -3
- package/lib/service/chatgpt4.ts +137 -0
- package/package.json +1 -1
- package/types/lib/broker/3.d.ts +1 -1
- package/types/lib/broker/35.d.ts +1 -1
- package/types/lib/broker/4.d.ts +86 -0
- package/types/lib/broker/index.d.ts +8 -7
- package/types/lib/core/plugin.d.ts +30 -0
- package/types/lib/index.d.ts +10 -0
- package/types/lib/plugins/index.d.ts +11 -0
- package/types/lib/plugins/limiter.d.ts +6 -1
- package/types/lib/plugins/print-log.d.ts +8 -1
- package/types/lib/plugins/retry.d.ts +9 -1
- package/types/lib/plugins/role.d.ts +8 -1
- package/types/lib/service/chatgpt35.d.ts +3 -3
- package/types/lib/service/chatgpt4.d.ts +89 -0
package/types/lib/index.d.ts
CHANGED
|
@@ -6,25 +6,32 @@ import { ValidateCallback } from './utils/validate';
|
|
|
6
6
|
import { TextParser as _TextParser } from './core/parser';
|
|
7
7
|
import { ChatGPT3 as _ChatGPT3 } from './service/chatgpt3';
|
|
8
8
|
import { ChatGPT35 as _ChatGPT35 } from './service/chatgpt35';
|
|
9
|
+
import { ChatGPT4 as _ChatGPT4 } from './service/chatgpt4';
|
|
9
10
|
import { ChatGPT3Broker as _ChatGPT3Broker } from './broker/3';
|
|
10
11
|
import { ChatGPT35Broker as _ChatGPT35Broker } from './broker/35';
|
|
12
|
+
import { ChatGPT4Broker as _ChatGPT4Broker } from './broker/4';
|
|
11
13
|
import { ImagesGenerations as _ImagesGenerations } from './service/images-generations';
|
|
12
14
|
export declare type TextParser = _TextParser;
|
|
13
15
|
export declare type Translator<S extends ValidateCallback<any>, O extends ValidateCallback<any>> = _Translator.Translator<S, O>;
|
|
14
16
|
export declare type TranslatorParams<S extends ValidateCallback<any>, O extends ValidateCallback<any>> = _Translator.TranslatorParams<S, O>;
|
|
15
17
|
export declare type ChatGPT3Broker<S extends ValidateCallback<any>, O extends ValidateCallback<any>> = _ChatGPT3Broker<S, O, any, any>;
|
|
16
18
|
export declare type ChatGPT35Broker<S extends ValidateCallback<any>, O extends ValidateCallback<any>> = _ChatGPT35Broker<S, O, any, any>;
|
|
19
|
+
export declare type ChatGPT4Broker<S extends ValidateCallback<any>, O extends ValidateCallback<any>> = _ChatGPT35Broker<S, O, any, any>;
|
|
17
20
|
export declare type Broker3Plugin<T extends ValidateCallback<any>, R extends ValidateCallback<any>> = _Plugins.Broker3Plugin<T, R>;
|
|
18
21
|
export declare type Broker35Plugin<T extends ValidateCallback<any>, R extends ValidateCallback<any>> = _Plugins.Broker35Plugin<T, R>;
|
|
22
|
+
export declare type Broker4Plugin<T extends ValidateCallback<any>, R extends ValidateCallback<any>> = _Plugins.Broker35Plugin<T, R>;
|
|
19
23
|
export declare type ImagesGenerations = _ImagesGenerations;
|
|
20
24
|
export declare const TextParser: typeof _TextParser;
|
|
21
25
|
export declare const Translator: typeof _Translator.Translator;
|
|
22
26
|
export declare const ChatGPT3: typeof _ChatGPT3;
|
|
23
27
|
export declare const ChatGPT35: typeof _ChatGPT35;
|
|
28
|
+
export declare const ChatGPT4: typeof _ChatGPT4;
|
|
24
29
|
export declare const ChatGPT3Broker: typeof _ChatGPT3Broker;
|
|
25
30
|
export declare const ChatGPT35Broker: typeof _ChatGPT35Broker;
|
|
31
|
+
export declare const ChatGPT4Broker: typeof _ChatGPT4Broker;
|
|
26
32
|
export declare const Broker3Plugin: typeof _Plugins.Broker3Plugin;
|
|
27
33
|
export declare const Broker35Plugin: typeof _Plugins.Broker35Plugin;
|
|
34
|
+
export declare const Broker4Plugin: typeof _Plugins.Broker35Plugin;
|
|
28
35
|
export declare const ImagesGenerations: typeof _ImagesGenerations;
|
|
29
36
|
export declare const plugins: typeof _plugins;
|
|
30
37
|
export declare const templates: typeof _templates;
|
|
@@ -33,12 +40,15 @@ export declare const ctod: {
|
|
|
33
40
|
templates: typeof _templates;
|
|
34
41
|
ChatGPT3: typeof _ChatGPT3;
|
|
35
42
|
ChatGPT35: typeof _ChatGPT35;
|
|
43
|
+
ChatGPT4: typeof _ChatGPT4;
|
|
36
44
|
Translator: typeof _Translator.Translator;
|
|
37
45
|
TextParser: typeof _TextParser;
|
|
38
46
|
Broker3Plugin: typeof _Plugins.Broker3Plugin;
|
|
39
47
|
Broker35Plugin: typeof _Plugins.Broker35Plugin;
|
|
48
|
+
Broker4Plugin: typeof _Plugins.Broker35Plugin;
|
|
40
49
|
ChatGPT3Broker: typeof _ChatGPT3Broker;
|
|
41
50
|
ChatGPT35Broker: typeof _ChatGPT35Broker;
|
|
51
|
+
ChatGPT4Broker: typeof _ChatGPT4Broker;
|
|
42
52
|
ImagesGenerations: typeof _ImagesGenerations;
|
|
43
53
|
};
|
|
44
54
|
export default ctod;
|
|
@@ -7,6 +7,9 @@ export declare const PrintLogPlugin: {
|
|
|
7
7
|
ver35: import("../core/plugin").Broker35Plugin<(yup: typeof import("yup")) => {
|
|
8
8
|
detail: import("yup").BooleanSchema<boolean, import("yup").AnyObject, false, "d">;
|
|
9
9
|
}, () => {}>;
|
|
10
|
+
ver4: import("../core/plugin").Broker4Plugin<(yup: typeof import("yup")) => {
|
|
11
|
+
detail: import("yup").BooleanSchema<boolean, import("yup").AnyObject, false, "d">;
|
|
12
|
+
}, () => {}>;
|
|
10
13
|
};
|
|
11
14
|
/**
|
|
12
15
|
* @zh 當解析失敗時,會自動重試的對話。
|
|
@@ -17,6 +20,10 @@ export declare const RetryPlugin: {
|
|
|
17
20
|
retry: import("yup").NumberSchema<number, import("yup").AnyObject, 1, "d">;
|
|
18
21
|
printWarn: import("yup").BooleanSchema<boolean, import("yup").AnyObject, true, "d">;
|
|
19
22
|
}, () => {}>;
|
|
23
|
+
ver4: import("../core/plugin").Broker4Plugin<(yup: typeof import("yup")) => {
|
|
24
|
+
retry: import("yup").NumberSchema<number, import("yup").AnyObject, 1, "d">;
|
|
25
|
+
printWarn: import("yup").BooleanSchema<boolean, import("yup").AnyObject, true, "d">;
|
|
26
|
+
}, () => {}>;
|
|
20
27
|
};
|
|
21
28
|
/**
|
|
22
29
|
* @zh 限制使用流量,這個 plugin 可以有效讓所有對話不會再限制內同時發送,可用於在開發過程中遭遇伺服器因頻率過高而阻擋請求。
|
|
@@ -37,6 +44,7 @@ export declare const LimiterPlugin: {
|
|
|
37
44
|
};
|
|
38
45
|
closeSchedule: () => void;
|
|
39
46
|
ver35: import("../core/plugin").Broker35Plugin<() => {}, () => {}>;
|
|
47
|
+
ver4: import("../core/plugin").Broker4Plugin<() => {}, () => {}>;
|
|
40
48
|
};
|
|
41
49
|
/**
|
|
42
50
|
* @zh 設定角色扮演。
|
|
@@ -46,4 +54,7 @@ export declare const RolePlugin: {
|
|
|
46
54
|
ver35: import("../core/plugin").Broker35Plugin<(yup: typeof import("yup")) => {
|
|
47
55
|
role: import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
48
56
|
}, () => {}>;
|
|
57
|
+
ver4: import("../core/plugin").Broker4Plugin<(yup: typeof import("yup")) => {
|
|
58
|
+
role: import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
59
|
+
}, () => {}>;
|
|
49
60
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Broker35Plugin } from '../core/plugin';
|
|
1
|
+
import { Broker35Plugin, Broker4Plugin } from '../core/plugin';
|
|
2
2
|
declare type Events = {
|
|
3
3
|
run: {
|
|
4
4
|
id: string;
|
|
@@ -31,5 +31,10 @@ declare const _default: {
|
|
|
31
31
|
* @en The version for Broker35.
|
|
32
32
|
*/
|
|
33
33
|
ver35: Broker35Plugin<() => {}, () => {}>;
|
|
34
|
+
/**
|
|
35
|
+
* @zh 用於 Broker4 的版本。
|
|
36
|
+
* @en The version for Broker4.
|
|
37
|
+
*/
|
|
38
|
+
ver4: Broker4Plugin<() => {}, () => {}>;
|
|
34
39
|
};
|
|
35
40
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Broker35Plugin, Broker3Plugin } from '../core/plugin';
|
|
1
|
+
import { Broker35Plugin, Broker3Plugin, Broker4Plugin } from '../core/plugin';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
/**
|
|
4
4
|
* @zh 用於 Broker3 的版本。
|
|
@@ -12,5 +12,12 @@ declare const _default: {
|
|
|
12
12
|
ver35: Broker35Plugin<(yup: typeof import("yup")) => {
|
|
13
13
|
detail: import("yup").BooleanSchema<boolean, import("yup").AnyObject, false, "d">;
|
|
14
14
|
}, () => {}>;
|
|
15
|
+
/**
|
|
16
|
+
* @zh 用於 Broker4 的版本。
|
|
17
|
+
* @en The version for Broker4.
|
|
18
|
+
*/
|
|
19
|
+
ver4: Broker4Plugin<(yup: typeof import("yup")) => {
|
|
20
|
+
detail: import("yup").BooleanSchema<boolean, import("yup").AnyObject, false, "d">;
|
|
21
|
+
}, () => {}>;
|
|
15
22
|
};
|
|
16
23
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Broker35Plugin } from '../core/plugin';
|
|
1
|
+
import { Broker35Plugin, Broker4Plugin } from '../core/plugin';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
/**
|
|
4
4
|
* @zh 用於 Broker35 的版本。
|
|
@@ -8,5 +8,13 @@ declare const _default: {
|
|
|
8
8
|
retry: import("yup").NumberSchema<number, import("yup").AnyObject, 1, "d">;
|
|
9
9
|
printWarn: import("yup").BooleanSchema<boolean, import("yup").AnyObject, true, "d">;
|
|
10
10
|
}, () => {}>;
|
|
11
|
+
/**
|
|
12
|
+
* @zh 用於 Broker4 的版本。
|
|
13
|
+
* @en The version for Broker4.
|
|
14
|
+
*/
|
|
15
|
+
ver4: Broker4Plugin<(yup: typeof import("yup")) => {
|
|
16
|
+
retry: import("yup").NumberSchema<number, import("yup").AnyObject, 1, "d">;
|
|
17
|
+
printWarn: import("yup").BooleanSchema<boolean, import("yup").AnyObject, true, "d">;
|
|
18
|
+
}, () => {}>;
|
|
11
19
|
};
|
|
12
20
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Broker35Plugin } from '../core/plugin';
|
|
1
|
+
import { Broker35Plugin, Broker4Plugin } from '../core/plugin';
|
|
2
2
|
declare const _default: {
|
|
3
3
|
/**
|
|
4
4
|
* @zh 用於 Broker35 的版本。
|
|
@@ -7,5 +7,12 @@ declare const _default: {
|
|
|
7
7
|
ver35: Broker35Plugin<(yup: typeof import("yup")) => {
|
|
8
8
|
role: import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
9
9
|
}, () => {}>;
|
|
10
|
+
/**
|
|
11
|
+
* @zh 用於 Broker4 的版本。
|
|
12
|
+
* @en The version for Broker4.
|
|
13
|
+
*/
|
|
14
|
+
ver4: Broker4Plugin<(yup: typeof import("yup")) => {
|
|
15
|
+
role: import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
16
|
+
}, () => {}>;
|
|
10
17
|
};
|
|
11
18
|
export default _default;
|
|
@@ -42,9 +42,9 @@ declare type Config = {
|
|
|
42
42
|
temperature: number;
|
|
43
43
|
};
|
|
44
44
|
export declare class ChatGPT35 {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
axios: AxiosInstance;
|
|
46
|
+
apiKey: string;
|
|
47
|
+
config: Config;
|
|
48
48
|
/**
|
|
49
49
|
* @zh 如果你有需要特別設定 axios,請使用這方法
|
|
50
50
|
* @en If you need to set axios, use this method
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { PromiseResponseType } from '../types';
|
|
3
|
+
export declare type ChatGPT4Message = {
|
|
4
|
+
role: 'system' | 'user' | 'assistant';
|
|
5
|
+
name?: string;
|
|
6
|
+
content: string;
|
|
7
|
+
};
|
|
8
|
+
declare type ApiResponse = {
|
|
9
|
+
id: string;
|
|
10
|
+
object: string;
|
|
11
|
+
created: number;
|
|
12
|
+
choices: Array<{
|
|
13
|
+
index: number;
|
|
14
|
+
finish_reason: string;
|
|
15
|
+
message: {
|
|
16
|
+
role: 'system' | 'user' | 'assistant';
|
|
17
|
+
name?: string;
|
|
18
|
+
content: string;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
usage: {
|
|
22
|
+
prompt_tokens: number;
|
|
23
|
+
completion_tokens: number;
|
|
24
|
+
total_tokens: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
declare type Config = {
|
|
28
|
+
/**
|
|
29
|
+
* @zh 一次回應數量
|
|
30
|
+
* @en How many chat completion choices to generate for each input message.
|
|
31
|
+
*/
|
|
32
|
+
n: number;
|
|
33
|
+
/**
|
|
34
|
+
* @zh 選擇運行的模型,32k意味著能處理長度為 32768 的文本,而預設為 8192。
|
|
35
|
+
* @en How many chat completion choices to generate for each input message.
|
|
36
|
+
*/
|
|
37
|
+
model: 'gpt-4' | 'gpt-4-32k';
|
|
38
|
+
/**
|
|
39
|
+
* @zh 冒險指數,數值由 0 ~ 2 之間。
|
|
40
|
+
* @en What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
|
|
41
|
+
*/
|
|
42
|
+
temperature: number;
|
|
43
|
+
};
|
|
44
|
+
export declare class ChatGPT4 {
|
|
45
|
+
axios: AxiosInstance;
|
|
46
|
+
apiKey: string;
|
|
47
|
+
config: Config;
|
|
48
|
+
/**
|
|
49
|
+
* @zh 如果你有需要特別設定 axios,請使用這方法
|
|
50
|
+
* @en If you need to set axios, use this method
|
|
51
|
+
*/
|
|
52
|
+
setAxios(axios: AxiosInstance): void;
|
|
53
|
+
/**
|
|
54
|
+
* @zh 設定 api key
|
|
55
|
+
* @en Set api key
|
|
56
|
+
*/
|
|
57
|
+
setConfiguration(apiKey: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* @zh 改變對話的一些設定
|
|
60
|
+
* @en Change some settings of the conversation
|
|
61
|
+
*/
|
|
62
|
+
setConfig(options: Partial<Config>): void;
|
|
63
|
+
/**
|
|
64
|
+
* @zh 進行對話
|
|
65
|
+
* @en Talk to the AI
|
|
66
|
+
*/
|
|
67
|
+
talk(messages?: ChatGPT4Message[]): Promise<{
|
|
68
|
+
id: string;
|
|
69
|
+
text: string;
|
|
70
|
+
isDone: boolean;
|
|
71
|
+
newMessages: ChatGPT4Message[];
|
|
72
|
+
apiReseponse: ApiResponse;
|
|
73
|
+
}>;
|
|
74
|
+
/**
|
|
75
|
+
* @zh 開啟持續性對話
|
|
76
|
+
*/
|
|
77
|
+
chat(prompt: string | string[], oldMessages?: ChatGPT4Message[]): Promise<{
|
|
78
|
+
result: {
|
|
79
|
+
id: string;
|
|
80
|
+
text: string;
|
|
81
|
+
isDone: boolean;
|
|
82
|
+
newMessages: ChatGPT4Message[];
|
|
83
|
+
apiReseponse: ApiResponse;
|
|
84
|
+
};
|
|
85
|
+
nextTalk: (prompt: string | string[]) => Promise<any>;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
export declare type ChatGPT4TalkResponse = PromiseResponseType<ChatGPT4['talk']>;
|
|
89
|
+
export {};
|