modelfusion 0.107.0 → 0.109.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +11 -10
  3. package/model-provider/llamacpp/LlamaCppCompletionModel.cjs +17 -3
  4. package/model-provider/llamacpp/LlamaCppCompletionModel.d.ts +99 -12
  5. package/model-provider/llamacpp/LlamaCppCompletionModel.js +17 -3
  6. package/model-provider/openai/AbstractOpenAIChatModel.cjs +2 -10
  7. package/model-provider/openai/AbstractOpenAIChatModel.d.ts +5 -187
  8. package/model-provider/openai/AbstractOpenAIChatModel.js +2 -10
  9. package/model-provider/openai/AbstractOpenAICompletionModel.cjs +167 -0
  10. package/model-provider/openai/AbstractOpenAICompletionModel.d.ts +199 -0
  11. package/model-provider/openai/AbstractOpenAICompletionModel.js +163 -0
  12. package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.d.ts +0 -2
  13. package/model-provider/openai/OpenAIChatModel.d.ts +3 -6
  14. package/model-provider/openai/OpenAICompletionModel.cjs +4 -156
  15. package/model-provider/openai/OpenAICompletionModel.d.ts +4 -191
  16. package/model-provider/openai/OpenAICompletionModel.js +3 -155
  17. package/model-provider/openai/index.cjs +1 -0
  18. package/model-provider/openai/index.d.ts +1 -0
  19. package/model-provider/openai/index.js +1 -0
  20. package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +4 -5
  21. package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.cjs +74 -0
  22. package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.d.ts +27 -0
  23. package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.js +70 -0
  24. package/model-provider/openai-compatible/OpenAICompatibleFacade.cjs +37 -6
  25. package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +33 -5
  26. package/model-provider/openai-compatible/OpenAICompatibleFacade.js +35 -5
  27. package/model-provider/openai-compatible/OpenAICompatibleProviderName.cjs +2 -0
  28. package/model-provider/openai-compatible/OpenAICompatibleProviderName.d.ts +1 -0
  29. package/model-provider/openai-compatible/OpenAICompatibleProviderName.js +1 -0
  30. package/model-provider/openai-compatible/TogetherAIApiConfiguration.cjs +29 -0
  31. package/model-provider/openai-compatible/TogetherAIApiConfiguration.d.ts +18 -0
  32. package/model-provider/openai-compatible/TogetherAIApiConfiguration.js +25 -0
  33. package/model-provider/openai-compatible/index.cjs +4 -1
  34. package/model-provider/openai-compatible/index.d.ts +4 -1
  35. package/model-provider/openai-compatible/index.js +4 -1
  36. package/package.json +1 -1
@@ -7,7 +7,7 @@ import { TextGenerationModelSettings } from "../../model-function/generate-text/
7
7
  import { TextGenerationFinishReason } from "../../model-function/generate-text/TextGenerationResult.js";
8
8
  import { ToolDefinition } from "../../tool/ToolDefinition.js";
9
9
  import { OpenAIChatMessage } from "./OpenAIChatMessage.js";
10
- export interface AbstractOpenAIChatCallSettings {
10
+ export interface AbstractOpenAIChatSettings extends TextGenerationModelSettings {
11
11
  api?: ApiConfiguration;
12
12
  model: string;
13
13
  functions?: Array<{
@@ -72,8 +72,6 @@ export interface AbstractOpenAIChatCallSettings {
72
72
  type?: "text" | "json_object";
73
73
  };
74
74
  logitBias?: Record<number, number>;
75
- }
76
- export interface AbstractOpenAIChatSettings extends TextGenerationModelSettings, AbstractOpenAIChatCallSettings {
77
75
  isUserIdForwardingEnabled?: boolean;
78
76
  }
79
77
  export type OpenAIChatPrompt = OpenAIChatMessage[];
@@ -87,10 +85,10 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
87
85
  callAPI<RESULT>(messages: OpenAIChatPrompt, options: {
88
86
  responseFormat: OpenAIChatResponseFormatType<RESULT>;
89
87
  } & FunctionOptions & {
90
- functions?: AbstractOpenAIChatCallSettings["functions"];
91
- functionCall?: AbstractOpenAIChatCallSettings["functionCall"];
92
- tools?: AbstractOpenAIChatCallSettings["tools"];
93
- toolChoice?: AbstractOpenAIChatCallSettings["toolChoice"];
88
+ functions?: AbstractOpenAIChatSettings["functions"];
89
+ functionCall?: AbstractOpenAIChatSettings["functionCall"];
90
+ tools?: AbstractOpenAIChatSettings["tools"];
91
+ toolChoice?: AbstractOpenAIChatSettings["toolChoice"];
94
92
  }): Promise<RESULT>;
95
93
  doGenerateTexts(prompt: OpenAIChatPrompt, options?: FunctionOptions): Promise<{
96
94
  response: {
@@ -163,8 +161,6 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
163
161
  finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
164
162
  }[];
165
163
  system_fingerprint?: string | null | undefined;
166
- } | {
167
- object: string;
168
164
  }>>>;
169
165
  extractTextDelta(delta: unknown): string | undefined;
170
166
  doGenerateToolCall(tool: ToolDefinition<string, unknown>, prompt: OpenAIChatPrompt, options?: FunctionOptions): Promise<{
@@ -465,180 +461,6 @@ declare const openAIChatResponseSchema: z.ZodObject<{
465
461
  system_fingerprint?: string | null | undefined;
466
462
  }>;
467
463
  export type OpenAIChatResponse = z.infer<typeof openAIChatResponseSchema>;
468
- declare const chatCompletionChunkSchema: z.ZodObject<{
469
- object: z.ZodLiteral<"chat.completion.chunk">;
470
- id: z.ZodString;
471
- choices: z.ZodArray<z.ZodObject<{
472
- delta: z.ZodObject<{
473
- role: z.ZodOptional<z.ZodEnum<["assistant", "user"]>>;
474
- content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
475
- function_call: z.ZodOptional<z.ZodObject<{
476
- name: z.ZodOptional<z.ZodString>;
477
- arguments: z.ZodOptional<z.ZodString>;
478
- }, "strip", z.ZodTypeAny, {
479
- name?: string | undefined;
480
- arguments?: string | undefined;
481
- }, {
482
- name?: string | undefined;
483
- arguments?: string | undefined;
484
- }>>;
485
- tool_calls: z.ZodOptional<z.ZodArray<z.ZodObject<{
486
- id: z.ZodString;
487
- type: z.ZodLiteral<"function">;
488
- function: z.ZodObject<{
489
- name: z.ZodString;
490
- arguments: z.ZodString;
491
- }, "strip", z.ZodTypeAny, {
492
- name: string;
493
- arguments: string;
494
- }, {
495
- name: string;
496
- arguments: string;
497
- }>;
498
- }, "strip", z.ZodTypeAny, {
499
- function: {
500
- name: string;
501
- arguments: string;
502
- };
503
- type: "function";
504
- id: string;
505
- }, {
506
- function: {
507
- name: string;
508
- arguments: string;
509
- };
510
- type: "function";
511
- id: string;
512
- }>, "many">>;
513
- }, "strip", z.ZodTypeAny, {
514
- role?: "user" | "assistant" | undefined;
515
- content?: string | null | undefined;
516
- function_call?: {
517
- name?: string | undefined;
518
- arguments?: string | undefined;
519
- } | undefined;
520
- tool_calls?: {
521
- function: {
522
- name: string;
523
- arguments: string;
524
- };
525
- type: "function";
526
- id: string;
527
- }[] | undefined;
528
- }, {
529
- role?: "user" | "assistant" | undefined;
530
- content?: string | null | undefined;
531
- function_call?: {
532
- name?: string | undefined;
533
- arguments?: string | undefined;
534
- } | undefined;
535
- tool_calls?: {
536
- function: {
537
- name: string;
538
- arguments: string;
539
- };
540
- type: "function";
541
- id: string;
542
- }[] | undefined;
543
- }>;
544
- finish_reason: z.ZodOptional<z.ZodNullable<z.ZodEnum<["stop", "length", "tool_calls", "content_filter", "function_call"]>>>;
545
- index: z.ZodNumber;
546
- }, "strip", z.ZodTypeAny, {
547
- delta: {
548
- role?: "user" | "assistant" | undefined;
549
- content?: string | null | undefined;
550
- function_call?: {
551
- name?: string | undefined;
552
- arguments?: string | undefined;
553
- } | undefined;
554
- tool_calls?: {
555
- function: {
556
- name: string;
557
- arguments: string;
558
- };
559
- type: "function";
560
- id: string;
561
- }[] | undefined;
562
- };
563
- index: number;
564
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
565
- }, {
566
- delta: {
567
- role?: "user" | "assistant" | undefined;
568
- content?: string | null | undefined;
569
- function_call?: {
570
- name?: string | undefined;
571
- arguments?: string | undefined;
572
- } | undefined;
573
- tool_calls?: {
574
- function: {
575
- name: string;
576
- arguments: string;
577
- };
578
- type: "function";
579
- id: string;
580
- }[] | undefined;
581
- };
582
- index: number;
583
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
584
- }>, "many">;
585
- created: z.ZodNumber;
586
- model: z.ZodString;
587
- system_fingerprint: z.ZodNullable<z.ZodOptional<z.ZodString>>;
588
- }, "strip", z.ZodTypeAny, {
589
- object: "chat.completion.chunk";
590
- model: string;
591
- id: string;
592
- created: number;
593
- choices: {
594
- delta: {
595
- role?: "user" | "assistant" | undefined;
596
- content?: string | null | undefined;
597
- function_call?: {
598
- name?: string | undefined;
599
- arguments?: string | undefined;
600
- } | undefined;
601
- tool_calls?: {
602
- function: {
603
- name: string;
604
- arguments: string;
605
- };
606
- type: "function";
607
- id: string;
608
- }[] | undefined;
609
- };
610
- index: number;
611
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
612
- }[];
613
- system_fingerprint?: string | null | undefined;
614
- }, {
615
- object: "chat.completion.chunk";
616
- model: string;
617
- id: string;
618
- created: number;
619
- choices: {
620
- delta: {
621
- role?: "user" | "assistant" | undefined;
622
- content?: string | null | undefined;
623
- function_call?: {
624
- name?: string | undefined;
625
- arguments?: string | undefined;
626
- } | undefined;
627
- tool_calls?: {
628
- function: {
629
- name: string;
630
- arguments: string;
631
- };
632
- type: "function";
633
- id: string;
634
- }[] | undefined;
635
- };
636
- index: number;
637
- finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
638
- }[];
639
- system_fingerprint?: string | null | undefined;
640
- }>;
641
- export type OpenAIChatCompletionChunk = z.infer<typeof chatCompletionChunkSchema>;
642
464
  declare const openaiChatChunkSchema: import("../../core/schema/ZodSchema.js").ZodSchema<{
643
465
  object: "chat.completion.chunk";
644
466
  model: string;
@@ -665,8 +487,6 @@ declare const openaiChatChunkSchema: import("../../core/schema/ZodSchema.js").Zo
665
487
  finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
666
488
  }[];
667
489
  system_fingerprint?: string | null | undefined;
668
- } | {
669
- object: string;
670
490
  }>;
671
491
  export type OpenAIChatChunk = (typeof openaiChatChunkSchema)["_type"];
672
492
  export type OpenAIChatResponseFormatType<T> = {
@@ -746,8 +566,6 @@ export declare const OpenAIChatResponseFormat: {
746
566
  finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
747
567
  }[];
748
568
  system_fingerprint?: string | null | undefined;
749
- } | {
750
- object: string;
751
569
  }>>>;
752
570
  };
753
571
  };
@@ -228,7 +228,7 @@ const openAIChatResponseSchema = z.object({
228
228
  total_tokens: z.number(),
229
229
  }),
230
230
  });
231
- const chatCompletionChunkSchema = z.object({
231
+ const openaiChatChunkSchema = zodSchema(z.object({
232
232
  object: z.literal("chat.completion.chunk"),
233
233
  id: z.string(),
234
234
  choices: z.array(z.object({
@@ -267,15 +267,7 @@ const chatCompletionChunkSchema = z.object({
267
267
  created: z.number(),
268
268
  model: z.string(),
269
269
  system_fingerprint: z.string().optional().nullable(),
270
- });
271
- const openaiChatChunkSchema = zodSchema(z.union([
272
- chatCompletionChunkSchema,
273
- z.object({
274
- object: z.string().refine((obj) => obj !== "chat.completion.chunk", {
275
- message: "Object must be 'chat.completion.chunk'",
276
- }),
277
- }),
278
- ]));
270
+ }));
279
271
  export const OpenAIChatResponseFormat = {
280
272
  /**
281
273
  * Returns the response as a JSON object.
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAITextResponseFormat = exports.AbstractOpenAICompletionModel = void 0;
4
+ const zod_1 = require("zod");
5
+ const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
6
+ const postToApi_js_1 = require("../../core/api/postToApi.cjs");
7
+ const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
8
+ const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
9
+ const createEventSourceResponseHandler_js_1 = require("../../util/streaming/createEventSourceResponseHandler.cjs");
10
+ const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
11
+ const OpenAIError_js_1 = require("./OpenAIError.cjs");
12
+ /**
13
+ * Abstract completion model that calls an API that is compatible with the OpenAI completions API.
14
+ *
15
+ * @see https://platform.openai.com/docs/api-reference/completions/create
16
+ */
17
+ class AbstractOpenAICompletionModel extends AbstractModel_js_1.AbstractModel {
18
+ constructor(settings) {
19
+ super({ settings });
20
+ }
21
+ async callAPI(prompt, options) {
22
+ const api = this.settings.api ?? new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration();
23
+ const user = this.settings.isUserIdForwardingEnabled
24
+ ? options.run?.userId
25
+ : undefined;
26
+ const abortSignal = options.run?.abortSignal;
27
+ const openaiResponseFormat = options.responseFormat;
28
+ // empty arrays are not allowed for stop:
29
+ const stopSequences = this.settings.stopSequences != null &&
30
+ Array.isArray(this.settings.stopSequences) &&
31
+ this.settings.stopSequences.length === 0
32
+ ? undefined
33
+ : this.settings.stopSequences;
34
+ return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
35
+ retry: api.retry,
36
+ throttle: api.throttle,
37
+ call: async () => {
38
+ return (0, postToApi_js_1.postJsonToApi)({
39
+ url: api.assembleUrl("/completions"),
40
+ headers: api.headers,
41
+ body: {
42
+ stream: openaiResponseFormat.stream,
43
+ model: this.settings.model,
44
+ prompt,
45
+ suffix: this.settings.suffix,
46
+ max_tokens: this.settings.maxGenerationTokens,
47
+ temperature: this.settings.temperature,
48
+ top_p: this.settings.topP,
49
+ n: this.settings.numberOfGenerations,
50
+ logprobs: this.settings.logprobs,
51
+ echo: this.settings.echo,
52
+ stop: stopSequences,
53
+ seed: this.settings.seed,
54
+ presence_penalty: this.settings.presencePenalty,
55
+ frequency_penalty: this.settings.frequencyPenalty,
56
+ best_of: this.settings.bestOf,
57
+ logit_bias: this.settings.logitBias,
58
+ user,
59
+ },
60
+ failedResponseHandler: OpenAIError_js_1.failedOpenAICallResponseHandler,
61
+ successfulResponseHandler: openaiResponseFormat.handler,
62
+ abortSignal,
63
+ });
64
+ },
65
+ });
66
+ }
67
+ async doGenerateTexts(prompt, options) {
68
+ const response = await this.callAPI(prompt, {
69
+ ...options,
70
+ responseFormat: exports.OpenAITextResponseFormat.json,
71
+ });
72
+ return {
73
+ response,
74
+ textGenerationResults: response.choices.map((choice) => {
75
+ return {
76
+ finishReason: this.translateFinishReason(choice.finish_reason),
77
+ text: choice.text,
78
+ };
79
+ }),
80
+ usage: {
81
+ promptTokens: response.usage.prompt_tokens,
82
+ completionTokens: response.usage.completion_tokens,
83
+ totalTokens: response.usage.total_tokens,
84
+ },
85
+ };
86
+ }
87
+ translateFinishReason(finishReason) {
88
+ switch (finishReason) {
89
+ case "stop":
90
+ return "stop";
91
+ case "length":
92
+ return "length";
93
+ case "content_filter":
94
+ return "content-filter";
95
+ default:
96
+ return "unknown";
97
+ }
98
+ }
99
+ doStreamText(prompt, options) {
100
+ return this.callAPI(prompt, {
101
+ ...options,
102
+ responseFormat: exports.OpenAITextResponseFormat.deltaIterable,
103
+ });
104
+ }
105
+ extractTextDelta(delta) {
106
+ const chunk = delta;
107
+ const firstChoice = chunk.choices[0];
108
+ if (firstChoice.index > 0) {
109
+ return undefined;
110
+ }
111
+ return chunk.choices[0].text;
112
+ }
113
+ }
114
+ exports.AbstractOpenAICompletionModel = AbstractOpenAICompletionModel;
115
+ const OpenAICompletionResponseSchema = zod_1.z.object({
116
+ id: zod_1.z.string(),
117
+ choices: zod_1.z.array(zod_1.z.object({
118
+ finish_reason: zod_1.z
119
+ .enum(["stop", "length", "content_filter"])
120
+ .optional()
121
+ .nullable(),
122
+ index: zod_1.z.number(),
123
+ logprobs: zod_1.z.nullable(zod_1.z.any()),
124
+ text: zod_1.z.string(),
125
+ })),
126
+ created: zod_1.z.number(),
127
+ model: zod_1.z.string(),
128
+ system_fingerprint: zod_1.z.string().optional(),
129
+ object: zod_1.z.literal("text_completion"),
130
+ usage: zod_1.z.object({
131
+ prompt_tokens: zod_1.z.number(),
132
+ completion_tokens: zod_1.z.number(),
133
+ total_tokens: zod_1.z.number(),
134
+ }),
135
+ });
136
+ const openaiCompletionStreamChunkSchema = (0, ZodSchema_js_1.zodSchema)(zod_1.z.object({
137
+ choices: zod_1.z.array(zod_1.z.object({
138
+ text: zod_1.z.string(),
139
+ finish_reason: zod_1.z
140
+ .enum(["stop", "length", "content_filter"])
141
+ .optional()
142
+ .nullable(),
143
+ index: zod_1.z.number(),
144
+ })),
145
+ created: zod_1.z.number(),
146
+ id: zod_1.z.string(),
147
+ model: zod_1.z.string(),
148
+ system_fingerprint: zod_1.z.string().optional(),
149
+ object: zod_1.z.literal("text_completion"),
150
+ }));
151
+ exports.OpenAITextResponseFormat = {
152
+ /**
153
+ * Returns the response as a JSON object.
154
+ */
155
+ json: {
156
+ stream: false,
157
+ handler: (0, postToApi_js_1.createJsonResponseHandler)(OpenAICompletionResponseSchema),
158
+ },
159
+ /**
160
+ * Returns an async iterable over the full deltas (all choices, including full current state at time of event)
161
+ * of the response stream.
162
+ */
163
+ deltaIterable: {
164
+ stream: true,
165
+ handler: (0, createEventSourceResponseHandler_js_1.createEventSourceResponseHandler)(openaiCompletionStreamChunkSchema),
166
+ },
167
+ };
@@ -0,0 +1,199 @@
1
+ import { z } from "zod";
2
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
3
+ import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
4
+ import { ResponseHandler } from "../../core/api/postToApi.js";
5
+ import { AbstractModel } from "../../model-function/AbstractModel.js";
6
+ import { TextGenerationModelSettings } from "../../model-function/generate-text/TextGenerationModel.js";
7
+ import { TextGenerationFinishReason } from "../../model-function/generate-text/TextGenerationResult.js";
8
+ export interface AbstractOpenAICompletionModelSettings extends TextGenerationModelSettings {
9
+ api?: ApiConfiguration;
10
+ model: string;
11
+ suffix?: string;
12
+ temperature?: number;
13
+ topP?: number;
14
+ logprobs?: number;
15
+ echo?: boolean;
16
+ presencePenalty?: number;
17
+ frequencyPenalty?: number;
18
+ bestOf?: number;
19
+ logitBias?: Record<number, number>;
20
+ seed?: number | null;
21
+ isUserIdForwardingEnabled?: boolean;
22
+ }
23
+ /**
24
+ * Abstract completion model that calls an API that is compatible with the OpenAI completions API.
25
+ *
26
+ * @see https://platform.openai.com/docs/api-reference/completions/create
27
+ */
28
+ export declare abstract class AbstractOpenAICompletionModel<SETTINGS extends AbstractOpenAICompletionModelSettings> extends AbstractModel<SETTINGS> {
29
+ constructor(settings: SETTINGS);
30
+ callAPI<RESULT>(prompt: string, options: {
31
+ responseFormat: OpenAITextResponseFormatType<RESULT>;
32
+ } & FunctionOptions): Promise<RESULT>;
33
+ doGenerateTexts(prompt: string, options?: FunctionOptions): Promise<{
34
+ response: {
35
+ object: "text_completion";
36
+ usage: {
37
+ prompt_tokens: number;
38
+ completion_tokens: number;
39
+ total_tokens: number;
40
+ };
41
+ model: string;
42
+ id: string;
43
+ created: number;
44
+ choices: {
45
+ text: string;
46
+ index: number;
47
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
48
+ logprobs?: any;
49
+ }[];
50
+ system_fingerprint?: string | undefined;
51
+ };
52
+ textGenerationResults: {
53
+ finishReason: TextGenerationFinishReason;
54
+ text: string;
55
+ }[];
56
+ usage: {
57
+ promptTokens: number;
58
+ completionTokens: number;
59
+ totalTokens: number;
60
+ };
61
+ }>;
62
+ private translateFinishReason;
63
+ doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<import("../../index.js").Delta<{
64
+ object: "text_completion";
65
+ model: string;
66
+ id: string;
67
+ created: number;
68
+ choices: {
69
+ text: string;
70
+ index: number;
71
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
72
+ }[];
73
+ system_fingerprint?: string | undefined;
74
+ }>>>;
75
+ extractTextDelta(delta: unknown): string | undefined;
76
+ }
77
+ declare const OpenAICompletionResponseSchema: z.ZodObject<{
78
+ id: z.ZodString;
79
+ choices: z.ZodArray<z.ZodObject<{
80
+ finish_reason: z.ZodNullable<z.ZodOptional<z.ZodEnum<["stop", "length", "content_filter"]>>>;
81
+ index: z.ZodNumber;
82
+ logprobs: z.ZodNullable<z.ZodAny>;
83
+ text: z.ZodString;
84
+ }, "strip", z.ZodTypeAny, {
85
+ text: string;
86
+ index: number;
87
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
88
+ logprobs?: any;
89
+ }, {
90
+ text: string;
91
+ index: number;
92
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
93
+ logprobs?: any;
94
+ }>, "many">;
95
+ created: z.ZodNumber;
96
+ model: z.ZodString;
97
+ system_fingerprint: z.ZodOptional<z.ZodString>;
98
+ object: z.ZodLiteral<"text_completion">;
99
+ usage: z.ZodObject<{
100
+ prompt_tokens: z.ZodNumber;
101
+ completion_tokens: z.ZodNumber;
102
+ total_tokens: z.ZodNumber;
103
+ }, "strip", z.ZodTypeAny, {
104
+ prompt_tokens: number;
105
+ completion_tokens: number;
106
+ total_tokens: number;
107
+ }, {
108
+ prompt_tokens: number;
109
+ completion_tokens: number;
110
+ total_tokens: number;
111
+ }>;
112
+ }, "strip", z.ZodTypeAny, {
113
+ object: "text_completion";
114
+ usage: {
115
+ prompt_tokens: number;
116
+ completion_tokens: number;
117
+ total_tokens: number;
118
+ };
119
+ model: string;
120
+ id: string;
121
+ created: number;
122
+ choices: {
123
+ text: string;
124
+ index: number;
125
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
126
+ logprobs?: any;
127
+ }[];
128
+ system_fingerprint?: string | undefined;
129
+ }, {
130
+ object: "text_completion";
131
+ usage: {
132
+ prompt_tokens: number;
133
+ completion_tokens: number;
134
+ total_tokens: number;
135
+ };
136
+ model: string;
137
+ id: string;
138
+ created: number;
139
+ choices: {
140
+ text: string;
141
+ index: number;
142
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
143
+ logprobs?: any;
144
+ }[];
145
+ system_fingerprint?: string | undefined;
146
+ }>;
147
+ export type OpenAICompletionResponse = z.infer<typeof OpenAICompletionResponseSchema>;
148
+ export type OpenAITextResponseFormatType<T> = {
149
+ stream: boolean;
150
+ handler: ResponseHandler<T>;
151
+ };
152
+ export declare const OpenAITextResponseFormat: {
153
+ /**
154
+ * Returns the response as a JSON object.
155
+ */
156
+ json: {
157
+ stream: boolean;
158
+ handler: ResponseHandler<{
159
+ object: "text_completion";
160
+ usage: {
161
+ prompt_tokens: number;
162
+ completion_tokens: number;
163
+ total_tokens: number;
164
+ };
165
+ model: string;
166
+ id: string;
167
+ created: number;
168
+ choices: {
169
+ text: string;
170
+ index: number;
171
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
172
+ logprobs?: any;
173
+ }[];
174
+ system_fingerprint?: string | undefined;
175
+ }>;
176
+ };
177
+ /**
178
+ * Returns an async iterable over the full deltas (all choices, including full current state at time of event)
179
+ * of the response stream.
180
+ */
181
+ deltaIterable: {
182
+ stream: boolean;
183
+ handler: ({ response }: {
184
+ response: Response;
185
+ }) => Promise<AsyncIterable<import("../../index.js").Delta<{
186
+ object: "text_completion";
187
+ model: string;
188
+ id: string;
189
+ created: number;
190
+ choices: {
191
+ text: string;
192
+ index: number;
193
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
194
+ }[];
195
+ system_fingerprint?: string | undefined;
196
+ }>>>;
197
+ };
198
+ };
199
+ export {};