@adaline/openai 0.8.0 → 0.9.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/dist/index.d.mts +74 -74
- package/dist/index.d.ts +74 -74
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -2220,7 +2220,7 @@ declare const OpenAIChatRequestMessage: z.ZodUnion<[z.ZodObject<{
|
|
|
2220
2220
|
type OpenAIChatRequestMessageType = z.infer<typeof OpenAIChatRequestMessage>;
|
|
2221
2221
|
declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
2222
2222
|
model: z.ZodOptional<z.ZodString>;
|
|
2223
|
-
messages: z.
|
|
2223
|
+
messages: z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
2224
2224
|
role: z.ZodLiteral<"system">;
|
|
2225
2225
|
content: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
|
|
2226
2226
|
text: z.ZodString;
|
|
@@ -2412,7 +2412,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2412
2412
|
content: string;
|
|
2413
2413
|
role: "tool";
|
|
2414
2414
|
tool_call_id: string;
|
|
2415
|
-
}>]>, "many"
|
|
2415
|
+
}>]>, "many">;
|
|
2416
2416
|
frequency_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
2417
2417
|
logprobs: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
2418
2418
|
top_logprobs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
@@ -2519,34 +2519,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2519
2519
|
type: "function";
|
|
2520
2520
|
}>]>>;
|
|
2521
2521
|
}, "strip", z.ZodTypeAny, {
|
|
2522
|
-
|
|
2523
|
-
top_p?: number | null | undefined;
|
|
2524
|
-
frequency_penalty?: number | null | undefined;
|
|
2525
|
-
presence_penalty?: number | null | undefined;
|
|
2526
|
-
seed?: number | null | undefined;
|
|
2527
|
-
logprobs?: boolean | null | undefined;
|
|
2528
|
-
top_logprobs?: number | null | undefined;
|
|
2529
|
-
response_format?: {
|
|
2530
|
-
type: "text" | "json_object";
|
|
2531
|
-
} | {
|
|
2532
|
-
type: "json_schema";
|
|
2533
|
-
json_schema: {
|
|
2534
|
-
name: string;
|
|
2535
|
-
description?: string | undefined;
|
|
2536
|
-
strict?: boolean | undefined;
|
|
2537
|
-
schema?: any;
|
|
2538
|
-
};
|
|
2539
|
-
} | undefined;
|
|
2540
|
-
tool_choice?: "auto" | "required" | "none" | {
|
|
2541
|
-
function: {
|
|
2542
|
-
name: string;
|
|
2543
|
-
};
|
|
2544
|
-
type: "function";
|
|
2545
|
-
} | undefined;
|
|
2546
|
-
max_tokens?: number | null | undefined;
|
|
2547
|
-
stop?: string | string[] | null | undefined;
|
|
2548
|
-
model?: string | undefined;
|
|
2549
|
-
messages?: ({
|
|
2522
|
+
messages: ({
|
|
2550
2523
|
content: string | {
|
|
2551
2524
|
type: "text";
|
|
2552
2525
|
text: string;
|
|
@@ -2582,17 +2555,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2582
2555
|
content: string;
|
|
2583
2556
|
role: "tool";
|
|
2584
2557
|
tool_call_id: string;
|
|
2585
|
-
})[]
|
|
2586
|
-
tools?: {
|
|
2587
|
-
function: {
|
|
2588
|
-
name: string;
|
|
2589
|
-
description?: string | undefined;
|
|
2590
|
-
strict?: boolean | undefined;
|
|
2591
|
-
parameters?: any;
|
|
2592
|
-
};
|
|
2593
|
-
type: "function";
|
|
2594
|
-
}[] | undefined;
|
|
2595
|
-
}, {
|
|
2558
|
+
})[];
|
|
2596
2559
|
temperature?: number | null | undefined;
|
|
2597
2560
|
top_p?: number | null | undefined;
|
|
2598
2561
|
frequency_penalty?: number | null | undefined;
|
|
@@ -2620,7 +2583,17 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2620
2583
|
max_tokens?: number | null | undefined;
|
|
2621
2584
|
stop?: string | string[] | null | undefined;
|
|
2622
2585
|
model?: string | undefined;
|
|
2623
|
-
|
|
2586
|
+
tools?: {
|
|
2587
|
+
function: {
|
|
2588
|
+
name: string;
|
|
2589
|
+
description?: string | undefined;
|
|
2590
|
+
strict?: boolean | undefined;
|
|
2591
|
+
parameters?: any;
|
|
2592
|
+
};
|
|
2593
|
+
type: "function";
|
|
2594
|
+
}[] | undefined;
|
|
2595
|
+
}, {
|
|
2596
|
+
messages: ({
|
|
2624
2597
|
content: string | {
|
|
2625
2598
|
type: "text";
|
|
2626
2599
|
text: string;
|
|
@@ -2656,17 +2629,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2656
2629
|
content: string;
|
|
2657
2630
|
role: "tool";
|
|
2658
2631
|
tool_call_id: string;
|
|
2659
|
-
})[]
|
|
2660
|
-
tools?: {
|
|
2661
|
-
function: {
|
|
2662
|
-
name: string;
|
|
2663
|
-
description?: string | undefined;
|
|
2664
|
-
strict?: boolean | undefined;
|
|
2665
|
-
parameters?: any;
|
|
2666
|
-
};
|
|
2667
|
-
type: "function";
|
|
2668
|
-
}[] | undefined;
|
|
2669
|
-
}>, {
|
|
2632
|
+
})[];
|
|
2670
2633
|
temperature?: number | null | undefined;
|
|
2671
2634
|
top_p?: number | null | undefined;
|
|
2672
2635
|
frequency_penalty?: number | null | undefined;
|
|
@@ -2694,7 +2657,17 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2694
2657
|
max_tokens?: number | null | undefined;
|
|
2695
2658
|
stop?: string | string[] | null | undefined;
|
|
2696
2659
|
model?: string | undefined;
|
|
2697
|
-
|
|
2660
|
+
tools?: {
|
|
2661
|
+
function: {
|
|
2662
|
+
name: string;
|
|
2663
|
+
description?: string | undefined;
|
|
2664
|
+
strict?: boolean | undefined;
|
|
2665
|
+
parameters?: any;
|
|
2666
|
+
};
|
|
2667
|
+
type: "function";
|
|
2668
|
+
}[] | undefined;
|
|
2669
|
+
}>, {
|
|
2670
|
+
messages: ({
|
|
2698
2671
|
content: string | {
|
|
2699
2672
|
type: "text";
|
|
2700
2673
|
text: string;
|
|
@@ -2730,17 +2703,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2730
2703
|
content: string;
|
|
2731
2704
|
role: "tool";
|
|
2732
2705
|
tool_call_id: string;
|
|
2733
|
-
})[]
|
|
2734
|
-
tools?: {
|
|
2735
|
-
function: {
|
|
2736
|
-
name: string;
|
|
2737
|
-
description?: string | undefined;
|
|
2738
|
-
strict?: boolean | undefined;
|
|
2739
|
-
parameters?: any;
|
|
2740
|
-
};
|
|
2741
|
-
type: "function";
|
|
2742
|
-
}[] | undefined;
|
|
2743
|
-
}, {
|
|
2706
|
+
})[];
|
|
2744
2707
|
temperature?: number | null | undefined;
|
|
2745
2708
|
top_p?: number | null | undefined;
|
|
2746
2709
|
frequency_penalty?: number | null | undefined;
|
|
@@ -2768,7 +2731,17 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2768
2731
|
max_tokens?: number | null | undefined;
|
|
2769
2732
|
stop?: string | string[] | null | undefined;
|
|
2770
2733
|
model?: string | undefined;
|
|
2771
|
-
|
|
2734
|
+
tools?: {
|
|
2735
|
+
function: {
|
|
2736
|
+
name: string;
|
|
2737
|
+
description?: string | undefined;
|
|
2738
|
+
strict?: boolean | undefined;
|
|
2739
|
+
parameters?: any;
|
|
2740
|
+
};
|
|
2741
|
+
type: "function";
|
|
2742
|
+
}[] | undefined;
|
|
2743
|
+
}, {
|
|
2744
|
+
messages: ({
|
|
2772
2745
|
content: string | {
|
|
2773
2746
|
type: "text";
|
|
2774
2747
|
text: string;
|
|
@@ -2804,7 +2777,34 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2804
2777
|
content: string;
|
|
2805
2778
|
role: "tool";
|
|
2806
2779
|
tool_call_id: string;
|
|
2807
|
-
})[]
|
|
2780
|
+
})[];
|
|
2781
|
+
temperature?: number | null | undefined;
|
|
2782
|
+
top_p?: number | null | undefined;
|
|
2783
|
+
frequency_penalty?: number | null | undefined;
|
|
2784
|
+
presence_penalty?: number | null | undefined;
|
|
2785
|
+
seed?: number | null | undefined;
|
|
2786
|
+
logprobs?: boolean | null | undefined;
|
|
2787
|
+
top_logprobs?: number | null | undefined;
|
|
2788
|
+
response_format?: {
|
|
2789
|
+
type: "text" | "json_object";
|
|
2790
|
+
} | {
|
|
2791
|
+
type: "json_schema";
|
|
2792
|
+
json_schema: {
|
|
2793
|
+
name: string;
|
|
2794
|
+
description?: string | undefined;
|
|
2795
|
+
strict?: boolean | undefined;
|
|
2796
|
+
schema?: any;
|
|
2797
|
+
};
|
|
2798
|
+
} | undefined;
|
|
2799
|
+
tool_choice?: "auto" | "required" | "none" | {
|
|
2800
|
+
function: {
|
|
2801
|
+
name: string;
|
|
2802
|
+
};
|
|
2803
|
+
type: "function";
|
|
2804
|
+
} | undefined;
|
|
2805
|
+
max_tokens?: number | null | undefined;
|
|
2806
|
+
stop?: string | string[] | null | undefined;
|
|
2807
|
+
model?: string | undefined;
|
|
2808
2808
|
tools?: {
|
|
2809
2809
|
function: {
|
|
2810
2810
|
name: string;
|
|
@@ -2856,8 +2856,8 @@ declare class BaseChatModel implements ChatModelV1<ChatModelSchemaType> {
|
|
|
2856
2856
|
getTokenCount(messages: MessageType[]): number;
|
|
2857
2857
|
transformModelRequest(request: OpenAIChatRequestType): {
|
|
2858
2858
|
modelName: string | undefined;
|
|
2859
|
-
config: ConfigType
|
|
2860
|
-
messages: MessageType[]
|
|
2859
|
+
config: ConfigType;
|
|
2860
|
+
messages: MessageType[];
|
|
2861
2861
|
tools: ToolType[] | undefined;
|
|
2862
2862
|
};
|
|
2863
2863
|
transformConfig(config: ConfigType, messages?: MessageType[], tools?: ToolType[]): ParamsType;
|
|
@@ -3005,19 +3005,19 @@ declare const OpenAIEmbeddingRequestInput: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z
|
|
|
3005
3005
|
type OpenAIEmbeddingRequestInputType = z.infer<typeof OpenAIEmbeddingRequestInput>;
|
|
3006
3006
|
declare const OpenAIEmbeddingRequest: z.ZodObject<{
|
|
3007
3007
|
model: z.ZodOptional<z.ZodString>;
|
|
3008
|
-
input: z.
|
|
3008
|
+
input: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodArray<z.ZodNumber, "many">]>, z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">]>;
|
|
3009
3009
|
encoding_format: z.ZodOptional<z.ZodEnum<["float", "base64"]>>;
|
|
3010
3010
|
dimensions: z.ZodOptional<z.ZodNumber>;
|
|
3011
3011
|
}, "strip", z.ZodTypeAny, {
|
|
3012
|
+
input: string | string[] | number[] | number[][];
|
|
3012
3013
|
encoding_format?: "float" | "base64" | undefined;
|
|
3013
3014
|
dimensions?: number | undefined;
|
|
3014
3015
|
model?: string | undefined;
|
|
3015
|
-
input?: string | string[] | number[] | number[][] | undefined;
|
|
3016
3016
|
}, {
|
|
3017
|
+
input: string | string[] | number[] | number[][];
|
|
3017
3018
|
encoding_format?: "float" | "base64" | undefined;
|
|
3018
3019
|
dimensions?: number | undefined;
|
|
3019
3020
|
model?: string | undefined;
|
|
3020
|
-
input?: string | string[] | number[] | number[][] | undefined;
|
|
3021
3021
|
}>;
|
|
3022
3022
|
type OpenAIEmbeddingRequestType = z.infer<typeof OpenAIEmbeddingRequest>;
|
|
3023
3023
|
|
|
@@ -3052,8 +3052,8 @@ declare class BaseEmbeddingModel implements EmbeddingModelV1<EmbeddingModelSchem
|
|
|
3052
3052
|
getTokenCount(requests: EmbeddingRequestsType): number;
|
|
3053
3053
|
transformModelRequest(request: any): {
|
|
3054
3054
|
modelName: string | undefined;
|
|
3055
|
-
config: ConfigType
|
|
3056
|
-
embeddingRequests: EmbeddingRequestsType
|
|
3055
|
+
config: ConfigType;
|
|
3056
|
+
embeddingRequests: EmbeddingRequestsType;
|
|
3057
3057
|
};
|
|
3058
3058
|
transformConfig(config: ConfigType, requests?: EmbeddingRequestsType): ParamsType;
|
|
3059
3059
|
transformEmbeddingRequests(requests: EmbeddingRequestsType): ParamsType;
|
package/dist/index.d.ts
CHANGED
|
@@ -2220,7 +2220,7 @@ declare const OpenAIChatRequestMessage: z.ZodUnion<[z.ZodObject<{
|
|
|
2220
2220
|
type OpenAIChatRequestMessageType = z.infer<typeof OpenAIChatRequestMessage>;
|
|
2221
2221
|
declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
2222
2222
|
model: z.ZodOptional<z.ZodString>;
|
|
2223
|
-
messages: z.
|
|
2223
|
+
messages: z.ZodArray<z.ZodUnion<[z.ZodObject<{
|
|
2224
2224
|
role: z.ZodLiteral<"system">;
|
|
2225
2225
|
content: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{
|
|
2226
2226
|
text: z.ZodString;
|
|
@@ -2412,7 +2412,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2412
2412
|
content: string;
|
|
2413
2413
|
role: "tool";
|
|
2414
2414
|
tool_call_id: string;
|
|
2415
|
-
}>]>, "many"
|
|
2415
|
+
}>]>, "many">;
|
|
2416
2416
|
frequency_penalty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
2417
2417
|
logprobs: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
2418
2418
|
top_logprobs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
@@ -2519,34 +2519,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2519
2519
|
type: "function";
|
|
2520
2520
|
}>]>>;
|
|
2521
2521
|
}, "strip", z.ZodTypeAny, {
|
|
2522
|
-
|
|
2523
|
-
top_p?: number | null | undefined;
|
|
2524
|
-
frequency_penalty?: number | null | undefined;
|
|
2525
|
-
presence_penalty?: number | null | undefined;
|
|
2526
|
-
seed?: number | null | undefined;
|
|
2527
|
-
logprobs?: boolean | null | undefined;
|
|
2528
|
-
top_logprobs?: number | null | undefined;
|
|
2529
|
-
response_format?: {
|
|
2530
|
-
type: "text" | "json_object";
|
|
2531
|
-
} | {
|
|
2532
|
-
type: "json_schema";
|
|
2533
|
-
json_schema: {
|
|
2534
|
-
name: string;
|
|
2535
|
-
description?: string | undefined;
|
|
2536
|
-
strict?: boolean | undefined;
|
|
2537
|
-
schema?: any;
|
|
2538
|
-
};
|
|
2539
|
-
} | undefined;
|
|
2540
|
-
tool_choice?: "auto" | "required" | "none" | {
|
|
2541
|
-
function: {
|
|
2542
|
-
name: string;
|
|
2543
|
-
};
|
|
2544
|
-
type: "function";
|
|
2545
|
-
} | undefined;
|
|
2546
|
-
max_tokens?: number | null | undefined;
|
|
2547
|
-
stop?: string | string[] | null | undefined;
|
|
2548
|
-
model?: string | undefined;
|
|
2549
|
-
messages?: ({
|
|
2522
|
+
messages: ({
|
|
2550
2523
|
content: string | {
|
|
2551
2524
|
type: "text";
|
|
2552
2525
|
text: string;
|
|
@@ -2582,17 +2555,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2582
2555
|
content: string;
|
|
2583
2556
|
role: "tool";
|
|
2584
2557
|
tool_call_id: string;
|
|
2585
|
-
})[]
|
|
2586
|
-
tools?: {
|
|
2587
|
-
function: {
|
|
2588
|
-
name: string;
|
|
2589
|
-
description?: string | undefined;
|
|
2590
|
-
strict?: boolean | undefined;
|
|
2591
|
-
parameters?: any;
|
|
2592
|
-
};
|
|
2593
|
-
type: "function";
|
|
2594
|
-
}[] | undefined;
|
|
2595
|
-
}, {
|
|
2558
|
+
})[];
|
|
2596
2559
|
temperature?: number | null | undefined;
|
|
2597
2560
|
top_p?: number | null | undefined;
|
|
2598
2561
|
frequency_penalty?: number | null | undefined;
|
|
@@ -2620,7 +2583,17 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2620
2583
|
max_tokens?: number | null | undefined;
|
|
2621
2584
|
stop?: string | string[] | null | undefined;
|
|
2622
2585
|
model?: string | undefined;
|
|
2623
|
-
|
|
2586
|
+
tools?: {
|
|
2587
|
+
function: {
|
|
2588
|
+
name: string;
|
|
2589
|
+
description?: string | undefined;
|
|
2590
|
+
strict?: boolean | undefined;
|
|
2591
|
+
parameters?: any;
|
|
2592
|
+
};
|
|
2593
|
+
type: "function";
|
|
2594
|
+
}[] | undefined;
|
|
2595
|
+
}, {
|
|
2596
|
+
messages: ({
|
|
2624
2597
|
content: string | {
|
|
2625
2598
|
type: "text";
|
|
2626
2599
|
text: string;
|
|
@@ -2656,17 +2629,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2656
2629
|
content: string;
|
|
2657
2630
|
role: "tool";
|
|
2658
2631
|
tool_call_id: string;
|
|
2659
|
-
})[]
|
|
2660
|
-
tools?: {
|
|
2661
|
-
function: {
|
|
2662
|
-
name: string;
|
|
2663
|
-
description?: string | undefined;
|
|
2664
|
-
strict?: boolean | undefined;
|
|
2665
|
-
parameters?: any;
|
|
2666
|
-
};
|
|
2667
|
-
type: "function";
|
|
2668
|
-
}[] | undefined;
|
|
2669
|
-
}>, {
|
|
2632
|
+
})[];
|
|
2670
2633
|
temperature?: number | null | undefined;
|
|
2671
2634
|
top_p?: number | null | undefined;
|
|
2672
2635
|
frequency_penalty?: number | null | undefined;
|
|
@@ -2694,7 +2657,17 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2694
2657
|
max_tokens?: number | null | undefined;
|
|
2695
2658
|
stop?: string | string[] | null | undefined;
|
|
2696
2659
|
model?: string | undefined;
|
|
2697
|
-
|
|
2660
|
+
tools?: {
|
|
2661
|
+
function: {
|
|
2662
|
+
name: string;
|
|
2663
|
+
description?: string | undefined;
|
|
2664
|
+
strict?: boolean | undefined;
|
|
2665
|
+
parameters?: any;
|
|
2666
|
+
};
|
|
2667
|
+
type: "function";
|
|
2668
|
+
}[] | undefined;
|
|
2669
|
+
}>, {
|
|
2670
|
+
messages: ({
|
|
2698
2671
|
content: string | {
|
|
2699
2672
|
type: "text";
|
|
2700
2673
|
text: string;
|
|
@@ -2730,17 +2703,7 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2730
2703
|
content: string;
|
|
2731
2704
|
role: "tool";
|
|
2732
2705
|
tool_call_id: string;
|
|
2733
|
-
})[]
|
|
2734
|
-
tools?: {
|
|
2735
|
-
function: {
|
|
2736
|
-
name: string;
|
|
2737
|
-
description?: string | undefined;
|
|
2738
|
-
strict?: boolean | undefined;
|
|
2739
|
-
parameters?: any;
|
|
2740
|
-
};
|
|
2741
|
-
type: "function";
|
|
2742
|
-
}[] | undefined;
|
|
2743
|
-
}, {
|
|
2706
|
+
})[];
|
|
2744
2707
|
temperature?: number | null | undefined;
|
|
2745
2708
|
top_p?: number | null | undefined;
|
|
2746
2709
|
frequency_penalty?: number | null | undefined;
|
|
@@ -2768,7 +2731,17 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2768
2731
|
max_tokens?: number | null | undefined;
|
|
2769
2732
|
stop?: string | string[] | null | undefined;
|
|
2770
2733
|
model?: string | undefined;
|
|
2771
|
-
|
|
2734
|
+
tools?: {
|
|
2735
|
+
function: {
|
|
2736
|
+
name: string;
|
|
2737
|
+
description?: string | undefined;
|
|
2738
|
+
strict?: boolean | undefined;
|
|
2739
|
+
parameters?: any;
|
|
2740
|
+
};
|
|
2741
|
+
type: "function";
|
|
2742
|
+
}[] | undefined;
|
|
2743
|
+
}, {
|
|
2744
|
+
messages: ({
|
|
2772
2745
|
content: string | {
|
|
2773
2746
|
type: "text";
|
|
2774
2747
|
text: string;
|
|
@@ -2804,7 +2777,34 @@ declare const OpenAIChatRequest: z.ZodEffects<z.ZodObject<{
|
|
|
2804
2777
|
content: string;
|
|
2805
2778
|
role: "tool";
|
|
2806
2779
|
tool_call_id: string;
|
|
2807
|
-
})[]
|
|
2780
|
+
})[];
|
|
2781
|
+
temperature?: number | null | undefined;
|
|
2782
|
+
top_p?: number | null | undefined;
|
|
2783
|
+
frequency_penalty?: number | null | undefined;
|
|
2784
|
+
presence_penalty?: number | null | undefined;
|
|
2785
|
+
seed?: number | null | undefined;
|
|
2786
|
+
logprobs?: boolean | null | undefined;
|
|
2787
|
+
top_logprobs?: number | null | undefined;
|
|
2788
|
+
response_format?: {
|
|
2789
|
+
type: "text" | "json_object";
|
|
2790
|
+
} | {
|
|
2791
|
+
type: "json_schema";
|
|
2792
|
+
json_schema: {
|
|
2793
|
+
name: string;
|
|
2794
|
+
description?: string | undefined;
|
|
2795
|
+
strict?: boolean | undefined;
|
|
2796
|
+
schema?: any;
|
|
2797
|
+
};
|
|
2798
|
+
} | undefined;
|
|
2799
|
+
tool_choice?: "auto" | "required" | "none" | {
|
|
2800
|
+
function: {
|
|
2801
|
+
name: string;
|
|
2802
|
+
};
|
|
2803
|
+
type: "function";
|
|
2804
|
+
} | undefined;
|
|
2805
|
+
max_tokens?: number | null | undefined;
|
|
2806
|
+
stop?: string | string[] | null | undefined;
|
|
2807
|
+
model?: string | undefined;
|
|
2808
2808
|
tools?: {
|
|
2809
2809
|
function: {
|
|
2810
2810
|
name: string;
|
|
@@ -2856,8 +2856,8 @@ declare class BaseChatModel implements ChatModelV1<ChatModelSchemaType> {
|
|
|
2856
2856
|
getTokenCount(messages: MessageType[]): number;
|
|
2857
2857
|
transformModelRequest(request: OpenAIChatRequestType): {
|
|
2858
2858
|
modelName: string | undefined;
|
|
2859
|
-
config: ConfigType
|
|
2860
|
-
messages: MessageType[]
|
|
2859
|
+
config: ConfigType;
|
|
2860
|
+
messages: MessageType[];
|
|
2861
2861
|
tools: ToolType[] | undefined;
|
|
2862
2862
|
};
|
|
2863
2863
|
transformConfig(config: ConfigType, messages?: MessageType[], tools?: ToolType[]): ParamsType;
|
|
@@ -3005,19 +3005,19 @@ declare const OpenAIEmbeddingRequestInput: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z
|
|
|
3005
3005
|
type OpenAIEmbeddingRequestInputType = z.infer<typeof OpenAIEmbeddingRequestInput>;
|
|
3006
3006
|
declare const OpenAIEmbeddingRequest: z.ZodObject<{
|
|
3007
3007
|
model: z.ZodOptional<z.ZodString>;
|
|
3008
|
-
input: z.
|
|
3008
|
+
input: z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodArray<z.ZodNumber, "many">]>, z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">]>;
|
|
3009
3009
|
encoding_format: z.ZodOptional<z.ZodEnum<["float", "base64"]>>;
|
|
3010
3010
|
dimensions: z.ZodOptional<z.ZodNumber>;
|
|
3011
3011
|
}, "strip", z.ZodTypeAny, {
|
|
3012
|
+
input: string | string[] | number[] | number[][];
|
|
3012
3013
|
encoding_format?: "float" | "base64" | undefined;
|
|
3013
3014
|
dimensions?: number | undefined;
|
|
3014
3015
|
model?: string | undefined;
|
|
3015
|
-
input?: string | string[] | number[] | number[][] | undefined;
|
|
3016
3016
|
}, {
|
|
3017
|
+
input: string | string[] | number[] | number[][];
|
|
3017
3018
|
encoding_format?: "float" | "base64" | undefined;
|
|
3018
3019
|
dimensions?: number | undefined;
|
|
3019
3020
|
model?: string | undefined;
|
|
3020
|
-
input?: string | string[] | number[] | number[][] | undefined;
|
|
3021
3021
|
}>;
|
|
3022
3022
|
type OpenAIEmbeddingRequestType = z.infer<typeof OpenAIEmbeddingRequest>;
|
|
3023
3023
|
|
|
@@ -3052,8 +3052,8 @@ declare class BaseEmbeddingModel implements EmbeddingModelV1<EmbeddingModelSchem
|
|
|
3052
3052
|
getTokenCount(requests: EmbeddingRequestsType): number;
|
|
3053
3053
|
transformModelRequest(request: any): {
|
|
3054
3054
|
modelName: string | undefined;
|
|
3055
|
-
config: ConfigType
|
|
3056
|
-
embeddingRequests: EmbeddingRequestsType
|
|
3055
|
+
config: ConfigType;
|
|
3056
|
+
embeddingRequests: EmbeddingRequestsType;
|
|
3057
3057
|
};
|
|
3058
3058
|
transformConfig(config: ConfigType, requests?: EmbeddingRequestsType): ParamsType;
|
|
3059
3059
|
transformEmbeddingRequests(requests: EmbeddingRequestsType): ParamsType;
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,12 @@ var zod = require('zod');
|
|
|
4
4
|
var provider = require('@adaline/provider');
|
|
5
5
|
var types = require('@adaline/types');
|
|
6
6
|
|
|
7
|
-
var et=Object.defineProperty,tt=Object.defineProperties;var ot=Object.getOwnPropertyDescriptors;var de=Object.getOwnPropertySymbols;var nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var at=(p,e)=>(e=Symbol[p])?e:Symbol.for("Symbol."+p);var ce=(p,e,o)=>e in p?et(p,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):p[e]=o,y=(p,e)=>{for(var o in e||(e={}))nt.call(e,o)&&ce(p,o,e[o]);if(de)for(var o of de(e))st.call(e,o)&&ce(p,o,e[o]);return p},_=(p,e)=>tt(p,ot(e));var R=(p,e,o)=>new Promise((t,n)=>{var s=i=>{try{r(o.next(i));}catch(c){n(c);}},l=i=>{try{r(o.throw(i));}catch(c){n(c);}},r=i=>i.done?t(i.value):Promise.resolve(i.value).then(s,l);r((o=o.apply(p,e)).next());}),rt=function(p,e){this[0]=p,this[1]=e;},ue=(p,e,o)=>{var t=(l,r,i,c)=>{try{var d=o[l](r),h=(r=d.value)instanceof rt,f=d.done;Promise.resolve(h?r[0]:r).then(g=>h?t(l==="return"?l:"next",r[1]?{done:g.done,value:g.value}:g,i,c):i({value:g,done:f})).catch(g=>t("throw",g,i,c));}catch(g){c(g);}},n=l=>s[l]=r=>new Promise((i,c)=>t(l,r,i,c)),s={};return o=o.apply(p,e),s[at("asyncIterator")]=()=>s,n("next"),n("throw"),n("return"),s};var B=provider.RangeConfigItem({param:"temperature",title:provider.CONFIG.TEMPERATURE.title,description:provider.CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),N=p=>provider.RangeConfigItem({param:"max_tokens",title:provider.CONFIG.MAX_TOKENS.title,description:provider.CONFIG.MAX_TOKENS.description,min:0,max:p,step:1,default:0}),G=p=>provider.MultiStringConfigItem({param:"stop",title:provider.CONFIG.STOP(p).title,description:provider.CONFIG.STOP(p).description,max:p}),K=provider.RangeConfigItem({param:"top_p",title:provider.CONFIG.TOP_P.title,description:provider.CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),V=provider.RangeConfigItem({param:"frequency_penalty",title:provider.CONFIG.FREQUENCY_PENALTY.title,description:provider.CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),H=provider.RangeConfigItem({param:"presence_penalty",title:provider.CONFIG.PRESENCE_PENALTY.title,description:provider.CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),J=provider.RangeConfigItem({param:"seed",title:"Seed",description:"This is in BETA. Set a seed to get reproducible results. Determinism is not guaranteed. Set to 0 to disable.",min:0,max:1e6,step:1,default:0}),W=provider.SelectBooleanConfigItem({param:"logprobs",title:"LogProbs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned.",default:!1}),Y=provider.RangeConfigItem({param:"top_logprobs",title:"Top logprobs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used.",min:0,max:20,step:1,default:0}),Z=provider.SelectStringConfigItem({param:"response_format",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt.",default:"text",choices:["text","json_object"]}),Q=provider.SelectStringConfigItem({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'none' means the model will not call a function. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","required","none"]});var q=(p,e)=>zod.z.object({temperature:B.schema,maxTokens:N(p).schema,stop:G(e).schema,topP:K.schema,frequencyPenalty:V.schema,presencePenalty:H.schema,seed:J.schema.transform(o=>o===0?void 0:o),logProbs:W.schema,topLogProbs:Y.schema,responseFormat:Z.schema,toolChoice:Q.schema}),w=(p,e)=>({temperature:B.def,maxTokens:N(p).def,stop:G(e).def,topP:K.def,frequencyPenalty:V.def,presencePenalty:H.def,seed:J.def,responseFormat:Z.def,logProbs:W.def,topLogProbs:Y.def,toolChoice:Q.def});var ct=["object","array","number","string","boolean","enum"],fe=zod.z.enum(ct),ut=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([fe,zod.z.array(zod.z.union([fe,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),ht=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(ut),additionalProperties:zod.z.literal(!1)}),ft=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:ht}).optional(),ge=provider.ObjectSchemaConfigItem({param:"response_schema",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema.",objectSchema:ft}),ye=provider.SelectStringConfigItem({param:"response_format",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to.",default:"text",choices:["text","json_object","json_schema"]}),be=(p,e)=>_(y({},w(p,e)),{responseFormat:ye.def,responseSchema:ge.def}),Te=(p,e)=>q(p,e).extend({responseFormat:ye.schema,responseSchema:ge.schema});var X=provider.SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),ee=provider.RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:1024,step:1,default:1024});var Ce=()=>zod.z.object({encodingFormat:X.schema,dimensions:ee.schema}),Me=()=>({encodingFormat:X.def,dimensions:ee.def});var te={base:(p,e)=>({def:w(p,e),schema:q(p,e)}),responseSchema:(p,e)=>({def:be(p,e),schema:Te(p,e)})},oe={base:()=>({def:Me(),schema:Ce()})};var Se=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),Ae={system:types.SystemRoleLiteral,user:types.UserRoleLiteral,assistant:types.AssistantRoleLiteral,tool:types.ToolRoleLiteral};var Pe=[types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],je=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var P=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),ve=zod.z.object({content:zod.z.array(P.extend({top_logprobs:zod.z.array(P)})).nullable(),refusal:zod.z.array(P.extend({top_logprobs:zod.z.array(P)})).nullable()}).nullable(),Mt=zod.z.array(zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["function"]),function:zod.z.object({name:zod.z.string(),arguments:zod.z.string()})})),ke=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string(),choices:zod.z.array(zod.z.object({index:zod.z.number(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Mt.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:ve,finish_reason:zod.z.string()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()})}),Rt=zod.z.array(zod.z.object({index:zod.z.number().int(),id:zod.z.string().min(1).optional(),type:zod.z.enum(["function"]).optional(),function:zod.z.object({name:zod.z.string().min(1).optional(),arguments:zod.z.string().optional()}).optional()})),Ue=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:Rt.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:ve,finish_reason:zod.z.string().nullable()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var Ot=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),parameters:zod.z.any()})}),It=zod.z.enum(["none","auto","required"]),Et=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),St=zod.z.object({type:zod.z.enum(["text","json_object"])}).or(zod.z.object({type:zod.z.literal("json_schema"),json_schema:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),schema:zod.z.any()})})),ne=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),At=zod.z.object({type:zod.z.literal("image_url"),image_url:zod.z.object({url:zod.z.string().url().min(1),detail:zod.z.enum(["low","high","auto"]).optional()})}),_t=zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),arguments:zod.z.string().min(1)})}),xt=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(ne).min(1))}),qt=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([ne,At])).min(1))}),wt=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(ne).min(1)).optional(),tool_calls:zod.z.array(_t).min(1).optional()}).refine(p=>!(!p.content&&!p.tool_calls),{message:"one of 'content' or 'tool_calls' must be provided",path:["content","tool_calls"]}),Pt=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),jt=zod.z.union([xt,qt,wt,Pt]),$e=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(jt).min(1).optional(),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.boolean().nullable().optional(),top_logprobs:zod.z.number().min(0).max(20).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:St.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Ot).optional(),tool_choice:It.or(Et).optional()}).refine(p=>!(p.tool_choice&&(!p.tools||p.tools.length===0)),{message:"'tools' must be provided if 'tool_choice' is provided",path:["tools"]});var re=zod.z.object({apiKey:zod.z.string(),baseUrl:zod.z.string().url(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),k=class{constructor(e,o){this.version="v1";let t=re.parse(o);this.modelSchema=e,this.apiKey=t.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(t.baseUrl),this.streamChatUrl=provider.urlWithoutTrailingSlash(t.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=provider.urlWithoutTrailingSlash(t.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=t.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return y({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let o=r=>{let i=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},d,h=0;for(;(d=i.exec(r))!==null;){let f=parseInt(d[1]),g=d[2];h+=f*c[g];}return h},t=0,n=0,s=!0;e["x-ratelimit-reset-requests"]&&(t=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(n=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(t,n);return {shouldRetry:s,delayMs:l}}getTokenCount(e){return e.reduce((o,t)=>o+t.content.map(n=>n.modality==="text"?n.value:"").join(" ").length,0)}transformModelRequest(e){let o=$e.safeParse(e);if(!o.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:o.error});let t=o.data,n=t.model,s={};t.response_format&&(s.responseFormat=t.response_format.type,t.response_format.type==="json_schema"&&(s.responseSchema={name:t.response_format.json_schema.name,description:t.response_format.json_schema.description||"",strict:t.response_format.json_schema.strict,schema:t.response_format.json_schema.schema})),t.tool_choice&&(typeof t.tool_choice=="string"?s.toolChoice=t.tool_choice:s.toolChoice=t.tool_choice.function.name),s.seed=t.seed,s.maxTokens=t.max_tokens,s.temperature=t.temperature,s.topP=t.top_p,s.presencePenalty=t.presence_penalty,s.frequencyPenalty=t.frequency_penalty,s.stop=t.stop,s.logProbs=t.logprobs,s.topLogProbs=t.top_logprobs;let l=types.Config().parse(provider.removeUndefinedEntries(s)),r=[],i={};t.messages&&t.messages.forEach(d=>{let h=d.role;switch(h){case"system":{let f=d.content;if(typeof f=="string")r.push({role:h,content:[{modality:types.TextModalityLiteral,value:f}]});else {let g=f.map(T=>({modality:types.TextModalityLiteral,value:T.text}));r.push({role:h,content:g});}}break;case"user":{let f=d.content;if(typeof f=="string")r.push({role:h,content:[{modality:types.TextModalityLiteral,value:f}]});else {let g=f.map(T=>T.type==="text"?{modality:types.TextModalityLiteral,value:T.text}:{modality:types.ImageModalityLiteral,detail:T.image_url.detail||"auto",value:{type:types.UrlImageContentTypeLiteral,url:T.image_url.url}});r.push({role:h,content:g});}}break;case"assistant":{let f=[];if(d.content){let g=d.content;typeof g=="string"?f.push({modality:types.TextModalityLiteral,value:g}):g.forEach(T=>{f.push({modality:types.TextModalityLiteral,value:T.text});});}d.tool_calls&&d.tool_calls.forEach((T,Xe)=>{let D={modality:types.ToolCallModalityLiteral,id:T.id,index:Xe,name:T.function.name,arguments:T.function.arguments};f.push(D),i[D.id]=D;}),r.push({role:h,content:f});}break;case"tool":{let f=d;r.push({role:h,content:[{modality:types.ToolResponseModalityLiteral,id:f.tool_call_id,index:i[f.tool_call_id].index,name:i[f.tool_call_id].name,data:f.content}]});}break}});let c=[];return t.tools&&t.tools.forEach(d=>{c.push({type:"function",definition:{schema:{name:d.function.name,description:d.function.description||"",strict:d.function.strict,parameters:d.function.parameters}}});}),{modelName:n,config:l,messages:r,tools:c}}transformConfig(e,o,t){let n=e.toolChoice;delete e.toolChoice;let s=this.modelSchema.config.schema.safeParse(e);if(!s.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:s.error});let l=s.data;n!==void 0&&(l.toolChoice=n),Object.keys(l).forEach(i=>{if(!(i in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${i}',
|
|
7
|
+
var et=Object.defineProperty,tt=Object.defineProperties;var ot=Object.getOwnPropertyDescriptors;var de=Object.getOwnPropertySymbols;var nt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var at=(p,e)=>(e=Symbol[p])?e:Symbol.for("Symbol."+p);var ce=(p,e,o)=>e in p?et(p,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):p[e]=o,y=(p,e)=>{for(var o in e||(e={}))nt.call(e,o)&&ce(p,o,e[o]);if(de)for(var o of de(e))st.call(e,o)&&ce(p,o,e[o]);return p},_=(p,e)=>tt(p,ot(e));var R=(p,e,o)=>new Promise((t,n)=>{var s=i=>{try{r(o.next(i));}catch(c){n(c);}},l=i=>{try{r(o.throw(i));}catch(c){n(c);}},r=i=>i.done?t(i.value):Promise.resolve(i.value).then(s,l);r((o=o.apply(p,e)).next());}),rt=function(p,e){this[0]=p,this[1]=e;},ue=(p,e,o)=>{var t=(l,r,i,c)=>{try{var d=o[l](r),h=(r=d.value)instanceof rt,f=d.done;Promise.resolve(h?r[0]:r).then(g=>h?t(l==="return"?l:"next",r[1]?{done:g.done,value:g.value}:g,i,c):i({value:g,done:f})).catch(g=>t("throw",g,i,c));}catch(g){c(g);}},n=l=>s[l]=r=>new Promise((i,c)=>t(l,r,i,c)),s={};return o=o.apply(p,e),s[at("asyncIterator")]=()=>s,n("next"),n("throw"),n("return"),s};var B=provider.RangeConfigItem({param:"temperature",title:provider.CONFIG.TEMPERATURE.title,description:provider.CONFIG.TEMPERATURE.description,min:0,max:2,step:.01,default:1}),N=p=>provider.RangeConfigItem({param:"max_tokens",title:provider.CONFIG.MAX_TOKENS.title,description:provider.CONFIG.MAX_TOKENS.description,min:0,max:p,step:1,default:0}),G=p=>provider.MultiStringConfigItem({param:"stop",title:provider.CONFIG.STOP(p).title,description:provider.CONFIG.STOP(p).description,max:p}),K=provider.RangeConfigItem({param:"top_p",title:provider.CONFIG.TOP_P.title,description:provider.CONFIG.TOP_P.description,min:0,max:1,step:.01,default:1}),V=provider.RangeConfigItem({param:"frequency_penalty",title:provider.CONFIG.FREQUENCY_PENALTY.title,description:provider.CONFIG.FREQUENCY_PENALTY.description,min:-2,max:2,step:.01,default:0}),H=provider.RangeConfigItem({param:"presence_penalty",title:provider.CONFIG.PRESENCE_PENALTY.title,description:provider.CONFIG.PRESENCE_PENALTY.description,min:-2,max:2,step:.01,default:0}),J=provider.RangeConfigItem({param:"seed",title:"Seed",description:"This is in BETA. Set a seed to get reproducible results. Determinism is not guaranteed. Set to 0 to disable.",min:0,max:1e6,step:1,default:0}),W=provider.SelectBooleanConfigItem({param:"logprobs",title:"LogProbs",description:"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned.",default:!1}),Y=provider.RangeConfigItem({param:"top_logprobs",title:"Top logprobs",description:"The number of most likely tokens to return at each token position, each with an associated log probability. 'logprobs' must be set to true if this parameter is used.",min:0,max:20,step:1,default:0}),Z=provider.SelectStringConfigItem({param:"response_format",title:"Response format",description:"Choose the response format of your model. For JSON, you must include the string 'JSON' in some form within your system / user prompt.",default:"text",choices:["text","json_object"]}),Q=provider.SelectStringConfigItem({param:"tool_choice",title:"Tool choice",description:"Controls which (if any) tool is called by the model. 'none' means the model will not call a function. 'auto' means the model can pick between generating a message or calling a tool.",default:"auto",choices:["auto","required","none"]});var q=(p,e)=>zod.z.object({temperature:B.schema,maxTokens:N(p).schema,stop:G(e).schema,topP:K.schema,frequencyPenalty:V.schema,presencePenalty:H.schema,seed:J.schema.transform(o=>o===0?void 0:o),logProbs:W.schema,topLogProbs:Y.schema,responseFormat:Z.schema,toolChoice:Q.schema}),w=(p,e)=>({temperature:B.def,maxTokens:N(p).def,stop:G(e).def,topP:K.def,frequencyPenalty:V.def,presencePenalty:H.def,seed:J.def,responseFormat:Z.def,logProbs:W.def,topLogProbs:Y.def,toolChoice:Q.def});var ct=["object","array","number","string","boolean","enum"],fe=zod.z.enum(ct),ut=zod.z.object({anyOf:zod.z.array(zod.z.any()).optional(),type:zod.z.union([fe,zod.z.array(zod.z.union([fe,zod.z.literal("null")]))]).optional(),default:zod.z.any().optional(),title:zod.z.string().optional(),description:zod.z.string().max(4096).optional(),properties:zod.z.record(zod.z.any()).optional(),required:zod.z.array(zod.z.string()).optional(),minItems:zod.z.number().int().min(0).optional(),maxItems:zod.z.number().int().optional(),items:zod.z.record(zod.z.any()).optional(),enum:zod.z.array(zod.z.union([zod.z.string(),zod.z.number(),zod.z.boolean(),zod.z.null()])).optional(),minimum:zod.z.number().optional(),maximum:zod.z.number().optional(),minLength:zod.z.number().int().min(0).optional(),maxLength:zod.z.number().int().optional(),$ref:zod.z.string().optional()}),ht=zod.z.object({type:zod.z.enum(["object"]),required:zod.z.array(zod.z.string()),$defs:zod.z.record(zod.z.any()).optional(),properties:zod.z.record(ut),additionalProperties:zod.z.literal(!1)}),ft=zod.z.object({name:zod.z.string().regex(/^[a-zA-Z0-9_]{1,64}$/).max(64),description:zod.z.string().max(4096),strict:zod.z.boolean().optional(),schema:ht}).optional(),ge=provider.ObjectSchemaConfigItem({param:"response_schema",title:"Response schema",description:"When response format is set to 'json_schema', the model will return a JSON object of the specified schema.",objectSchema:ft}),ye=provider.SelectStringConfigItem({param:"response_format",title:"Response format",description:"Choose the response format of your model. 'json_object' colloquially known as JSON mode, instructs the model to respond with a valid JSON (must include the term 'json' in prompt). 'json_schema' colloquially known as structured outputs, allows you to specify a strict response schema that the model will adhere to.",default:"text",choices:["text","json_object","json_schema"]}),be=(p,e)=>_(y({},w(p,e)),{responseFormat:ye.def,responseSchema:ge.def}),Te=(p,e)=>q(p,e).extend({responseFormat:ye.schema,responseSchema:ge.schema});var X=provider.SelectStringConfigItem({param:"encoding_format",title:"Encoding format",description:"Select the encoding format for the word embedding.",default:"float",choices:["float","base64"]}),ee=provider.RangeConfigItem({param:"dimensions",title:"Dimensions",description:"Select the number of dimensions for the word embedding.",min:1,max:1024,step:1,default:1024});var Ce=()=>zod.z.object({encodingFormat:X.schema,dimensions:ee.schema}),Me=()=>({encodingFormat:X.def,dimensions:ee.def});var te={base:(p,e)=>({def:w(p,e),schema:q(p,e)}),responseSchema:(p,e)=>({def:be(p,e),schema:Te(p,e)})},oe={base:()=>({def:Me(),schema:Ce()})};var Se=zod.z.enum([types.SystemRoleLiteral,types.UserRoleLiteral,types.AssistantRoleLiteral,types.ToolRoleLiteral]),Ae={system:types.SystemRoleLiteral,user:types.UserRoleLiteral,assistant:types.AssistantRoleLiteral,tool:types.ToolRoleLiteral};var Pe=[types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral],je=zod.z.enum([types.TextModalityLiteral,types.ImageModalityLiteral,types.ToolCallModalityLiteral,types.ToolResponseModalityLiteral]);var P=zod.z.object({token:zod.z.string(),logprob:zod.z.number(),bytes:zod.z.array(zod.z.number()).nullable()}),ve=zod.z.object({content:zod.z.array(P.extend({top_logprobs:zod.z.array(P)})).nullable(),refusal:zod.z.array(P.extend({top_logprobs:zod.z.array(P)})).nullable()}).nullable(),Mt=zod.z.array(zod.z.object({id:zod.z.string().min(1),type:zod.z.enum(["function"]),function:zod.z.object({name:zod.z.string(),arguments:zod.z.string()})})),ke=zod.z.object({id:zod.z.string(),object:zod.z.literal("chat.completion"),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string(),choices:zod.z.array(zod.z.object({index:zod.z.number(),message:zod.z.object({role:zod.z.string(),content:zod.z.string().nullable().optional(),tool_calls:Mt.optional(),refusal:zod.z.string().nullable().optional()}),logprobs:ve,finish_reason:zod.z.string()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()})}),Rt=zod.z.array(zod.z.object({index:zod.z.number().int(),id:zod.z.string().min(1).optional(),type:zod.z.enum(["function"]).optional(),function:zod.z.object({name:zod.z.string().min(1).optional(),arguments:zod.z.string().optional()}).optional()})),Ue=zod.z.object({id:zod.z.string(),object:zod.z.string(),created:zod.z.number(),model:zod.z.string(),system_fingerprint:zod.z.string().nullable(),choices:zod.z.array(zod.z.object({index:zod.z.number(),delta:zod.z.object({content:zod.z.string().nullable().optional(),tool_calls:Rt.optional(),refusal:zod.z.string().nullable().optional()}).or(zod.z.object({})),logprobs:ve,finish_reason:zod.z.string().nullable()})),usage:zod.z.object({prompt_tokens:zod.z.number(),completion_tokens:zod.z.number(),total_tokens:zod.z.number()}).nullable().optional()});var Ot=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),parameters:zod.z.any()})}),It=zod.z.enum(["none","auto","required"]),Et=zod.z.object({type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1)})}),St=zod.z.object({type:zod.z.enum(["text","json_object"])}).or(zod.z.object({type:zod.z.literal("json_schema"),json_schema:zod.z.object({name:zod.z.string().min(1),description:zod.z.string().min(1).optional(),strict:zod.z.boolean().optional(),schema:zod.z.any()})})),ne=zod.z.object({text:zod.z.string().min(1),type:zod.z.literal("text")}),At=zod.z.object({type:zod.z.literal("image_url"),image_url:zod.z.object({url:zod.z.string().url().min(1),detail:zod.z.enum(["low","high","auto"]).optional()})}),_t=zod.z.object({id:zod.z.string().min(1),type:zod.z.literal("function"),function:zod.z.object({name:zod.z.string().min(1),arguments:zod.z.string().min(1)})}),xt=zod.z.object({role:zod.z.literal("system"),content:zod.z.string().min(1).or(zod.z.array(ne).min(1))}),qt=zod.z.object({role:zod.z.literal("user"),content:zod.z.string().min(1).or(zod.z.array(zod.z.union([ne,At])).min(1))}),wt=zod.z.object({role:zod.z.literal("assistant"),content:zod.z.string().min(1).or(zod.z.array(ne).min(1)).optional(),tool_calls:zod.z.array(_t).min(1).optional()}).refine(p=>!(!p.content&&!p.tool_calls),{message:"one of 'content' or 'tool_calls' must be provided",path:["content","tool_calls"]}),Pt=zod.z.object({role:zod.z.literal("tool"),tool_call_id:zod.z.string().min(1),content:zod.z.string().min(1)}),jt=zod.z.union([xt,qt,wt,Pt]),$e=zod.z.object({model:zod.z.string().min(1).optional(),messages:zod.z.array(jt).min(1),frequency_penalty:zod.z.number().min(-2).max(2).nullable().optional(),logprobs:zod.z.boolean().nullable().optional(),top_logprobs:zod.z.number().min(0).max(20).nullable().optional(),max_tokens:zod.z.number().min(0).nullable().optional(),presence_penalty:zod.z.number().min(-2).max(2).nullable().optional(),response_format:St.optional(),seed:zod.z.number().nullable().optional(),stop:zod.z.string().or(zod.z.array(zod.z.string()).max(4)).nullable().optional(),temperature:zod.z.number().min(0).max(2).nullable().optional(),top_p:zod.z.number().min(0).max(1).nullable().optional(),tools:zod.z.array(Ot).optional(),tool_choice:It.or(Et).optional()}).refine(p=>!(p.tool_choice&&(!p.tools||p.tools.length===0)),{message:"'tools' must be provided if 'tool_choice' is provided",path:["tools"]});var re=zod.z.object({apiKey:zod.z.string(),baseUrl:zod.z.string().url(),completeChatUrl:zod.z.string().url().optional(),streamChatUrl:zod.z.string().url().optional(),organization:zod.z.string().optional()}),k=class{constructor(e,o){this.version="v1";let t=re.parse(o);this.modelSchema=e,this.apiKey=t.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(t.baseUrl),this.streamChatUrl=provider.urlWithoutTrailingSlash(t.streamChatUrl||`${this.baseUrl}/chat/completions`),this.completeChatUrl=provider.urlWithoutTrailingSlash(t.completeChatUrl||`${this.baseUrl}/chat/completions`),this.organization=t.organization;}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return y({Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},this.organization?{"OpenAI-Organization":this.organization}:{})}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let o=r=>{let i=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},d,h=0;for(;(d=i.exec(r))!==null;){let f=parseInt(d[1]),g=d[2];h+=f*c[g];}return h},t=0,n=0,s=!0;e["x-ratelimit-reset-requests"]&&(t=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(n=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(t,n);return {shouldRetry:s,delayMs:l}}getTokenCount(e){return e.reduce((o,t)=>o+t.content.map(n=>n.modality==="text"?n.value:"").join(" ").length,0)}transformModelRequest(e){let o=$e.safeParse(e);if(!o.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:o.error});let t=o.data,n=t.model,s={};t.response_format&&(s.responseFormat=t.response_format.type,t.response_format.type==="json_schema"&&(s.responseSchema={name:t.response_format.json_schema.name,description:t.response_format.json_schema.description||"",strict:t.response_format.json_schema.strict,schema:t.response_format.json_schema.schema})),t.tool_choice&&(typeof t.tool_choice=="string"?s.toolChoice=t.tool_choice:s.toolChoice=t.tool_choice.function.name),s.seed=t.seed,s.maxTokens=t.max_tokens,s.temperature=t.temperature,s.topP=t.top_p,s.presencePenalty=t.presence_penalty,s.frequencyPenalty=t.frequency_penalty,s.stop=t.stop,s.logProbs=t.logprobs,s.topLogProbs=t.top_logprobs;let l=types.Config().parse(provider.removeUndefinedEntries(s)),r=[],i={};t.messages.forEach(d=>{let h=d.role;switch(h){case"system":{let f=d.content;if(typeof f=="string")r.push({role:h,content:[{modality:types.TextModalityLiteral,value:f}]});else {let g=f.map(T=>({modality:types.TextModalityLiteral,value:T.text}));r.push({role:h,content:g});}}break;case"user":{let f=d.content;if(typeof f=="string")r.push({role:h,content:[{modality:types.TextModalityLiteral,value:f}]});else {let g=f.map(T=>T.type==="text"?{modality:types.TextModalityLiteral,value:T.text}:{modality:types.ImageModalityLiteral,detail:T.image_url.detail||"auto",value:{type:types.UrlImageContentTypeLiteral,url:T.image_url.url}});r.push({role:h,content:g});}}break;case"assistant":{let f=[];if(d.content){let g=d.content;typeof g=="string"?f.push({modality:types.TextModalityLiteral,value:g}):g.forEach(T=>{f.push({modality:types.TextModalityLiteral,value:T.text});});}d.tool_calls&&d.tool_calls.forEach((T,Xe)=>{let D={modality:types.ToolCallModalityLiteral,id:T.id,index:Xe,name:T.function.name,arguments:T.function.arguments};f.push(D),i[D.id]=D;}),r.push({role:h,content:f});}break;case"tool":{let f=d;r.push({role:h,content:[{modality:types.ToolResponseModalityLiteral,id:f.tool_call_id,index:i[f.tool_call_id].index,name:i[f.tool_call_id].name,data:f.content}]});}break}});let c=[];return t.tools&&t.tools.forEach(d=>{c.push({type:"function",definition:{schema:{name:d.function.name,description:d.function.description||"",strict:d.function.strict,parameters:d.function.parameters}}});}),{modelName:n,config:l,messages:r,tools:c.length>0?c:void 0}}transformConfig(e,o,t){let n=e.toolChoice;delete e.toolChoice;let s=this.modelSchema.config.schema.safeParse(e);if(!s.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:s.error});let l=s.data;n!==void 0&&(l.toolChoice=n),Object.keys(l).forEach(i=>{if(!(i in this.modelSchema.config.def))throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${i}',
|
|
8
8
|
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})});let r=Object.keys(l).reduce((i,c)=>{let d=this.modelSchema.config.def[c],h=d.param,f=l[c];return h==="max_tokens"&&d.type==="range"&&f===0?i[h]=d.max:i[h]=f,i},{});if("tool_choice"in r&&r.tool_choice!==void 0){let i=r.tool_choice;if(!t||t&&t.length===0)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'tools' are required when 'toolChoice' is specified")});if(t&&t.length>0){let c=this.modelSchema.config.def.toolChoice;if(!c.choices.includes(i))if(t.map(d=>d.definition.schema.name).includes(i))r.tool_choice={type:"function",function:{name:i}};else throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`toolChoice : '${i}' is not part of provided 'tools' names or
|
|
9
9
|
one of [${c.choices.join(", ")}]`)})}}if("response_format"in r&&r.response_format!==void 0){let i=r.response_format;if(i==="json_schema")if("response_schema"in r)r.response_format={type:"json_schema",json_schema:r.response_schema},delete r.response_schema;else throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error("'responseSchema' is required in config when 'responseFormat' is 'json_schema'")});else r.response_format={type:i};}return r}transformMessages(e){if(!e||e&&e.length===0)return {messages:[]};let o=e.map(n=>{let s=types.Message().safeParse(n);if(!s.success)throw new provider.InvalidMessagesError({info:"Invalid messages",cause:s.error});return s.data});return o.forEach(n=>{n.content.forEach(s=>{if(!this.modelSchema.modalities.includes(s.modality))throw new provider.InvalidMessagesError({info:`Invalid message content for model : '${this.modelSchema.name}'`,cause:new Error(`model : '${this.modelSchema.name}' does not support modality : '${s.modality}',
|
|
10
10
|
available modalities : [${this.modelSchema.modalities.join(", ")}]`)})});}),{messages:o.map(n=>{switch(n.role){case types.SystemRoleLiteral:{let s=[];return n.content.forEach(l=>{if(l.modality===types.TextModalityLiteral)s.push({type:"text",text:l.value});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${l.modality}'`)})}),{role:this.modelSchema.roles[n.role],content:s}}case types.AssistantRoleLiteral:{let s=[],l=[];return n.content.forEach(r=>{if(r.modality===types.TextModalityLiteral)s.push({type:"text",text:r.value});else if(r.modality===types.ToolCallModalityLiteral)l.push({id:r.id,type:"function",function:{name:r.name,arguments:r.arguments}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${r.modality}'`)})}),y({role:this.modelSchema.roles[n.role],content:s},l.length>0?{tool_calls:l}:{})}case types.UserRoleLiteral:{let s=[],l=[];n.content.forEach(i=>{if(i.modality===types.TextModalityLiteral)s.push({type:"text",text:i.value});else if(i.modality===types.ImageModalityLiteral)l.push({type:"image_url",image_url:{url:i.value.type==="url"?i.value.url:i.value.base64,detail:i.detail}});else throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${n.role}' cannot have content with modality : '${i.modality}'`)})});let r=[...s,...l];return {role:this.modelSchema.roles[n.role],content:r}}case types.ToolRoleLiteral:{if(n.content.length!==1)throw new provider.InvalidMessagesError({info:`Invalid message for role : '${n.role}'`,cause:new Error(`role : '${n.role}' must have exactly one content item`)});if(n.content[0].modality!==types.ToolResponseModalityLiteral)throw new provider.InvalidMessagesError({info:`Invalid message 'role' and 'modality' combination for model : ${this.modelSchema.name}`,cause:new Error(`role : '${n.role}' must have content with modality : '${types.ToolResponseModalityLiteral}'`)});let s=n.content[0];return {role:this.modelSchema.roles[n.role],tool_call_id:s.id,content:s.data}}default:throw new provider.InvalidMessagesError({info:`Invalid message 'role' for model : ${this.modelSchema.name}`,cause:new Error(`role : '${n.role}' is not supported,
|
|
11
11
|
available roles : [${Object.keys(this.modelSchema.roles).join(", ")}]`)})}})}}transformTools(e){if(!this.modelSchema.modalities.includes(types.ToolCallModalityLiteral))throw new provider.InvalidToolsError({info:`Invalid tool 'modality' for model : ${this.modelSchema.name}`,cause:new Error(`model : '${this.modelSchema.name}' does not support tool modality : '${types.ToolCallModalityLiteral}'`)});return !e||e&&e.length===0?{tools:[]}:{tools:e.map(n=>{let s=types.Tool().safeParse(n);if(!s.success)throw new provider.InvalidToolsError({info:"Invalid tools",cause:s.error});return s.data}).map(n=>({type:"function",function:n.definition.schema}))}}getCompleteChatUrl(e,o,t){return R(this,null,function*(){return new Promise(n=>{n(this.completeChatUrl);})})}getCompleteChatHeaders(e,o,t){return R(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getCompleteChatData(e,o,t){return R(this,null,function*(){let n=this.transformConfig(e,o,t),s=this.transformMessages(o);if(s.messages&&s.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let l=t?this.transformTools(t):{};return new Promise(r=>{r(y(y(y(y({},this.getDefaultParams()),n),s),l));})})}transformCompleteChatResponse(e){let o=ke.safeParse(e);if(o.success){if(o.data.choices.length===0)throw new provider.ModelResponseError({info:"Invalid response from model",cause:new Error(`No choices in response : ${JSON.stringify(o.data)}`)});let t=o.data,n=[],s=t.choices[0].message;s.content&&n.push(types.createTextMessage(types.AssistantRoleLiteral,s.content)),s.refusal&&n.push(types.createTextMessage(types.AssistantRoleLiteral,s.refusal)),s.tool_calls&&s.tool_calls.forEach((c,d)=>{n.push(types.createToolCallMessage(types.AssistantRoleLiteral,d,c.id,c.function.name,c.function.arguments));});let l={promptTokens:t.usage.prompt_tokens,completionTokens:t.usage.completion_tokens,totalTokens:t.usage.total_tokens},r=[],i=t.choices[0].logprobs;return i&&(i.content&&r.push(...i.content.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(d=>({token:d.token,logProb:d.logprob,bytes:d.bytes}))}))),i.refusal&&r.push(...i.refusal.map(c=>({token:c.token,logProb:c.logprob,bytes:c.bytes,topLogProbs:c.top_logprobs.map(d=>({token:d.token,logProb:d.logprob,bytes:d.bytes}))})))),{messages:n,usage:l,logProbs:r}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:o.error})}getStreamChatUrl(e,o,t){return R(this,null,function*(){return new Promise(n=>{n(this.streamChatUrl);})})}getStreamChatHeaders(e,o,t){return R(this,null,function*(){return new Promise(n=>{n(this.getDefaultHeaders());})})}getStreamChatData(e,o,t){return R(this,null,function*(){let n=this.transformConfig(e,o,t),s=this.transformMessages(o);if(s.messages&&s.messages.length===0)throw new provider.InvalidMessagesError({info:"Messages are required",cause:new Error("Messages are required")});let l=t?this.transformTools(t):{};return new Promise(r=>{r(y(y(y(y({stream:!0,stream_options:{include_usage:!0}},this.getDefaultParams()),n),s),l));})})}transformStreamChatResponseChunk(e,o){return ue(this,null,function*(){var n,s;let t=(o+e).split(`
|
|
12
|
-
`).filter(l=>l.trim()!=="");for(let l of t){if(l==="data: [DONE]")return;if(l.startsWith("data: {")&&l.endsWith("}")){let r;try{r=JSON.parse(l.substring(6));}catch(c){throw new provider.ModelResponseError({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${r}`)})}let i=Ue.safeParse(r);if(i.success){let c={partialMessages:[]},d=i.data;if(d.choices.length>0){let h=d.choices[0].delta;if(h!==void 0&&Object.keys(h).length!==0){if("content"in h&&h.content!==null)c.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,h.content));else if("refusal"in h&&h.refusal!==null)c.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,h.refusal));else if("tool_calls"in h&&h.tool_calls!==void 0){let f=h.tool_calls.at(0);c.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,f.index,f.id,(n=f.function)==null?void 0:n.name,(s=f.function)==null?void 0:s.arguments));}}}d.usage&&(c.usage={promptTokens:d.usage.prompt_tokens,completionTokens:d.usage.completion_tokens,totalTokens:d.usage.total_tokens}),yield {partialResponse:c,buffer:o};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:i.error})}}})}};var Vt="gpt-4o",Ht="GPT-4o is a large-scale multimodal model trained by OpenAI. It is the successor to GPT-4 and is designed to be more powerful and capable than its predecessor.",ie=provider.ChatModelSchema(Se,je).parse({name:Vt,description:Ht,maxInputTokens:128e3,maxOutputTokens:128e3,roles:Ae,modalities:Pe,config:{def:te.base(128e3,4).def,schema:te.base(128e3,4).schema}}),Be=re,U=class extends k{constructor(e){super(ie,e);}};var Ke=[types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral],Ve=zod.z.enum([types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral]);var He=zod.z.object({object:zod.z.literal("list"),model:zod.z.string(),data:zod.z.array(zod.z.object({index:zod.z.number(),object:zod.z.literal("embedding"),embedding:zod.z.array(zod.z.number()).or(zod.z.string().base64())})),usage:zod.z.object({prompt_tokens:zod.z.number().nonnegative(),total_tokens:zod.z.number().nonnegative()})});var Wt=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)).or(zod.z.array(zod.z.number().int().nonnegative()).min(1)).or(zod.z.array(zod.z.array(zod.z.number().int().nonnegative()).min(1)).min(1)),Je=zod.z.object({model:zod.z.string().min(1).optional(),input:Wt
|
|
12
|
+
`).filter(l=>l.trim()!=="");for(let l of t){if(l==="data: [DONE]")return;if(l.startsWith("data: {")&&l.endsWith("}")){let r;try{r=JSON.parse(l.substring(6));}catch(c){throw new provider.ModelResponseError({info:"Malformed JSON received in stream",cause:new Error(`Malformed JSON received in stream : ${r}`)})}let i=Ue.safeParse(r);if(i.success){let c={partialMessages:[]},d=i.data;if(d.choices.length>0){let h=d.choices[0].delta;if(h!==void 0&&Object.keys(h).length!==0){if("content"in h&&h.content!==null)c.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,h.content));else if("refusal"in h&&h.refusal!==null)c.partialMessages.push(types.createPartialTextMessage(types.AssistantRoleLiteral,h.refusal));else if("tool_calls"in h&&h.tool_calls!==void 0){let f=h.tool_calls.at(0);c.partialMessages.push(types.createPartialToolCallMessage(types.AssistantRoleLiteral,f.index,f.id,(n=f.function)==null?void 0:n.name,(s=f.function)==null?void 0:s.arguments));}}}d.usage&&(c.usage={promptTokens:d.usage.prompt_tokens,completionTokens:d.usage.completion_tokens,totalTokens:d.usage.total_tokens}),yield {partialResponse:c,buffer:o};}else throw new provider.ModelResponseError({info:"Invalid response from model",cause:i.error})}}})}};var Vt="gpt-4o",Ht="GPT-4o is a large-scale multimodal model trained by OpenAI. It is the successor to GPT-4 and is designed to be more powerful and capable than its predecessor.",ie=provider.ChatModelSchema(Se,je).parse({name:Vt,description:Ht,maxInputTokens:128e3,maxOutputTokens:128e3,roles:Ae,modalities:Pe,config:{def:te.base(128e3,4).def,schema:te.base(128e3,4).schema}}),Be=re,U=class extends k{constructor(e){super(ie,e);}};var Ke=[types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral],Ve=zod.z.enum([types.EmbeddingTextModalityLiteral,types.EmbeddingTokenModalityLiteral]);var He=zod.z.object({object:zod.z.literal("list"),model:zod.z.string(),data:zod.z.array(zod.z.object({index:zod.z.number(),object:zod.z.literal("embedding"),embedding:zod.z.array(zod.z.number()).or(zod.z.string().base64())})),usage:zod.z.object({prompt_tokens:zod.z.number().nonnegative(),total_tokens:zod.z.number().nonnegative()})});var Wt=zod.z.string().min(1).or(zod.z.array(zod.z.string().min(1)).min(1)).or(zod.z.array(zod.z.number().int().nonnegative()).min(1)).or(zod.z.array(zod.z.array(zod.z.number().int().nonnegative()).min(1)).min(1)),Je=zod.z.object({model:zod.z.string().min(1).optional(),input:Wt,encoding_format:zod.z.enum(["float","base64"]).optional(),dimensions:zod.z.number().int().min(1).optional()});var me=zod.z.object({apiKey:zod.z.string(),baseUrl:zod.z.string().url(),getEmbeddingsUrl:zod.z.string().url().optional()}),F=class{constructor(e,o){this.version="v1";let t=me.parse(o);this.modelSchema=e,this.apiKey=t.apiKey,this.baseUrl=provider.urlWithoutTrailingSlash(t.baseUrl),this.getEmbeddingsUrl=provider.urlWithoutTrailingSlash(t.getEmbeddingsUrl||`${this.baseUrl}/embeddings`);}getDefaultBaseUrl(){return this.baseUrl}getDefaultHeaders(){return {Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}getDefaultParams(){return {model:this.modelSchema.name}}getRetryDelay(e){let o=r=>{let i=/(\d+)(h|m|s|ms)/g,c={h:36e5,m:6e4,s:1e3,ms:1},d,h=0;for(;(d=i.exec(r))!==null;){let f=parseInt(d[1]),g=d[2];h+=f*c[g];}return h},t=0,n=0,s=!0;e["x-ratelimit-reset-requests"]&&(t=o(e["x-ratelimit-reset-requests"])),e["x-ratelimit-reset-tokens"]&&(n=o(e["x-ratelimit-reset-tokens"]));let l=Math.max(t,n);return {shouldRetry:s,delayMs:l}}getTokenCount(e){return e.requests.reduce((o,t)=>o+t.length,0)}transformModelRequest(e){let o=Je.safeParse(e);if(!o.success)throw new provider.InvalidModelRequestError({info:"Invalid model request",cause:o.error});let t=o.data,n=t.model,s={encodingFormat:t.encoding_format,dimensions:t.dimensions},l=types.Config().parse(provider.removeUndefinedEntries(s)),r,i;return typeof t.input=="string"?i=types.EmbeddingTextModalityLiteral:typeof t.input[0]=="string"?i=types.EmbeddingTextModalityLiteral:i=types.EmbeddingTokenModalityLiteral,i===types.EmbeddingTextModalityLiteral?typeof t.input=="string"?r={modality:i,requests:[t.input]}:r={modality:i,requests:t.input}:typeof t.input[0]=="number"?r={modality:i,requests:[t.input]}:r={modality:i,requests:t.input},{modelName:n,config:l,embeddingRequests:r}}transformConfig(e,o){let t=this.modelSchema.config.schema.safeParse(e);if(!t.success)throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:t.error});let n=t.data;return Object.keys(n).forEach(l=>{if(!this.modelSchema.config.def[l])throw new provider.InvalidConfigError({info:`Invalid config for model : '${this.modelSchema.name}'`,cause:new Error(`Invalid config key : '${l}',
|
|
13
13
|
available keys : [${Object.keys(this.modelSchema.config.def).join(", ")}]`)})}),Object.keys(n).reduce((l,r)=>{let c=this.modelSchema.config.def[r].param,d=n[r];return l[c]=d,l},{})}transformEmbeddingRequests(e){let o=types.EmbeddingRequests().safeParse(e);if(!o.success)throw new provider.InvalidEmbeddingRequestsError({info:"Invalid embedding requests",cause:o.error});return {input:o.data.requests}}getGetEmbeddingsUrl(e,o){return R(this,null,function*(){return new Promise(t=>{t(this.getEmbeddingsUrl);})})}getGetEmbeddingsHeaders(e,o){return R(this,null,function*(){return new Promise(t=>{t(this.getDefaultHeaders());})})}getGetEmbeddingsData(e,o){return R(this,null,function*(){return new Promise(t=>{t(y(y(y({},this.getDefaultParams()),this.transformConfig(e,o)),this.transformEmbeddingRequests(o)));})})}transformGetEmbeddingsResponse(e){let o,t=He.safeParse(e);if(t.success){let n=t.data;o=typeof n.data[0].embedding=="string"?types.Base64EmbeddingLiteral:types.FloatEmbeddingLiteral;let s=n.data.map(l=>typeof l.embedding=="string"?{index:l.index,embedding:l.embedding}:{index:l.index,embedding:l.embedding});return {encodingFormat:o,embeddings:s,usage:{totalTokens:n.usage.total_tokens}}}throw new provider.ModelResponseError({info:"Invalid response from model",cause:t.error})}};var ro="text-embedding-ada-002",io="some description",pe=provider.EmbeddingModelSchema(Ve).parse({name:ro,description:io,modalities:Ke,maxInputTokens:8192,maxOutputTokens:8192,config:{def:oe.base().def,schema:oe.base().schema}}),Ze=me,L=class extends F{constructor(e){super(pe,e);}};var lo="openai",Qe=class{constructor(){this.version="v1";this.name=lo;this.baseUrl="https://api.openai.com/v1";this.chatModelFactories={"gpt-4o":{model:U,modelOptions:Be,modelSchema:ie}};this.embeddingModelFactories={"text-embedding-ada-002":{model:L,modelOptions:Ze,modelSchema:pe}};}chatModelLiterals(){return Object.keys(this.chatModelFactories)}chatModel(e,o){var l;if(!(e in this.chatModelFactories))throw new provider.ProviderError({info:`OpenAI chat model: ${e} not found`,cause:new Error(`OpenAI chat model: ${e} not found, available chat models:
|
|
14
14
|
${this.chatModelLiterals().join(", ")}`)});let t=this.chatModelFactories[e].model,n=_(y({},o),{baseUrl:(l=o.baseUrl)!=null?l:this.baseUrl}),s=this.chatModelFactories[e].modelOptions.parse(n);return new t(s)}chatModelSchema(e){if(!(e in this.chatModelFactories))throw new provider.ProviderError({info:`OpenAI chat model: ${e} not found`,cause:new Error(`OpenAI chat model: ${e} not found, available chat models:
|
|
15
15
|
${this.chatModelLiterals().join(", ")}`)});return this.chatModelFactories[e].modelSchema}chatModelSchemas(){return Object.keys(this.chatModelFactories).reduce((e,o)=>(e[o]=this.chatModelFactories[o].modelSchema,e),{})}embeddingModelLiterals(){return Object.keys(this.embeddingModelFactories)}embeddingModel(e,o){var l;if(!(e in this.embeddingModelFactories))throw new provider.ProviderError({info:`OpenAI embedding model: ${e} not found`,cause:new Error(`OpenAI embedding model: ${e} not found, available embedding models:
|