ctod 0.6.3 → 0.7.1
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/.api-key +1 -0
- package/.nyc_output/42919e68-b472-4a5d-b2d3-5d5153f28467.json +1 -0
- package/.nyc_output/processinfo/42919e68-b472-4a5d-b2d3-5d5153f28467.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.output/.output/stores//344/270/200/345/240/264/346/234/237/345/276/205/345/267/262/344/271/205/347/232/204/345/222/214/350/247/243/cover-0.png +1 -0
- package/.output/.output/stores//344/270/200/345/240/264/346/234/237/345/276/205/345/267/262/344/271/205/347/232/204/345/222/214/350/247/243/cover-1.png +1 -0
- package/.output/.output/stores//344/270/200/345/240/264/346/234/237/345/276/205/345/267/262/344/271/205/347/232/204/345/222/214/350/247/243/story-config.json +4 -0
- package/.output/.output/stores//344/270/200/345/240/264/346/234/237/345/276/205/345/267/262/344/271/205/347/232/204/345/222/214/350/247/243/story.json +22 -0
- package/.output/.output/stores//345/276/236/351/273/221/346/232/227/350/265/260/345/220/221/345/205/211/346/230/216/cover-0.png +1 -0
- package/.output/.output/stores//345/276/236/351/273/221/346/232/227/350/265/260/345/220/221/345/205/211/346/230/216/cover-1.png +1 -0
- package/.output/.output/stores//345/276/236/351/273/221/346/232/227/350/265/260/345/220/221/345/205/211/346/230/216/story-config.json +4 -0
- package/.output/.output/stores//345/276/236/351/273/221/346/232/227/350/265/260/345/220/221/345/205/211/346/230/216/story.json +24 -0
- package/.output/.output/stores//347/240/264/347/242/216/347/232/204/345/271/273/350/261/241/cover-0.png +1 -0
- package/.output/.output/stores//347/240/264/347/242/216/347/232/204/345/271/273/350/261/241/cover-1.png +1 -0
- package/.output/.output/stores//347/240/264/347/242/216/347/232/204/345/271/273/350/261/241/story-config.json +4 -0
- package/.output/.output/stores//347/240/264/347/242/216/347/232/204/345/271/273/350/261/241/story.json +24 -0
- package/.output/.output/stores//350/227/235/350/241/223/345/256/266/347/232/204/351/235/210/346/204/237/cover-0.png +1 -0
- package/.output/.output/stores//350/227/235/350/241/223/345/256/266/347/232/204/351/235/210/346/204/237/cover-1.png +1 -0
- package/.output/.output/stores//350/227/235/350/241/223/345/256/266/347/232/204/351/235/210/346/204/237/story-config.json +4 -0
- package/.output/.output/stores//350/227/235/350/241/223/345/256/266/347/232/204/351/235/210/346/204/237/story.json +28 -0
- package/.output/.output/stores//350/250/230/346/206/266/345/225/206/344/272/272/cover-0.png +1 -0
- package/.output/.output/stores//350/250/230/346/206/266/345/225/206/344/272/272/cover-1.png +1 -0
- package/.output/.output/stores//350/250/230/346/206/266/345/225/206/344/272/272/story-config.json +4 -0
- package/.output/.output/stores//350/250/230/346/206/266/345/225/206/344/272/272/story.json +18 -0
- package/.output/.output/stores//350/250/255/350/250/210/350/210/207/351/226/213/347/231/274/347/232/204/346/214/221/346/210/260/content.json +22 -0
- package/.output/.output/talks//344/273/245/347/254/221/350/251/261/347/202/272/345/237/272/347/244/216/347/232/204/351/235/242/350/251/246/content.json +30 -0
- package/.output/.output/talks//344/273/245/347/254/221/350/251/261/347/202/272/345/237/272/347/244/216/347/232/204/351/235/242/350/251/246/cover-1684055229695.png +0 -0
- package/.output/.output/talks//345/234/250/346/224/277/346/262/273/345/200/231/351/201/270/344/272/272/350/276/257/350/253/226/344/270/255/347/232/204/350/252/252/346/234/215/346/200/247/346/272/235/351/200/232/content.json +30 -0
- package/.output/.output/talks//345/234/250/346/224/277/346/262/273/345/200/231/351/201/270/344/272/272/350/276/257/350/253/226/344/270/255/347/232/204/350/252/252/346/234/215/346/200/247/346/272/235/351/200/232/cover-1684056611678.png +0 -0
- package/.output/.output/talks//346/224/276/351/254/206/347/232/204/345/200/231/351/201/270/344/272/272/351/200/262/350/241/214/346/224/277/346/262/273/350/276/257/350/253/226/content.json +36 -0
- package/.output/.output/talks//346/224/276/351/254/206/347/232/204/345/200/231/351/201/270/344/272/272/351/200/262/350/241/214/346/224/277/346/262/273/350/276/257/350/253/226/cover-1684055140609.png +0 -0
- package/.output/.output/talks//346/224/277/346/262/273/347/254/221/350/251/261/content.json +30 -0
- package/.output/.output/talks//346/224/277/346/262/273/347/254/221/350/251/261/cover-1684056246465.png +0 -0
- package/.output/.output/talks//350/251/274/350/253/247/345/256/266/351/225/267/346/225/231/345/270/253/346/234/203/350/255/260/content.json +26 -0
- package/.output/.output/talks//350/251/274/350/253/247/345/256/266/351/225/267/346/225/231/345/270/253/346/234/203/350/255/260/cover-1685785935121.png +0 -0
- package/.output/.output/talks//350/262/241/345/213/231/351/241/247/345/225/217/350/253/256/350/251/242/content.json +26 -0
- package/.output/.output/talks//350/262/241/345/213/231/351/241/247/345/225/217/350/253/256/350/251/242/cover-1685785115833.png +0 -0
- package/.output/.output/talks//351/206/253/347/224/237/345/222/214/347/227/205/344/272/272/350/250/216/350/253/226/346/202/262/345/202/267/content.json +32 -0
- package/.output/.output/talks//351/206/253/347/224/237/345/222/214/347/227/205/344/272/272/350/250/216/350/253/226/346/202/262/345/202/267/cover-1684055075942.png +0 -0
- package/README.md +87 -84
- package/dist/index.js +1 -1
- package/package.json +4 -4
- package/examples/chat-demo.ts +0 -89
- package/examples/chat-for-llama.cpp-demo.ts +0 -57
- package/examples/plugin-demo.ts +0 -110
- package/examples/stream-for-llama.cpp-demo.ts +0 -33
- package/examples/vision-demo-ex.png +0 -0
- package/examples/vision-demo.png +0 -0
- package/examples/vision-demo.ts +0 -168
- package/lib/broker/chat.ts +0 -406
- package/lib/core/parser.ts +0 -62
- package/lib/core/plugin.ts +0 -46
- package/lib/core/translator.ts +0 -111
- package/lib/index.ts +0 -38
- package/lib/plugins/index.ts +0 -38
- package/lib/plugins/limiter.ts +0 -103
- package/lib/plugins/print-log.ts +0 -35
- package/lib/plugins/retry.ts +0 -25
- package/lib/plugins/role.ts +0 -28
- package/lib/service/llama3.cpp/completion.ts +0 -313
- package/lib/service/llama3.cpp/index.ts +0 -53
- package/lib/service/openai/chat.ts +0 -244
- package/lib/service/openai/images-generation.ts +0 -64
- package/lib/service/openai/index.ts +0 -97
- package/lib/service/openai/vision.ts +0 -111
- package/lib/shims.d.ts +0 -4
- package/lib/templates.ts +0 -71
- package/lib/types.ts +0 -4
- package/lib/utils/error.ts +0 -14
- package/lib/utils/validate.ts +0 -64
- package/logo.ai +2 -1141
- package/logo.png +0 -0
- package/types/examples/chat-demo.d.ts +0 -2
- package/types/examples/chat-for-llama.cpp-demo.d.ts +0 -2
- package/types/examples/chat-with-json-schema-demo.d.ts +0 -2
- package/types/examples/plugin-demo.d.ts +0 -2
- package/types/examples/stream-for-llama.cpp-demo.d.ts +0 -2
- package/types/examples/vision-demo.d.ts +0 -2
- package/types/lib/broker/chat.d.ts +0 -142
- package/types/lib/core/parser.d.ts +0 -32
- package/types/lib/core/plugin.d.ts +0 -34
- package/types/lib/core/translator.d.ts +0 -68
- package/types/lib/index.d.ts +0 -31
- package/types/lib/plugins/index.d.ts +0 -47
- package/types/lib/plugins/limiter.d.ts +0 -36
- package/types/lib/plugins/print-log.d.ts +0 -5
- package/types/lib/plugins/retry.d.ts +0 -6
- package/types/lib/plugins/role.d.ts +0 -5
- package/types/lib/service/llama3.cpp/completion.d.ts +0 -61
- package/types/lib/service/llama3.cpp/index.d.ts +0 -19
- package/types/lib/service/openai/chat.d.ts +0 -110
- package/types/lib/service/openai/completion.d.ts +0 -59
- package/types/lib/service/openai/images-generation.d.ts +0 -35
- package/types/lib/service/openai/index.d.ts +0 -29
- package/types/lib/service/openai/vision.d.ts +0 -74
- package/types/lib/templates.d.ts +0 -20
- package/types/lib/types.d.ts +0 -1
- package/types/lib/utils/error.d.ts +0 -11
- package/types/lib/utils/validate.d.ts +0 -16
package/logo.png
DELETED
|
Binary file
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { ChatBrokerPlugin } from '../core/plugin';
|
|
2
|
-
import { Event, Hook, Log } from 'power-helper';
|
|
3
|
-
import { Translator, TranslatorParams } from '../core/translator';
|
|
4
|
-
import { ValidateCallback, ValidateCallbackOutputs } from '../utils/validate';
|
|
5
|
-
type Message = {
|
|
6
|
-
role: 'system' | 'user' | 'assistant';
|
|
7
|
-
name?: string;
|
|
8
|
-
content: string;
|
|
9
|
-
};
|
|
10
|
-
export type ChatBrokerHooks<S extends ValidateCallback<any>, O extends ValidateCallback<any>, P extends ChatBrokerPlugin<any, any>, PS extends Record<string, ReturnType<P['use']>>> = {
|
|
11
|
-
/**
|
|
12
|
-
* @zh 第一次聊天的時候觸發
|
|
13
|
-
* @en Triggered when chatting for the first time
|
|
14
|
-
*/
|
|
15
|
-
start: {
|
|
16
|
-
id: string;
|
|
17
|
-
data: ValidateCallbackOutputs<S>;
|
|
18
|
-
plugins: {
|
|
19
|
-
[K in keyof PS]: {
|
|
20
|
-
send: (data: PS[K]['__receiveData']) => void;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
schema: {
|
|
24
|
-
input: S;
|
|
25
|
-
output: O;
|
|
26
|
-
};
|
|
27
|
-
messages: Message[];
|
|
28
|
-
setPreMessages: (messages: (Omit<Message, 'content'> & {
|
|
29
|
-
content: string | string[];
|
|
30
|
-
})[]) => void;
|
|
31
|
-
changeMessages: (messages: Message[]) => void;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* @zh 發送聊天訊息給機器人前觸發
|
|
35
|
-
* @en Triggered before sending chat message to bot
|
|
36
|
-
*/
|
|
37
|
-
talkBefore: {
|
|
38
|
-
id: string;
|
|
39
|
-
data: ValidateCallbackOutputs<S>;
|
|
40
|
-
messages: Message[];
|
|
41
|
-
lastUserMessage: string;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* @zh 當聊天機器人回傳資料的時候觸發
|
|
45
|
-
* @en Triggered when the chatbot returns data
|
|
46
|
-
*/
|
|
47
|
-
talkAfter: {
|
|
48
|
-
id: string;
|
|
49
|
-
data: ValidateCallbackOutputs<S>;
|
|
50
|
-
response: any;
|
|
51
|
-
messages: Message[];
|
|
52
|
-
parseText: string;
|
|
53
|
-
lastUserMessage: string;
|
|
54
|
-
/**
|
|
55
|
-
* @zh 宣告解析失敗
|
|
56
|
-
* @en Declare parsing failure
|
|
57
|
-
*/
|
|
58
|
-
parseFail: (error: any) => void;
|
|
59
|
-
changeParseText: (text: string) => void;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* @zh 當回傳資料符合規格時觸發
|
|
63
|
-
* @en Triggered when the returned data meets the specifications
|
|
64
|
-
*/
|
|
65
|
-
succeeded: {
|
|
66
|
-
id: string;
|
|
67
|
-
output: ValidateCallbackOutputs<O>;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* @zh 當回傳資料不符合規格,或是解析錯誤時觸發
|
|
71
|
-
* @en Triggered when the returned data does not meet the specifications or parsing errors
|
|
72
|
-
*/
|
|
73
|
-
parseFailed: {
|
|
74
|
-
id: string;
|
|
75
|
-
error: any;
|
|
76
|
-
retry: () => void;
|
|
77
|
-
count: number;
|
|
78
|
-
response: any;
|
|
79
|
-
parserFails: {
|
|
80
|
-
name: string;
|
|
81
|
-
error: any;
|
|
82
|
-
}[];
|
|
83
|
-
messages: Message[];
|
|
84
|
-
lastUserMessage: string;
|
|
85
|
-
changeMessages: (messages: Message[]) => void;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* @zh 不論成功失敗,執行結束的時候會執行。
|
|
89
|
-
* @en It will be executed when the execution is completed, regardless of success or failure.
|
|
90
|
-
*/
|
|
91
|
-
done: {
|
|
92
|
-
id: string;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
type RequestContext = {
|
|
96
|
-
count: number;
|
|
97
|
-
isRetry: boolean;
|
|
98
|
-
onCancel: (cb: () => void) => void;
|
|
99
|
-
schema: {
|
|
100
|
-
input: any;
|
|
101
|
-
output: any;
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
export type Params<S extends ValidateCallback<any>, O extends ValidateCallback<any>, C extends Record<string, any>, P extends ChatBrokerPlugin<any, any>, PS extends Record<string, ReturnType<P['use']>>> = Omit<TranslatorParams<S, O>, 'parsers'> & {
|
|
105
|
-
name?: string;
|
|
106
|
-
plugins?: PS | (() => PS);
|
|
107
|
-
request: (messages: Message[], context: RequestContext) => Promise<string>;
|
|
108
|
-
install?: (context: {
|
|
109
|
-
log: Log;
|
|
110
|
-
attach: Hook<C>['attach'];
|
|
111
|
-
attachAfter: Hook<C>['attachAfter'];
|
|
112
|
-
translator: Translator<S, O>;
|
|
113
|
-
}) => void;
|
|
114
|
-
};
|
|
115
|
-
export declare class ChatBroker<S extends ValidateCallback<any>, O extends ValidateCallback<any>, P extends ChatBrokerPlugin<any, any>, PS extends Record<string, ReturnType<P['use']>>, C extends ChatBrokerHooks<S, O, P, PS> = ChatBrokerHooks<S, O, P, PS>> {
|
|
116
|
-
protected __hookType: C;
|
|
117
|
-
protected log: Log;
|
|
118
|
-
protected hook: Hook<C>;
|
|
119
|
-
protected params: Params<S, O, C, P, PS>;
|
|
120
|
-
protected plugins: PS;
|
|
121
|
-
protected installed: boolean;
|
|
122
|
-
protected translator: Translator<S, O>;
|
|
123
|
-
protected event: Event<{
|
|
124
|
-
cancel: {
|
|
125
|
-
requestId: string;
|
|
126
|
-
};
|
|
127
|
-
cancelAll: any;
|
|
128
|
-
}>;
|
|
129
|
-
constructor(params: Params<S, O, C, P, PS>);
|
|
130
|
-
protected _install(): any;
|
|
131
|
-
cancel(requestId?: string): Promise<void>;
|
|
132
|
-
requestWithId<T extends Translator<S, O>>(data: T['__schemeType']): {
|
|
133
|
-
id: string;
|
|
134
|
-
request: Promise<T['__outputType']>;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* @zh 將請求發出至聊天機器人。
|
|
138
|
-
* @en Send request to chatbot.
|
|
139
|
-
*/
|
|
140
|
-
request<T extends Translator<S, O>>(data: T['__schemeType']): Promise<T['__outputType']>;
|
|
141
|
-
}
|
|
142
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
type TextParserParams = {
|
|
2
|
-
/**
|
|
3
|
-
* @zh 解讀器名字。
|
|
4
|
-
* @en The name of the parser.
|
|
5
|
-
*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**
|
|
8
|
-
* @zh 解讀文本。
|
|
9
|
-
* @en Read the text.
|
|
10
|
-
*/
|
|
11
|
-
handler: (text: string) => Promise<any>;
|
|
12
|
-
};
|
|
13
|
-
export declare class TextParser {
|
|
14
|
-
private params;
|
|
15
|
-
/**
|
|
16
|
-
* @zh 盡可能將文字內的 json 解讀出來。
|
|
17
|
-
* @en Try to read the json in the text as much as possible.
|
|
18
|
-
*/
|
|
19
|
-
static JsonMessage(): TextParser;
|
|
20
|
-
constructor(params: TextParserParams);
|
|
21
|
-
/**
|
|
22
|
-
* @zh 解讀器名字。
|
|
23
|
-
* @en The name of the parser.
|
|
24
|
-
*/
|
|
25
|
-
get name(): string;
|
|
26
|
-
/**
|
|
27
|
-
* @zh 解讀文本。
|
|
28
|
-
* @en Read the text.
|
|
29
|
-
*/
|
|
30
|
-
read(text: string): Promise<any>;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Translator } from './translator';
|
|
2
|
-
import { ChatBrokerHooks } from '../broker/chat';
|
|
3
|
-
import { Log, Hook, Event } from 'power-helper';
|
|
4
|
-
import { ValidateCallback, ValidateCallbackOutputs } from '../utils/validate';
|
|
5
|
-
type BrokerHooks = ChatBrokerHooks<any, any, any, any>;
|
|
6
|
-
type BrokerPluginParams<T extends ValidateCallback<any>, R extends ValidateCallback<any>> = {
|
|
7
|
-
name: string;
|
|
8
|
-
params: T;
|
|
9
|
-
receiveData: R;
|
|
10
|
-
onInstall: (context: {
|
|
11
|
-
log: Log;
|
|
12
|
-
params: ValidateCallbackOutputs<T>;
|
|
13
|
-
attach: Hook<BrokerHooks>['attach'];
|
|
14
|
-
attachAfter: Hook<BrokerHooks>['attachAfter'];
|
|
15
|
-
translator: Translator<any, any>;
|
|
16
|
-
receive: (callback: (params: {
|
|
17
|
-
id: string;
|
|
18
|
-
data: ValidateCallbackOutputs<R>;
|
|
19
|
-
}) => void) => void;
|
|
20
|
-
}) => void;
|
|
21
|
-
};
|
|
22
|
-
export declare class ChatBrokerPlugin<T extends ValidateCallback<any>, R extends ValidateCallback<any>> {
|
|
23
|
-
_event: Event<Record<string, Record<string, any>>>;
|
|
24
|
-
_params: BrokerPluginParams<T, R>;
|
|
25
|
-
constructor(params: BrokerPluginParams<T, R>);
|
|
26
|
-
use(params: ValidateCallbackOutputs<T>): {
|
|
27
|
-
instance: any;
|
|
28
|
-
params: ValidateCallbackOutputs<T, ReturnType<T>>;
|
|
29
|
-
send: (data: ValidateCallbackOutputs<R>) => void;
|
|
30
|
-
receive: (callback: any) => void;
|
|
31
|
-
__receiveData: ValidateCallbackOutputs<R, ReturnType<R>>;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export {};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { TextParser } from './parser';
|
|
2
|
-
import { ValidateCallback, ValidateCallbackOutputs } from '../utils/validate';
|
|
3
|
-
export type TranslatorParams<S extends ValidateCallback<any>, O extends ValidateCallback<any>> = {
|
|
4
|
-
/**
|
|
5
|
-
* @zh 輸入的資料格式。
|
|
6
|
-
* @en The input data format.
|
|
7
|
-
*/
|
|
8
|
-
input: S;
|
|
9
|
-
/**
|
|
10
|
-
* @zh 輸出的資料格式。
|
|
11
|
-
* @en The output data format.
|
|
12
|
-
*/
|
|
13
|
-
output: O;
|
|
14
|
-
/**
|
|
15
|
-
* @zh 註冊解讀文字的解析器。
|
|
16
|
-
* @en Register the parser to interpret the text.
|
|
17
|
-
*/
|
|
18
|
-
parsers: TextParser[];
|
|
19
|
-
/**
|
|
20
|
-
* @zh 組合輸入資料成為提示文字。
|
|
21
|
-
* @en Combine the input data into a prompt.
|
|
22
|
-
*/
|
|
23
|
-
question: (data: ValidateCallbackOutputs<S>, context: {
|
|
24
|
-
schema: {
|
|
25
|
-
input: S;
|
|
26
|
-
output: O;
|
|
27
|
-
};
|
|
28
|
-
}) => Promise<string | string[]>;
|
|
29
|
-
};
|
|
30
|
-
export declare class Translator<S extends ValidateCallback<any>, O extends ValidateCallback<any>> {
|
|
31
|
-
private params;
|
|
32
|
-
constructor(params: TranslatorParams<S, O>);
|
|
33
|
-
get __schemeType(): ValidateCallbackOutputs<S>;
|
|
34
|
-
get __outputType(): ValidateCallbackOutputs<O>;
|
|
35
|
-
/**
|
|
36
|
-
* @zh 組合輸入資料成為提示文字。
|
|
37
|
-
* @en Combine the input data into a prompt.
|
|
38
|
-
*/
|
|
39
|
-
compile(data: ValidateCallbackOutputs<S>, context: {
|
|
40
|
-
schema: {
|
|
41
|
-
input: S;
|
|
42
|
-
output: O;
|
|
43
|
-
};
|
|
44
|
-
}): Promise<{
|
|
45
|
-
scheme: ReturnType<S> extends infer T ? { [K in keyof T]: ReturnType<S>[K] extends {
|
|
46
|
-
__outputType: any;
|
|
47
|
-
} ? ReturnType<S>[K]["__outputType"] : unknown; } : never;
|
|
48
|
-
prompt: string;
|
|
49
|
-
}>;
|
|
50
|
-
getValidate(): {
|
|
51
|
-
input: S;
|
|
52
|
-
output: O;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* @zh 將文字轉換成序列化資料。
|
|
56
|
-
* @en Convert text to serialized data.
|
|
57
|
-
*/
|
|
58
|
-
parse(text: string): Promise<{
|
|
59
|
-
output: ReturnType<O> extends infer T ? { [K in keyof T]: ReturnType<O>[K] extends {
|
|
60
|
-
__outputType: any;
|
|
61
|
-
} ? ReturnType<O>[K]["__outputType"] : unknown; } : never;
|
|
62
|
-
parserName: string;
|
|
63
|
-
parserFails: {
|
|
64
|
-
name: string;
|
|
65
|
-
error: any;
|
|
66
|
-
}[];
|
|
67
|
-
}>;
|
|
68
|
-
}
|
package/types/lib/index.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export * as plugins from './plugins';
|
|
2
|
-
export * as templates from './templates';
|
|
3
|
-
export { validateToJsonSchema, defineYupSchema } from './utils/validate';
|
|
4
|
-
export { OpenAI } from './service/openai';
|
|
5
|
-
export { Llama3Cpp } from './service/llama3.cpp';
|
|
6
|
-
export { TextParser } from './core/parser';
|
|
7
|
-
export { ChatGPTMessage } from './service/openai/chat';
|
|
8
|
-
export { ChatBroker } from './broker/chat';
|
|
9
|
-
export { ChatBrokerPlugin } from './core/plugin';
|
|
10
|
-
export { Translator, TranslatorParams } from './core/translator';
|
|
11
|
-
import * as plugins from './plugins';
|
|
12
|
-
import * as templates from './templates';
|
|
13
|
-
import { OpenAI } from './service/openai';
|
|
14
|
-
import { Llama3Cpp } from './service/llama3.cpp';
|
|
15
|
-
import { Translator } from './core/translator';
|
|
16
|
-
import { TextParser } from './core/parser';
|
|
17
|
-
import { ChatBroker } from './broker/chat';
|
|
18
|
-
import { ChatBrokerPlugin } from './core/plugin';
|
|
19
|
-
export declare const ctod: {
|
|
20
|
-
OpenAI: typeof OpenAI;
|
|
21
|
-
Llama3Cpp: typeof Llama3Cpp;
|
|
22
|
-
plugins: typeof plugins;
|
|
23
|
-
templates: typeof templates;
|
|
24
|
-
ChatBroker: typeof ChatBroker;
|
|
25
|
-
Translator: typeof Translator;
|
|
26
|
-
TextParser: typeof TextParser;
|
|
27
|
-
ChatBrokerPlugin: typeof ChatBrokerPlugin;
|
|
28
|
-
defineYupSchema: <T extends Record<string, import("yup").Schema<any, any, any, "">>>(cb: import("./utils/validate").ValidateCallback<T>) => T;
|
|
29
|
-
validateToJsonSchema: <T_1 extends import("./utils/validate").ValidateCallback<any>>(cb: T_1) => import("json-schema").JSONSchema7;
|
|
30
|
-
};
|
|
31
|
-
export default ctod;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @zh 一個基於印出 log 的 plugin。
|
|
3
|
-
* @en A plugin based on printing log.
|
|
4
|
-
*/
|
|
5
|
-
export declare const PrintLogPlugin: import("..").ChatBrokerPlugin<(yup: typeof import("yup")) => {
|
|
6
|
-
detail: import("yup").BooleanSchema<boolean | undefined, import("yup").AnyObject, false, "d">;
|
|
7
|
-
}, () => {}>;
|
|
8
|
-
/**
|
|
9
|
-
* @zh 當解析失敗時,會自動重試的對話。
|
|
10
|
-
* @en A conversation that will automatically retry when parsing fails.
|
|
11
|
-
*/
|
|
12
|
-
export declare const RetryPlugin: import("..").ChatBrokerPlugin<(yup: typeof import("yup")) => {
|
|
13
|
-
retry: import("yup").NumberSchema<number, import("yup").AnyObject, 1, "d">;
|
|
14
|
-
printWarn: import("yup").BooleanSchema<NonNullable<boolean | undefined>, import("yup").AnyObject, true, "d">;
|
|
15
|
-
}, () => {}>;
|
|
16
|
-
/**
|
|
17
|
-
* @zh 限制使用流量,這個 plugin 可以有效讓所有對話不會再限制內同時發送,可用於在開發過程中遭遇伺服器因頻率過高而阻擋請求。
|
|
18
|
-
* @en Limit the use of traffic. This plugin can effectively prevent all conversations from being sent at the same time within the limit, and can be used when the server blocks requests due to high frequency during development.
|
|
19
|
-
*/
|
|
20
|
-
export declare const LimiterPlugin: import("..").ChatBrokerPlugin<() => {}, () => {}>;
|
|
21
|
-
/**
|
|
22
|
-
* @zh 排程系統將全域託管,有什麼必要設定可以來更動它的狀態,例如:關閉排程。
|
|
23
|
-
* @en The scheduling system will be globally hosted. What is necessary to set can come to change its status, for example: close the schedule.
|
|
24
|
-
*/
|
|
25
|
-
export declare const LimiterPluginGlobState: {
|
|
26
|
-
event: import("power-helper").Event<{
|
|
27
|
-
run: {
|
|
28
|
-
id: string;
|
|
29
|
-
};
|
|
30
|
-
waitTimeChange: {
|
|
31
|
-
waitTime: number;
|
|
32
|
-
};
|
|
33
|
-
}>;
|
|
34
|
-
config: {
|
|
35
|
-
limit: number;
|
|
36
|
-
interval: number;
|
|
37
|
-
};
|
|
38
|
-
closeSchedule: () => void;
|
|
39
|
-
plugin: import("..").ChatBrokerPlugin<() => {}, () => {}>;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* @zh 設定角色扮演。
|
|
43
|
-
* @en Set role play.
|
|
44
|
-
*/
|
|
45
|
-
export declare const RolePlugin: import("..").ChatBrokerPlugin<(yup: typeof import("yup")) => {
|
|
46
|
-
role: import("yup").StringSchema<string, import("yup").AnyObject, undefined, "">;
|
|
47
|
-
}, () => {}>;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ChatBrokerPlugin } from '../core/plugin';
|
|
2
|
-
import { Event } from 'power-helper';
|
|
3
|
-
type Events = {
|
|
4
|
-
run: {
|
|
5
|
-
id: string;
|
|
6
|
-
};
|
|
7
|
-
waitTimeChange: {
|
|
8
|
-
waitTime: number;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
declare const _default: {
|
|
12
|
-
/**
|
|
13
|
-
* @zh 你可以監聽一些事件行為,例如還需要等待多少時間。
|
|
14
|
-
* @en You can listen for some event behaviors, such as how long you still need to wait.
|
|
15
|
-
*/
|
|
16
|
-
event: Event<Events>;
|
|
17
|
-
/**
|
|
18
|
-
* @zh 預設是每分鐘限制3次,你可以在設定中改變限制流量。
|
|
19
|
-
* @en By default, the limit is 3 times per minute, and you can change the limit flow in the settings.
|
|
20
|
-
*/
|
|
21
|
-
config: {
|
|
22
|
-
limit: number;
|
|
23
|
-
interval: number;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* @zh 由於排程會在背景持續倒數,如果有關閉程式的需求,需要手動進行移除。
|
|
27
|
-
* @en Since the schedule will continue to count down in the background, if there is a need to close the program, you need to manually remove it.
|
|
28
|
-
*/
|
|
29
|
-
closeSchedule: () => void;
|
|
30
|
-
/**
|
|
31
|
-
* @zh Plugin 的接口
|
|
32
|
-
* @en Plugin interface
|
|
33
|
-
*/
|
|
34
|
-
plugin: ChatBrokerPlugin<() => {}, () => {}>;
|
|
35
|
-
};
|
|
36
|
-
export default _default;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ChatBrokerPlugin } from '../core/plugin';
|
|
2
|
-
declare const _default: ChatBrokerPlugin<(yup: typeof import("yup")) => {
|
|
3
|
-
retry: import("yup").NumberSchema<number, import("yup").AnyObject, 1, "d">;
|
|
4
|
-
printWarn: import("yup").BooleanSchema<NonNullable<boolean | undefined>, import("yup").AnyObject, true, "d">;
|
|
5
|
-
}, () => {}>;
|
|
6
|
-
export default _default;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Llama3Cpp } from './index';
|
|
2
|
-
type Message = {
|
|
3
|
-
role: string;
|
|
4
|
-
content: string;
|
|
5
|
-
};
|
|
6
|
-
type Options = any;
|
|
7
|
-
export type Config = {
|
|
8
|
-
baseUrl: string;
|
|
9
|
-
headers: Record<string, string>;
|
|
10
|
-
autoConvertTraditionalChinese: boolean;
|
|
11
|
-
};
|
|
12
|
-
type Stream = {
|
|
13
|
-
onMessage: (data: {
|
|
14
|
-
message: string;
|
|
15
|
-
}) => void;
|
|
16
|
-
onEnd?: () => void;
|
|
17
|
-
onWarn?: (error: any) => void;
|
|
18
|
-
onError?: (error: any) => void;
|
|
19
|
-
};
|
|
20
|
-
export declare class Llama3CppCompletion {
|
|
21
|
-
core: Llama3Cpp;
|
|
22
|
-
config: Config;
|
|
23
|
-
constructor(core: Llama3Cpp);
|
|
24
|
-
setConfig(config: Partial<Config>): void;
|
|
25
|
-
completion(params: {
|
|
26
|
-
options?: Options;
|
|
27
|
-
messages: Message[];
|
|
28
|
-
}): {
|
|
29
|
-
run: () => Promise<{
|
|
30
|
-
message: string;
|
|
31
|
-
fullMessage: string;
|
|
32
|
-
}>;
|
|
33
|
-
cancel: () => void;
|
|
34
|
-
};
|
|
35
|
-
completionStream(params: Stream & {
|
|
36
|
-
messages: Message[];
|
|
37
|
-
options?: Options;
|
|
38
|
-
}): {
|
|
39
|
-
cancel: () => void;
|
|
40
|
-
};
|
|
41
|
-
talk(params: {
|
|
42
|
-
options?: Options;
|
|
43
|
-
messages: Message[];
|
|
44
|
-
response_format?: {
|
|
45
|
-
type: 'json_object';
|
|
46
|
-
schema: any;
|
|
47
|
-
};
|
|
48
|
-
}): {
|
|
49
|
-
run: () => Promise<{
|
|
50
|
-
message: string;
|
|
51
|
-
}>;
|
|
52
|
-
cancel: () => void;
|
|
53
|
-
};
|
|
54
|
-
talkStream(params: Stream & {
|
|
55
|
-
options?: Options;
|
|
56
|
-
messages: Message[];
|
|
57
|
-
}): {
|
|
58
|
-
cancel: () => void;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { Llama3CppCompletion, Config } from './completion';
|
|
3
|
-
export declare class Llama3Cpp {
|
|
4
|
-
_axios: AxiosInstance;
|
|
5
|
-
static createChatRequest(params: {
|
|
6
|
-
config: Partial<Config> | (() => Promise<Partial<Config>>);
|
|
7
|
-
talkOptions?: any;
|
|
8
|
-
}): (messages: any[], { schema, onCancel }: any) => Promise<string>;
|
|
9
|
-
/**
|
|
10
|
-
* @zh 如果你有需要特別設定 axios,請使用這方法。
|
|
11
|
-
* @en If you need to set axios, please use this method.
|
|
12
|
-
*/
|
|
13
|
-
setAxios(axios: AxiosInstance): void;
|
|
14
|
-
/**
|
|
15
|
-
* @zh 建立 補強/ 對話物件。
|
|
16
|
-
* @en Create completion object.
|
|
17
|
-
*/
|
|
18
|
-
createCompletion(): Llama3CppCompletion;
|
|
19
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from './index';
|
|
2
|
-
import { PromiseResponseType } from '../../types';
|
|
3
|
-
export type ChatGPTMessage = {
|
|
4
|
-
role: 'system' | 'user' | 'assistant';
|
|
5
|
-
name?: string;
|
|
6
|
-
content: string;
|
|
7
|
-
};
|
|
8
|
-
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
|
-
export 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 選擇運行的模型,16k意味著能處理長度為 16,384 的文本,32k意味著能處理長度為 32768 的文本。
|
|
35
|
-
* @en How many chat completion choices to generate for each input message.
|
|
36
|
-
*/
|
|
37
|
-
model: 'gpt-4' | 'gpt-3.5-turbo' | 'gpt-4-turbo' | 'gpt-4o' | 'gpt-4o-mini' | 'o1-preview' | 'o1' | 'o1-mini';
|
|
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
|
-
* @zh 是否強制要回傳 JSON 格式的資料
|
|
45
|
-
* @en Whether to force the return of JSON format data
|
|
46
|
-
*/
|
|
47
|
-
forceJsonFormat: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* @zh 每次對話最多產生幾個 tokens。
|
|
50
|
-
* @en How many tokens to complete to.
|
|
51
|
-
*/
|
|
52
|
-
maxTokens?: number;
|
|
53
|
-
};
|
|
54
|
-
export declare class OpenAIChat {
|
|
55
|
-
openai: OpenAI;
|
|
56
|
-
config: Config;
|
|
57
|
-
constructor(openai: OpenAI);
|
|
58
|
-
/**
|
|
59
|
-
* @zh 改變對話的一些設定
|
|
60
|
-
* @en Change some settings of the conversation
|
|
61
|
-
*/
|
|
62
|
-
setConfig(options: Partial<Config>): void;
|
|
63
|
-
/**
|
|
64
|
-
* @zh 檢視內容是否符合 OpenAI 的審查
|
|
65
|
-
* @en View content for OpenAI moderation
|
|
66
|
-
*/
|
|
67
|
-
moderations(input: string): Promise<{
|
|
68
|
-
isSafe: boolean;
|
|
69
|
-
result: any;
|
|
70
|
-
}>;
|
|
71
|
-
/**
|
|
72
|
-
* @zh 進行對話
|
|
73
|
-
* @en Talk to the AI
|
|
74
|
-
*/
|
|
75
|
-
talk(messages?: ChatGPTMessage[], options?: {
|
|
76
|
-
/** 要 forceJsonFormat 為 true 才會生效 */
|
|
77
|
-
jsonSchema?: any;
|
|
78
|
-
abortController?: AbortController;
|
|
79
|
-
}): Promise<{
|
|
80
|
-
id: string;
|
|
81
|
-
text: string;
|
|
82
|
-
newMessages: ChatGPTMessage[];
|
|
83
|
-
isDone: boolean;
|
|
84
|
-
apiReseponse: ApiResponse;
|
|
85
|
-
}>;
|
|
86
|
-
talkStream(params: {
|
|
87
|
-
messages: any[];
|
|
88
|
-
onMessage: (message: string) => void;
|
|
89
|
-
onEnd: () => void;
|
|
90
|
-
onWarn: (warn: any) => void;
|
|
91
|
-
onError: (error: any) => void;
|
|
92
|
-
}): {
|
|
93
|
-
cancel: () => void;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* @zh 開啟持續性對話
|
|
97
|
-
*/
|
|
98
|
-
keepTalk(prompt: string | string[], oldMessages?: ChatGPTMessage[]): Promise<{
|
|
99
|
-
result: {
|
|
100
|
-
id: string;
|
|
101
|
-
text: string;
|
|
102
|
-
newMessages: ChatGPTMessage[];
|
|
103
|
-
isDone: boolean;
|
|
104
|
-
apiReseponse: ApiResponse;
|
|
105
|
-
};
|
|
106
|
-
nextTalk: (prompt: string | string[]) => Promise<any>;
|
|
107
|
-
}>;
|
|
108
|
-
}
|
|
109
|
-
export type OpenAIChatTalkResponse = PromiseResponseType<OpenAIChat['talk']>;
|
|
110
|
-
export {};
|