@shenghuabi/openai 1.0.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.
@@ -0,0 +1,32 @@
1
+ import { OpenAIChat } from './vendor/openai';
2
+ import { ChatRequestOptions, ChatToolBodyInput } from './type';
3
+ import { CreateChatModelOptions } from './options.define';
4
+ export declare class ChatProviderService {
5
+ #private;
6
+ create(input: Omit<CreateChatModelOptions, 'name'>): {
7
+ stream: (input: import("./type").ChatBodyInput, options?: ChatRequestOptions | undefined) => AsyncGenerator<{
8
+ content: string;
9
+ isThinking: boolean;
10
+ delta: any;
11
+ thinkContent: string | undefined;
12
+ }, void, unknown>;
13
+ chat: (input: import("./type").ChatBodyInput, options?: ChatRequestOptions | undefined) => Promise<{
14
+ content: string;
15
+ isThinking: boolean;
16
+ delta: any;
17
+ thinkContent: string | undefined;
18
+ }>;
19
+ callTool: (input: ChatToolBodyInput, options?: ChatRequestOptions) => Promise<{
20
+ type: "function";
21
+ function: {
22
+ name: any;
23
+ arguments: Record<string, any> | undefined;
24
+ };
25
+ text?: undefined;
26
+ } | {
27
+ type: "text";
28
+ text: string;
29
+ function?: undefined;
30
+ }>;
31
+ };
32
+ }
@@ -0,0 +1,3 @@
1
+ import { InjectionToken, Signal } from 'static-injector';
2
+ import { OpenAIConfig } from './type';
3
+ export declare const OpenAIConfigToken: InjectionToken<Signal<OpenAIConfig>>;
@@ -0,0 +1,7 @@
1
+ import { ChatMessageListOutputType } from '../message.define';
2
+ export interface HistoryItem {
3
+ messages: ChatMessageListOutputType;
4
+ config: any;
5
+ options: any;
6
+ date: number;
7
+ }
package/chat/type.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { ChatMessageListOutputType } from './message.define';
2
+ export interface ResolvedChatOptions {
3
+ model: string;
4
+ temperature: number;
5
+ topP: number;
6
+ maxTokens: number;
7
+ baseURL: string;
8
+ verbose: boolean;
9
+ apiKey: string;
10
+ vendor: string;
11
+ }
12
+ interface ResponseFormatText {
13
+ type: 'text';
14
+ }
15
+ interface JSONSchema {
16
+ name: string;
17
+ description?: string;
18
+ schema?: Record<string, unknown>;
19
+ strict?: boolean | null;
20
+ }
21
+ interface ResponseFormatJSONSchema {
22
+ json_schema: JSONSchema;
23
+ type: 'json_schema';
24
+ }
25
+ interface ResponseFormatJSONObject {
26
+ type: 'json_object';
27
+ }
28
+ export interface ChatBodyInput {
29
+ response_format?: ResponseFormatText | ResponseFormatJSONSchema | ResponseFormatJSONObject;
30
+ messages: ChatMessageListOutputType;
31
+ }
32
+ export type FunctionDefinition = {
33
+ name: string;
34
+ description?: string;
35
+ parameters?: Record<string, unknown>;
36
+ strict?: boolean | null;
37
+ };
38
+ export type RunnableToolFunctionWithParse = {
39
+ type: 'function';
40
+ function: FunctionDefinition;
41
+ };
42
+ export type ChatToolBodyInput = ChatBodyInput & {
43
+ tools: RunnableToolFunctionWithParse[];
44
+ };
45
+ export interface ChatRequestOptions {
46
+ headers?: Record<string, string | null | undefined>;
47
+ signal?: AbortSignal | undefined;
48
+ tryPull?: (error: any) => boolean;
49
+ pullModel?: (name: string) => Promise<any>;
50
+ }
51
+ export interface OpenAIConfig {
52
+ tryPull?: () => boolean;
53
+ pullModel?: (name: string) => Promise<any>;
54
+ captureException: (error: any) => any;
55
+ history: {
56
+ dir: string;
57
+ enable: boolean;
58
+ };
59
+ }
60
+ export {};
@@ -0,0 +1,4 @@
1
+ import { AssistantChatMessageType, SystemChatMessageType, UserChatMessageType } from '../message.define';
2
+ export declare function createSystemMessage(): SystemChatMessageType;
3
+ export declare function createUserMessage(text?: string): UserChatMessageType;
4
+ export declare function createAssistantMessage(text?: string): AssistantChatMessageType;
@@ -0,0 +1,20 @@
1
+ import { OpenAIChat } from '../openai';
2
+ import Anthropic from '@anthropic-ai/sdk';
3
+ import { ChatBodyInput, ChatRequestOptions, ChatToolBodyInput } from '../../type';
4
+ export declare class AnthropicChat extends OpenAIChat {
5
+ client: Anthropic;
6
+ init(): void;
7
+ stream(input: ChatBodyInput, options?: ChatRequestOptions): AsyncGenerator<string, void, unknown>;
8
+ callTool(input: ChatToolBodyInput, options?: ChatRequestOptions): Promise<{
9
+ type: "function";
10
+ function: {
11
+ name: string;
12
+ arguments: Record<string, any> | undefined;
13
+ };
14
+ text?: undefined;
15
+ } | {
16
+ type: "text";
17
+ text: string;
18
+ function?: undefined;
19
+ }>;
20
+ }
@@ -0,0 +1,77 @@
1
+ import * as v from 'valibot';
2
+ export declare const AnthropicSystemMessageDefine: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
3
+ readonly text: v.StringSchema<undefined>;
4
+ readonly type: v.OptionalSchema<v.LiteralSchema<"text", undefined>, "text">;
5
+ }, undefined>, undefined>, v.TransformAction<{
6
+ text: string;
7
+ type: "text";
8
+ }[], {
9
+ text: string;
10
+ type: "text";
11
+ }[]>]>;
12
+ export declare const AnthropicChatMessageListDefine: v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
13
+ readonly role: v.OptionalSchema<v.LiteralSchema<"user", undefined>, "user">;
14
+ readonly content: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
15
+ readonly text: v.StringSchema<undefined>;
16
+ readonly type: v.OptionalSchema<v.LiteralSchema<"text", undefined>, "text">;
17
+ }, undefined>, v.ObjectSchema<{
18
+ readonly image_url: v.ObjectSchema<{
19
+ readonly url: v.StringSchema<undefined>;
20
+ readonly detail: v.OptionalSchema<v.PicklistSchema<["auto", "low", "high"], undefined>, undefined>;
21
+ }, undefined>;
22
+ readonly type: v.OptionalSchema<v.LiteralSchema<"image_url", undefined>, "image_url">;
23
+ }, undefined>], undefined>, undefined>;
24
+ }, undefined>, v.TransformAction<{
25
+ role: "user";
26
+ content: ({
27
+ text: string;
28
+ type: "text";
29
+ } | {
30
+ image_url: {
31
+ url: string;
32
+ detail?: "auto" | "low" | "high" | undefined;
33
+ };
34
+ type: "image_url";
35
+ })[];
36
+ }, {
37
+ content: ({
38
+ text: string;
39
+ type: "text";
40
+ } | {
41
+ type: "image";
42
+ source: {
43
+ type: "base64";
44
+ media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
45
+ data: string;
46
+ };
47
+ })[];
48
+ role: "user";
49
+ }>]>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
50
+ readonly role: v.OptionalSchema<v.LiteralSchema<"assistant", undefined>, "assistant">;
51
+ readonly content: v.ArraySchema<v.ObjectSchema<{
52
+ readonly text: v.StringSchema<undefined>;
53
+ readonly type: v.OptionalSchema<v.LiteralSchema<"text", undefined>, "text">;
54
+ }, undefined>, undefined>;
55
+ readonly thinkContent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
56
+ }, undefined>, v.TransformAction<{
57
+ role: "assistant";
58
+ content: {
59
+ text: string;
60
+ type: "text";
61
+ }[];
62
+ thinkContent?: string | undefined;
63
+ }, {
64
+ content: ({
65
+ text: string;
66
+ type: "text";
67
+ } | {
68
+ type: "image";
69
+ source: {
70
+ type: "base64";
71
+ media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
72
+ data: string;
73
+ };
74
+ })[];
75
+ role: "assistant";
76
+ thinkContent?: string | undefined;
77
+ }>]>], undefined>, undefined>;
@@ -0,0 +1,7 @@
1
+ import { OpenAIChat } from '../openai';
2
+ import { ChatBodyInput, ChatRequestOptions } from '../../type';
3
+ export declare class GeminiChat extends OpenAIChat {
4
+ #private;
5
+ init(): void;
6
+ stream(input: ChatBodyInput, options?: ChatRequestOptions): AsyncGenerator<string, void, unknown>;
7
+ }
@@ -0,0 +1,68 @@
1
+ import * as v from 'valibot';
2
+ export declare const GenminiSystemMessageDefine: v.SchemaWithPipe<readonly [v.ObjectSchema<{
3
+ readonly role: v.OptionalSchema<v.LiteralSchema<"system", undefined>, "system">;
4
+ readonly content: v.ArraySchema<v.ObjectSchema<{
5
+ readonly text: v.StringSchema<undefined>;
6
+ readonly type: v.OptionalSchema<v.LiteralSchema<"text", undefined>, "text">;
7
+ }, undefined>, undefined>;
8
+ }, undefined>, v.TransformAction<{
9
+ role: "system";
10
+ content: {
11
+ text: string;
12
+ type: "text";
13
+ }[];
14
+ }, {
15
+ role: string;
16
+ parts: {
17
+ text: string;
18
+ }[];
19
+ }>]>;
20
+ export declare const GenminiChatMessageListDefine: v.SchemaWithPipe<readonly [v.ArraySchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.ObjectSchema<{
21
+ readonly role: v.OptionalSchema<v.LiteralSchema<"user", undefined>, "user">;
22
+ readonly content: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
23
+ readonly text: v.StringSchema<undefined>;
24
+ readonly type: v.OptionalSchema<v.LiteralSchema<"text", undefined>, "text">;
25
+ }, undefined>, v.ObjectSchema<{
26
+ readonly image_url: v.ObjectSchema<{
27
+ readonly url: v.StringSchema<undefined>;
28
+ readonly detail: v.OptionalSchema<v.PicklistSchema<["auto", "low", "high"], undefined>, undefined>;
29
+ }, undefined>;
30
+ readonly type: v.OptionalSchema<v.LiteralSchema<"image_url", undefined>, "image_url">;
31
+ }, undefined>], undefined>, undefined>;
32
+ }, undefined>, v.TransformAction<{
33
+ role: "user";
34
+ content: ({
35
+ text: string;
36
+ type: "text";
37
+ } | {
38
+ image_url: {
39
+ url: string;
40
+ detail?: "auto" | "low" | "high" | undefined;
41
+ };
42
+ type: "image_url";
43
+ })[];
44
+ }, {
45
+ role: "user";
46
+ parts: {
47
+ text: string;
48
+ }[];
49
+ }>]>, v.SchemaWithPipe<readonly [v.ObjectSchema<{
50
+ readonly role: v.OptionalSchema<v.LiteralSchema<"assistant", undefined>, "assistant">;
51
+ readonly content: v.ArraySchema<v.ObjectSchema<{
52
+ readonly text: v.StringSchema<undefined>;
53
+ readonly type: v.OptionalSchema<v.LiteralSchema<"text", undefined>, "text">;
54
+ }, undefined>, undefined>;
55
+ readonly thinkContent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
56
+ }, undefined>, v.TransformAction<{
57
+ role: "assistant";
58
+ content: {
59
+ text: string;
60
+ type: "text";
61
+ }[];
62
+ thinkContent?: string | undefined;
63
+ }, {
64
+ role: "model";
65
+ parts: {
66
+ text: string;
67
+ }[];
68
+ }>]>], undefined>, undefined>]>;
@@ -0,0 +1,3 @@
1
+ import { ChatModelOptions } from '../options.define';
2
+ import { OpenAIChat } from './openai';
3
+ export declare function createCompatibleFactory(options: ChatModelOptions): OpenAIChat;
@@ -0,0 +1,25 @@
1
+ import { OpenAI } from 'openai';
2
+ import { ChatBodyInput, ChatRequestOptions, ChatToolBodyInput } from '../type';
3
+ import { ChatModelOptions } from '../options.define';
4
+ export declare class OpenAIChat {
5
+ #private;
6
+ protected options: ChatModelOptions;
7
+ protected instance: OpenAI;
8
+ protected extraBody: {};
9
+ protected extraHeaders: {};
10
+ constructor(options: ChatModelOptions);
11
+ init(): void;
12
+ stream(input: ChatBodyInput, options?: ChatRequestOptions): AsyncGenerator<any, void, unknown>;
13
+ callTool(input: ChatToolBodyInput, options?: ChatRequestOptions): Promise<{
14
+ type: "function";
15
+ function: {
16
+ name: any;
17
+ arguments: Record<string, any> | undefined;
18
+ };
19
+ text?: undefined;
20
+ } | {
21
+ type: "text";
22
+ text: string;
23
+ function?: undefined;
24
+ }>;
25
+ }
@@ -0,0 +1,2 @@
1
+ export * from '../chat/message.define';
2
+ export * from '../chat/options.define';