@xsai/shared-chat 0.0.27 → 0.0.29
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/dist/index.d.ts +34 -28
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { CommonRequestOptions } from '@xsai/shared';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface AudioBase64 {
|
|
4
|
+
/**
|
|
5
|
+
* Base64 encoded audio data.
|
|
6
|
+
*/
|
|
7
|
+
data: string;
|
|
8
|
+
format: 'mp3' | 'wav';
|
|
9
|
+
}
|
|
10
|
+
interface AudioPart extends CommonPart<'input_audio'> {
|
|
11
|
+
input_audio: AudioBase64;
|
|
12
|
+
}
|
|
4
13
|
interface CommonPart<T extends string> {
|
|
5
14
|
type: T;
|
|
6
15
|
}
|
|
@@ -17,16 +26,7 @@ interface ImageURLorBase64 {
|
|
|
17
26
|
*/
|
|
18
27
|
url: string;
|
|
19
28
|
}
|
|
20
|
-
|
|
21
|
-
input_audio: AudioBase64;
|
|
22
|
-
}
|
|
23
|
-
interface AudioBase64 {
|
|
24
|
-
/**
|
|
25
|
-
* Base64 encoded audio data.
|
|
26
|
-
*/
|
|
27
|
-
data: string;
|
|
28
|
-
format: 'mp3' | 'wav';
|
|
29
|
-
}
|
|
29
|
+
type Part = AudioPart | ImagePart | RefusalPart | TextPart;
|
|
30
30
|
interface RefusalPart extends CommonPart<'refusal'> {
|
|
31
31
|
refusal: string;
|
|
32
32
|
}
|
|
@@ -34,20 +34,23 @@ interface TextPart extends CommonPart<'text'> {
|
|
|
34
34
|
text: string;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
interface AssistantMessage extends Optional<CommonMessage<'assistant', AssistantMessagePart>, 'content'> {
|
|
38
|
+
refusal?: null | string;
|
|
39
|
+
tool_calls?: ToolCall[];
|
|
40
|
+
}
|
|
41
|
+
type AssistantMessagePart = RefusalPart | TextPart;
|
|
42
|
+
interface AssistantMessageResponse extends Omit<AssistantMessage, 'content'> {
|
|
43
|
+
content?: string;
|
|
44
|
+
}
|
|
39
45
|
interface CommonMessage<T extends string, P extends Part> {
|
|
40
46
|
content: Array<P> | string;
|
|
41
47
|
name?: string;
|
|
42
48
|
role: T;
|
|
43
49
|
}
|
|
44
|
-
type
|
|
50
|
+
type Message = AssistantMessage | SystemMessage | ToolMessage | UserMessage;
|
|
45
51
|
interface SystemMessage extends CommonMessage<'system', SystemMessagePart> {
|
|
46
52
|
}
|
|
47
|
-
type
|
|
48
|
-
interface UserMessage extends CommonMessage<'user', UserMessagePart> {
|
|
49
|
-
}
|
|
50
|
-
type AssistantMessagePart = RefusalPart | TextPart;
|
|
53
|
+
type SystemMessagePart = TextPart;
|
|
51
54
|
interface ToolCall {
|
|
52
55
|
function: {
|
|
53
56
|
arguments: string;
|
|
@@ -56,17 +59,14 @@ interface ToolCall {
|
|
|
56
59
|
id: string;
|
|
57
60
|
type: 'function';
|
|
58
61
|
}
|
|
59
|
-
interface AssistantMessage extends Optional<CommonMessage<'assistant', AssistantMessagePart>, 'content'> {
|
|
60
|
-
refusal?: null | string;
|
|
61
|
-
tool_calls?: ToolCall[];
|
|
62
|
-
}
|
|
63
|
-
interface AssistantMessageResponse extends Omit<AssistantMessage, 'content'> {
|
|
64
|
-
content?: string;
|
|
65
|
-
}
|
|
66
|
-
type ToolMessagePart = TextPart;
|
|
67
62
|
interface ToolMessage extends Omit<CommonMessage<'tool', ToolMessagePart>, 'name'> {
|
|
68
63
|
tool_call_id: string;
|
|
69
64
|
}
|
|
65
|
+
type ToolMessagePart = TextPart;
|
|
66
|
+
interface UserMessage extends CommonMessage<'user', UserMessagePart> {
|
|
67
|
+
}
|
|
68
|
+
type UserMessagePart = AudioPart | ImagePart | TextPart;
|
|
69
|
+
type Optional<T, K extends keyof T> = Omit<T, K> & Pick<Partial<T>, K>;
|
|
70
70
|
|
|
71
71
|
type ToolChoice = 'auto' | 'none' | 'required' | {
|
|
72
72
|
function: {
|
|
@@ -81,7 +81,7 @@ interface ChatOptions extends CommonRequestOptions {
|
|
|
81
81
|
toolChoice?: ToolChoice;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | (
|
|
84
|
+
type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | (string & {});
|
|
85
85
|
|
|
86
86
|
interface Tool {
|
|
87
87
|
execute: (input: unknown) => Promise<string> | string;
|
|
@@ -94,6 +94,12 @@ interface Tool {
|
|
|
94
94
|
type: 'function';
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
interface Usage {
|
|
98
|
+
completion_tokens: number;
|
|
99
|
+
prompt_tokens: number;
|
|
100
|
+
total_tokens: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
97
103
|
declare const chat: <T extends ChatOptions>(options: T) => Promise<Response>;
|
|
98
104
|
|
|
99
105
|
declare const messages: (...messages: Message[]) => Message[];
|
|
@@ -115,4 +121,4 @@ declare namespace message {
|
|
|
115
121
|
export { message_assistant as assistant, message_imagePart as imagePart, message_messages as messages, message_system as system, message_textPart as textPart, message_tool as tool, message_user as user };
|
|
116
122
|
}
|
|
117
123
|
|
|
118
|
-
export { type AssistantMessage, type AssistantMessagePart, type AssistantMessageResponse, type AudioBase64, type AudioPart, type ChatOptions, type CommonMessage, type CommonPart, type FinishReason, type ImagePart, type ImageURLorBase64, type Message, type Part, type RefusalPart, type SystemMessage, type SystemMessagePart, type TextPart, type Tool, type ToolCall, type ToolChoice, type ToolMessage, type ToolMessagePart, type UserMessage, type UserMessagePart, chat, message };
|
|
124
|
+
export { type AssistantMessage, type AssistantMessagePart, type AssistantMessageResponse, type AudioBase64, type AudioPart, type ChatOptions, type CommonMessage, type CommonPart, type FinishReason, type ImagePart, type ImageURLorBase64, type Message, type Part, type RefusalPart, type SystemMessage, type SystemMessagePart, type TextPart, type Tool, type ToolCall, type ToolChoice, type ToolMessage, type ToolMessagePart, type Usage, type UserMessage, type UserMessagePart, chat, message };
|