modelfusion 0.109.0 → 0.111.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/CHANGELOG.md +25 -0
- package/core/api/ApiFacade.cjs +20 -0
- package/core/api/ApiFacade.d.ts +4 -0
- package/core/api/ApiFacade.js +4 -0
- package/core/api/BaseUrlApiConfiguration.cjs +47 -5
- package/core/api/BaseUrlApiConfiguration.d.ts +23 -6
- package/core/api/BaseUrlApiConfiguration.js +45 -4
- package/core/api/BaseUrlApiConfiguration.test.cjs +11 -0
- package/core/api/BaseUrlApiConfiguration.test.d.ts +1 -0
- package/core/api/BaseUrlApiConfiguration.test.js +9 -0
- package/core/api/callWithRetryAndThrottle.cjs +3 -3
- package/core/api/callWithRetryAndThrottle.js +3 -3
- package/core/api/index.cjs +15 -2
- package/core/api/index.d.ts +2 -2
- package/core/api/index.js +2 -2
- package/core/api/postToApi.cjs +28 -5
- package/core/api/postToApi.d.ts +5 -4
- package/core/api/postToApi.js +26 -4
- package/core/api/throttleOff.cjs +8 -0
- package/core/api/throttleOff.d.ts +5 -0
- package/core/api/throttleOff.js +4 -0
- package/{extension → internal}/index.cjs +2 -7
- package/{extension → internal}/index.d.ts +1 -1
- package/{extension → internal}/index.js +1 -1
- package/model-function/generate-structure/generateStructure.d.ts +1 -1
- package/model-provider/anthropic/AnthropicApiConfiguration.cjs +14 -6
- package/model-provider/anthropic/AnthropicApiConfiguration.d.ts +7 -8
- package/model-provider/anthropic/AnthropicApiConfiguration.js +15 -7
- package/model-provider/anthropic/AnthropicError.cjs +7 -27
- package/model-provider/anthropic/AnthropicError.d.ts +21 -16
- package/model-provider/anthropic/AnthropicError.js +7 -25
- package/model-provider/anthropic/AnthropicFacade.cjs +10 -1
- package/model-provider/anthropic/AnthropicFacade.d.ts +9 -0
- package/model-provider/anthropic/AnthropicFacade.js +8 -0
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +22 -24
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +23 -25
- package/model-provider/anthropic/index.cjs +1 -4
- package/model-provider/anthropic/index.d.ts +1 -1
- package/model-provider/anthropic/index.js +0 -1
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.cjs +12 -4
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.d.ts +3 -3
- package/model-provider/automatic1111/Automatic1111ApiConfiguration.js +12 -4
- package/model-provider/automatic1111/Automatic1111Error.cjs +3 -3
- package/model-provider/automatic1111/Automatic1111Error.d.ts +13 -3
- package/model-provider/automatic1111/Automatic1111Error.js +4 -4
- package/model-provider/automatic1111/Automatic1111Facade.cjs +9 -9
- package/model-provider/automatic1111/Automatic1111Facade.d.ts +6 -6
- package/model-provider/automatic1111/Automatic1111Facade.js +7 -7
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +11 -7
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +11 -7
- package/model-provider/cohere/CohereApiConfiguration.cjs +14 -6
- package/model-provider/cohere/CohereApiConfiguration.d.ts +7 -8
- package/model-provider/cohere/CohereApiConfiguration.js +15 -7
- package/model-provider/cohere/CohereError.cjs +8 -43
- package/model-provider/cohere/CohereError.d.ts +9 -16
- package/model-provider/cohere/CohereError.js +8 -41
- package/model-provider/cohere/CohereFacade.cjs +12 -3
- package/model-provider/cohere/CohereFacade.d.ts +11 -2
- package/model-provider/cohere/CohereFacade.js +10 -2
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +18 -22
- package/model-provider/cohere/CohereTextEmbeddingModel.js +18 -22
- package/model-provider/cohere/CohereTextGenerationModel.cjs +31 -39
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +110 -8
- package/model-provider/cohere/CohereTextGenerationModel.js +31 -39
- package/model-provider/cohere/CohereTokenizer.cjs +32 -41
- package/model-provider/cohere/CohereTokenizer.d.ts +2 -2
- package/model-provider/cohere/CohereTokenizer.js +32 -41
- package/model-provider/cohere/index.cjs +1 -3
- package/model-provider/cohere/index.d.ts +1 -1
- package/model-provider/cohere/index.js +0 -1
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.cjs +14 -6
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.d.ts +7 -8
- package/model-provider/elevenlabs/ElevenLabsApiConfiguration.js +15 -7
- package/model-provider/elevenlabs/ElevenLabsFacade.cjs +10 -1
- package/model-provider/elevenlabs/ElevenLabsFacade.d.ts +9 -0
- package/model-provider/elevenlabs/ElevenLabsFacade.js +8 -0
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +42 -53
- package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +44 -55
- package/model-provider/huggingface/HuggingFaceApiConfiguration.cjs +14 -6
- package/model-provider/huggingface/HuggingFaceApiConfiguration.d.ts +7 -8
- package/model-provider/huggingface/HuggingFaceApiConfiguration.js +15 -7
- package/model-provider/huggingface/HuggingFaceError.cjs +7 -29
- package/model-provider/huggingface/HuggingFaceError.d.ts +9 -16
- package/model-provider/huggingface/HuggingFaceError.js +7 -27
- package/model-provider/huggingface/HuggingFaceFacade.cjs +10 -1
- package/model-provider/huggingface/HuggingFaceFacade.d.ts +9 -0
- package/model-provider/huggingface/HuggingFaceFacade.js +8 -0
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.cjs +17 -27
- package/model-provider/huggingface/HuggingFaceTextEmbeddingModel.js +17 -27
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +22 -23
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +22 -23
- package/model-provider/huggingface/index.cjs +1 -3
- package/model-provider/huggingface/index.d.ts +1 -1
- package/model-provider/huggingface/index.js +0 -1
- package/model-provider/llamacpp/LlamaCppApiConfiguration.cjs +13 -6
- package/model-provider/llamacpp/LlamaCppApiConfiguration.d.ts +7 -9
- package/model-provider/llamacpp/LlamaCppApiConfiguration.js +14 -7
- package/model-provider/llamacpp/LlamaCppCompletionModel.cjs +4 -4
- package/model-provider/llamacpp/LlamaCppCompletionModel.d.ts +173 -5
- package/model-provider/llamacpp/LlamaCppCompletionModel.js +4 -4
- package/model-provider/llamacpp/LlamaCppError.cjs +7 -27
- package/model-provider/llamacpp/LlamaCppError.d.ts +9 -16
- package/model-provider/llamacpp/LlamaCppError.js +7 -25
- package/model-provider/llamacpp/LlamaCppFacade.cjs +10 -2
- package/model-provider/llamacpp/LlamaCppFacade.d.ts +8 -1
- package/model-provider/llamacpp/LlamaCppFacade.js +8 -1
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +10 -14
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +10 -14
- package/model-provider/llamacpp/LlamaCppTokenizer.cjs +14 -18
- package/model-provider/llamacpp/LlamaCppTokenizer.js +14 -18
- package/model-provider/llamacpp/index.cjs +1 -3
- package/model-provider/llamacpp/index.d.ts +1 -1
- package/model-provider/llamacpp/index.js +0 -1
- package/model-provider/lmnt/LmntApiConfiguration.cjs +14 -6
- package/model-provider/lmnt/LmntApiConfiguration.d.ts +7 -8
- package/model-provider/lmnt/LmntApiConfiguration.js +15 -7
- package/model-provider/lmnt/LmntFacade.cjs +11 -2
- package/model-provider/lmnt/LmntFacade.d.ts +10 -1
- package/model-provider/lmnt/LmntFacade.js +9 -1
- package/model-provider/lmnt/LmntSpeechModel.cjs +53 -41
- package/model-provider/lmnt/LmntSpeechModel.d.ts +51 -3
- package/model-provider/lmnt/LmntSpeechModel.js +54 -42
- package/model-provider/mistral/MistralApiConfiguration.cjs +14 -6
- package/model-provider/mistral/MistralApiConfiguration.d.ts +9 -11
- package/model-provider/mistral/MistralApiConfiguration.js +15 -7
- package/model-provider/mistral/MistralChatModel.cjs +4 -4
- package/model-provider/mistral/MistralChatModel.d.ts +48 -3
- package/model-provider/mistral/MistralChatModel.js +5 -5
- package/model-provider/mistral/MistralError.cjs +3 -3
- package/model-provider/mistral/MistralError.d.ts +15 -3
- package/model-provider/mistral/MistralError.js +4 -4
- package/model-provider/mistral/MistralFacade.cjs +5 -1
- package/model-provider/mistral/MistralFacade.d.ts +10 -3
- package/model-provider/mistral/MistralFacade.js +6 -2
- package/model-provider/mistral/MistralTextEmbeddingModel.cjs +2 -1
- package/model-provider/mistral/MistralTextEmbeddingModel.js +2 -1
- package/model-provider/ollama/OllamaApiConfiguration.cjs +13 -6
- package/model-provider/ollama/OllamaApiConfiguration.d.ts +7 -10
- package/model-provider/ollama/OllamaApiConfiguration.js +14 -7
- package/model-provider/ollama/OllamaChatModel.cjs +4 -4
- package/model-provider/ollama/OllamaChatModel.d.ts +46 -5
- package/model-provider/ollama/OllamaChatModel.js +5 -5
- package/model-provider/ollama/OllamaCompletionModel.cjs +4 -4
- package/model-provider/ollama/OllamaCompletionModel.d.ts +40 -5
- package/model-provider/ollama/OllamaCompletionModel.js +5 -5
- package/model-provider/ollama/OllamaError.cjs +3 -3
- package/model-provider/ollama/OllamaError.d.ts +7 -3
- package/model-provider/ollama/OllamaError.js +4 -4
- package/model-provider/ollama/OllamaFacade.cjs +6 -2
- package/model-provider/ollama/OllamaFacade.d.ts +8 -3
- package/model-provider/ollama/OllamaFacade.js +6 -2
- package/model-provider/ollama/OllamaTextEmbeddingModel.cjs +15 -16
- package/model-provider/ollama/OllamaTextEmbeddingModel.js +15 -16
- package/model-provider/openai/AbstractOpenAIChatModel.cjs +4 -4
- package/model-provider/openai/AbstractOpenAIChatModel.d.ts +148 -2
- package/model-provider/openai/AbstractOpenAIChatModel.js +4 -4
- package/model-provider/openai/AbstractOpenAICompletionModel.cjs +30 -32
- package/model-provider/openai/AbstractOpenAICompletionModel.js +30 -32
- package/model-provider/openai/AzureOpenAIApiConfiguration.d.ts +9 -8
- package/model-provider/openai/OpenAIApiConfiguration.cjs +14 -6
- package/model-provider/openai/OpenAIApiConfiguration.d.ts +7 -8
- package/model-provider/openai/OpenAIApiConfiguration.js +15 -7
- package/model-provider/openai/OpenAICompletionModel.cjs +3 -91
- package/model-provider/openai/OpenAICompletionModel.d.ts +3 -71
- package/model-provider/openai/OpenAICompletionModel.js +3 -91
- package/model-provider/openai/OpenAIError.cjs +8 -8
- package/model-provider/openai/OpenAIError.d.ts +27 -3
- package/model-provider/openai/OpenAIError.js +9 -9
- package/model-provider/openai/OpenAIFacade.cjs +23 -2
- package/model-provider/openai/OpenAIFacade.d.ts +20 -2
- package/model-provider/openai/OpenAIFacade.js +20 -1
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +20 -21
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +1 -1
- package/model-provider/openai/OpenAIImageGenerationModel.js +20 -21
- package/model-provider/openai/OpenAISpeechModel.cjs +17 -22
- package/model-provider/openai/OpenAISpeechModel.js +17 -22
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +18 -23
- package/model-provider/openai/OpenAITextEmbeddingModel.js +18 -23
- package/model-provider/openai/OpenAITranscriptionModel.cjs +42 -48
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +14 -10
- package/model-provider/openai/OpenAITranscriptionModel.js +42 -48
- package/model-provider/openai/TikTokenTokenizer.cjs +0 -18
- package/model-provider/openai/TikTokenTokenizer.d.ts +3 -3
- package/model-provider/openai/TikTokenTokenizer.js +0 -18
- package/model-provider/openai-compatible/FireworksAIApiConfiguration.cjs +11 -7
- package/model-provider/openai-compatible/FireworksAIApiConfiguration.d.ts +4 -9
- package/model-provider/openai-compatible/FireworksAIApiConfiguration.js +12 -8
- package/model-provider/openai-compatible/OpenAICompatibleFacade.cjs +25 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +23 -0
- package/model-provider/openai-compatible/OpenAICompatibleFacade.js +22 -0
- package/model-provider/openai-compatible/TogetherAIApiConfiguration.cjs +11 -7
- package/model-provider/openai-compatible/TogetherAIApiConfiguration.d.ts +4 -9
- package/model-provider/openai-compatible/TogetherAIApiConfiguration.js +12 -8
- package/model-provider/stability/StabilityApiConfiguration.cjs +13 -12
- package/model-provider/stability/StabilityApiConfiguration.d.ts +4 -4
- package/model-provider/stability/StabilityApiConfiguration.js +13 -12
- package/model-provider/stability/StabilityError.cjs +3 -3
- package/model-provider/stability/StabilityError.d.ts +7 -3
- package/model-provider/stability/StabilityError.js +4 -4
- package/model-provider/stability/StabilityFacade.cjs +9 -9
- package/model-provider/stability/StabilityFacade.d.ts +8 -8
- package/model-provider/stability/StabilityFacade.js +7 -7
- package/model-provider/stability/StabilityImageGenerationModel.cjs +2 -1
- package/model-provider/stability/StabilityImageGenerationModel.js +2 -1
- package/model-provider/whispercpp/WhisperCppApiConfiguration.cjs +13 -6
- package/model-provider/whispercpp/WhisperCppApiConfiguration.d.ts +7 -10
- package/model-provider/whispercpp/WhisperCppApiConfiguration.js +14 -7
- package/model-provider/whispercpp/WhisperCppFacade.cjs +9 -5
- package/model-provider/whispercpp/WhisperCppFacade.d.ts +7 -2
- package/model-provider/whispercpp/WhisperCppFacade.js +8 -4
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.cjs +5 -2
- package/model-provider/whispercpp/WhisperCppTranscriptionModel.js +6 -3
- package/package.json +5 -5
- package/tool/WebSearchTool.cjs +2 -2
- package/tool/WebSearchTool.d.ts +1 -2
- package/tool/WebSearchTool.js +3 -3
- package/vector-index/memory/MemoryVectorIndex.cjs +2 -2
- package/vector-index/memory/MemoryVectorIndex.js +3 -3
- package/core/api/BaseUrlPartsApiConfiguration.cjs +0 -53
- package/core/api/BaseUrlPartsApiConfiguration.d.ts +0 -26
- package/core/api/BaseUrlPartsApiConfiguration.js +0 -49
- package/core/api/throttleUnlimitedConcurrency.cjs +0 -8
- package/core/api/throttleUnlimitedConcurrency.d.ts +0 -5
- package/core/api/throttleUnlimitedConcurrency.js +0 -4
- package/model-provider/elevenlabs/ElevenLabsError.cjs +0 -30
- package/model-provider/elevenlabs/ElevenLabsError.d.ts +0 -3
- package/model-provider/elevenlabs/ElevenLabsError.js +0 -26
- package/model-provider/lmnt/LmntError.cjs +0 -30
- package/model-provider/lmnt/LmntError.d.ts +0 -3
- package/model-provider/lmnt/LmntError.js +0 -26
@@ -17,100 +17,12 @@ exports.OPENAI_TEXT_GENERATION_MODELS = {
|
|
17
17
|
promptTokenCostInMillicents: 0.15,
|
18
18
|
completionTokenCostInMillicents: 0.2,
|
19
19
|
},
|
20
|
-
"davinci-002": {
|
21
|
-
contextWindowSize: 16384,
|
22
|
-
promptTokenCostInMillicents: 0.2,
|
23
|
-
completionTokenCostInMillicents: 0.2,
|
24
|
-
fineTunedTokenCostInMillicents: 1.2,
|
25
|
-
},
|
26
|
-
"babbage-002": {
|
27
|
-
contextWindowSize: 16384,
|
28
|
-
promptTokenCostInMillicents: 0.04,
|
29
|
-
completionTokenCostInMillicents: 0.04,
|
30
|
-
fineTunedTokenCostInMillicents: 0.16,
|
31
|
-
},
|
32
|
-
"text-davinci-003": {
|
33
|
-
contextWindowSize: 4096,
|
34
|
-
promptTokenCostInMillicents: 2,
|
35
|
-
completionTokenCostInMillicents: 2,
|
36
|
-
},
|
37
|
-
"text-davinci-002": {
|
38
|
-
contextWindowSize: 4096,
|
39
|
-
promptTokenCostInMillicents: 2,
|
40
|
-
completionTokenCostInMillicents: 2,
|
41
|
-
},
|
42
|
-
"code-davinci-002": {
|
43
|
-
contextWindowSize: 8000,
|
44
|
-
promptTokenCostInMillicents: 2,
|
45
|
-
completionTokenCostInMillicents: 2,
|
46
|
-
},
|
47
|
-
davinci: {
|
48
|
-
contextWindowSize: 2048,
|
49
|
-
promptTokenCostInMillicents: 2,
|
50
|
-
completionTokenCostInMillicents: 2,
|
51
|
-
},
|
52
|
-
"text-curie-001": {
|
53
|
-
contextWindowSize: 2048,
|
54
|
-
promptTokenCostInMillicents: 0.2,
|
55
|
-
completionTokenCostInMillicents: 0.2,
|
56
|
-
},
|
57
|
-
curie: {
|
58
|
-
contextWindowSize: 2048,
|
59
|
-
promptTokenCostInMillicents: 0.2,
|
60
|
-
completionTokenCostInMillicents: 0.2,
|
61
|
-
},
|
62
|
-
"text-babbage-001": {
|
63
|
-
contextWindowSize: 2048,
|
64
|
-
promptTokenCostInMillicents: 0.05,
|
65
|
-
completionTokenCostInMillicents: 0.05,
|
66
|
-
},
|
67
|
-
babbage: {
|
68
|
-
contextWindowSize: 2048,
|
69
|
-
promptTokenCostInMillicents: 0.05,
|
70
|
-
completionTokenCostInMillicents: 0.05,
|
71
|
-
},
|
72
|
-
"text-ada-001": {
|
73
|
-
contextWindowSize: 2048,
|
74
|
-
promptTokenCostInMillicents: 0.04,
|
75
|
-
completionTokenCostInMillicents: 0.04,
|
76
|
-
},
|
77
|
-
ada: {
|
78
|
-
contextWindowSize: 2048,
|
79
|
-
promptTokenCostInMillicents: 0.04,
|
80
|
-
completionTokenCostInMillicents: 0.04,
|
81
|
-
},
|
82
20
|
};
|
83
21
|
function getOpenAICompletionModelInformation(model) {
|
84
|
-
|
85
|
-
if (model in exports.OPENAI_TEXT_GENERATION_MODELS) {
|
86
|
-
const baseModelInformation = exports.OPENAI_TEXT_GENERATION_MODELS[model];
|
87
|
-
return {
|
88
|
-
baseModel: model,
|
89
|
-
isFineTuned: false,
|
90
|
-
contextWindowSize: baseModelInformation.contextWindowSize,
|
91
|
-
promptTokenCostInMillicents: baseModelInformation.promptTokenCostInMillicents,
|
92
|
-
completionTokenCostInMillicents: baseModelInformation.completionTokenCostInMillicents,
|
93
|
-
};
|
94
|
-
}
|
95
|
-
// Extract the base model from the fine-tuned model:
|
96
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
97
|
-
const [_, baseModel, ___, ____, _____] = model.split(":");
|
98
|
-
if (["davinci-002", "babbage-002"].includes(baseModel)) {
|
99
|
-
const baseModelInformation = exports.OPENAI_TEXT_GENERATION_MODELS[baseModel];
|
100
|
-
return {
|
101
|
-
baseModel: baseModel,
|
102
|
-
isFineTuned: true,
|
103
|
-
contextWindowSize: baseModelInformation.contextWindowSize,
|
104
|
-
promptTokenCostInMillicents: baseModelInformation.fineTunedTokenCostInMillicents,
|
105
|
-
completionTokenCostInMillicents: baseModelInformation.fineTunedTokenCostInMillicents,
|
106
|
-
};
|
107
|
-
}
|
108
|
-
throw new Error(`Unknown OpenAI chat base model ${baseModel}.`);
|
22
|
+
return exports.OPENAI_TEXT_GENERATION_MODELS[model];
|
109
23
|
}
|
110
24
|
exports.getOpenAICompletionModelInformation = getOpenAICompletionModelInformation;
|
111
|
-
const isOpenAICompletionModel = (model) => model in exports.OPENAI_TEXT_GENERATION_MODELS
|
112
|
-
model.startsWith("ft:davinci-002:") ||
|
113
|
-
model.startsWith("ft:babbage-002:");
|
25
|
+
const isOpenAICompletionModel = (model) => model in exports.OPENAI_TEXT_GENERATION_MODELS;
|
114
26
|
exports.isOpenAICompletionModel = isOpenAICompletionModel;
|
115
27
|
const calculateOpenAICompletionCostInMillicents = ({ model, response, }) => {
|
116
28
|
const modelInformation = getOpenAICompletionModelInformation(model);
|
@@ -161,7 +73,7 @@ class OpenAICompletionModel extends AbstractOpenAICompletionModel_js_1.AbstractO
|
|
161
73
|
});
|
162
74
|
const modelInformation = getOpenAICompletionModelInformation(this.settings.model);
|
163
75
|
this.tokenizer = new TikTokenTokenizer_js_1.TikTokenTokenizer({
|
164
|
-
model:
|
76
|
+
model: this.settings.model,
|
165
77
|
});
|
166
78
|
this.contextWindowSize = modelInformation.contextWindowSize;
|
167
79
|
}
|
@@ -13,81 +13,14 @@ export declare const OPENAI_TEXT_GENERATION_MODELS: {
|
|
13
13
|
promptTokenCostInMillicents: number;
|
14
14
|
completionTokenCostInMillicents: number;
|
15
15
|
};
|
16
|
-
"davinci-002": {
|
17
|
-
contextWindowSize: number;
|
18
|
-
promptTokenCostInMillicents: number;
|
19
|
-
completionTokenCostInMillicents: number;
|
20
|
-
fineTunedTokenCostInMillicents: number;
|
21
|
-
};
|
22
|
-
"babbage-002": {
|
23
|
-
contextWindowSize: number;
|
24
|
-
promptTokenCostInMillicents: number;
|
25
|
-
completionTokenCostInMillicents: number;
|
26
|
-
fineTunedTokenCostInMillicents: number;
|
27
|
-
};
|
28
|
-
"text-davinci-003": {
|
29
|
-
contextWindowSize: number;
|
30
|
-
promptTokenCostInMillicents: number;
|
31
|
-
completionTokenCostInMillicents: number;
|
32
|
-
};
|
33
|
-
"text-davinci-002": {
|
34
|
-
contextWindowSize: number;
|
35
|
-
promptTokenCostInMillicents: number;
|
36
|
-
completionTokenCostInMillicents: number;
|
37
|
-
};
|
38
|
-
"code-davinci-002": {
|
39
|
-
contextWindowSize: number;
|
40
|
-
promptTokenCostInMillicents: number;
|
41
|
-
completionTokenCostInMillicents: number;
|
42
|
-
};
|
43
|
-
davinci: {
|
44
|
-
contextWindowSize: number;
|
45
|
-
promptTokenCostInMillicents: number;
|
46
|
-
completionTokenCostInMillicents: number;
|
47
|
-
};
|
48
|
-
"text-curie-001": {
|
49
|
-
contextWindowSize: number;
|
50
|
-
promptTokenCostInMillicents: number;
|
51
|
-
completionTokenCostInMillicents: number;
|
52
|
-
};
|
53
|
-
curie: {
|
54
|
-
contextWindowSize: number;
|
55
|
-
promptTokenCostInMillicents: number;
|
56
|
-
completionTokenCostInMillicents: number;
|
57
|
-
};
|
58
|
-
"text-babbage-001": {
|
59
|
-
contextWindowSize: number;
|
60
|
-
promptTokenCostInMillicents: number;
|
61
|
-
completionTokenCostInMillicents: number;
|
62
|
-
};
|
63
|
-
babbage: {
|
64
|
-
contextWindowSize: number;
|
65
|
-
promptTokenCostInMillicents: number;
|
66
|
-
completionTokenCostInMillicents: number;
|
67
|
-
};
|
68
|
-
"text-ada-001": {
|
69
|
-
contextWindowSize: number;
|
70
|
-
promptTokenCostInMillicents: number;
|
71
|
-
completionTokenCostInMillicents: number;
|
72
|
-
};
|
73
|
-
ada: {
|
74
|
-
contextWindowSize: number;
|
75
|
-
promptTokenCostInMillicents: number;
|
76
|
-
completionTokenCostInMillicents: number;
|
77
|
-
};
|
78
16
|
};
|
79
17
|
export declare function getOpenAICompletionModelInformation(model: OpenAICompletionModelType): {
|
80
|
-
baseModel: OpenAICompletionBaseModelType;
|
81
|
-
isFineTuned: boolean;
|
82
18
|
contextWindowSize: number;
|
83
19
|
promptTokenCostInMillicents: number;
|
84
20
|
completionTokenCostInMillicents: number;
|
85
21
|
};
|
86
|
-
type
|
87
|
-
|
88
|
-
export type OpenAICompletionBaseModelType = keyof typeof OPENAI_TEXT_GENERATION_MODELS;
|
89
|
-
export type OpenAICompletionModelType = OpenAICompletionBaseModelType | FineTunedOpenAICompletionModelType;
|
90
|
-
export declare const isOpenAICompletionModel: (model: string) => model is OpenAICompletionModelType;
|
22
|
+
export type OpenAICompletionModelType = keyof typeof OPENAI_TEXT_GENERATION_MODELS;
|
23
|
+
export declare const isOpenAICompletionModel: (model: string) => model is "gpt-3.5-turbo-instruct";
|
91
24
|
export declare const calculateOpenAICompletionCostInMillicents: ({ model, response, }: {
|
92
25
|
model: OpenAICompletionModelType;
|
93
26
|
response: OpenAICompletionResponse;
|
@@ -116,7 +49,7 @@ export interface OpenAICompletionModelSettings extends AbstractOpenAICompletionM
|
|
116
49
|
export declare class OpenAICompletionModel extends AbstractOpenAICompletionModel<OpenAICompletionModelSettings> implements TextStreamingModel<string, OpenAICompletionModelSettings> {
|
117
50
|
constructor(settings: OpenAICompletionModelSettings);
|
118
51
|
readonly provider: "openai";
|
119
|
-
get modelName():
|
52
|
+
get modelName(): "gpt-3.5-turbo-instruct";
|
120
53
|
readonly contextWindowSize: number;
|
121
54
|
readonly tokenizer: TikTokenTokenizer;
|
122
55
|
countPromptTokens(input: string): Promise<number>;
|
@@ -135,4 +68,3 @@ export declare class OpenAICompletionModel extends AbstractOpenAICompletionModel
|
|
135
68
|
withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, string>): PromptTemplateTextStreamingModel<INPUT_PROMPT, string, OpenAICompletionModelSettings, this>;
|
136
69
|
withSettings(additionalSettings: Partial<OpenAICompletionModelSettings>): this;
|
137
70
|
}
|
138
|
-
export {};
|
@@ -14,99 +14,11 @@ export const OPENAI_TEXT_GENERATION_MODELS = {
|
|
14
14
|
promptTokenCostInMillicents: 0.15,
|
15
15
|
completionTokenCostInMillicents: 0.2,
|
16
16
|
},
|
17
|
-
"davinci-002": {
|
18
|
-
contextWindowSize: 16384,
|
19
|
-
promptTokenCostInMillicents: 0.2,
|
20
|
-
completionTokenCostInMillicents: 0.2,
|
21
|
-
fineTunedTokenCostInMillicents: 1.2,
|
22
|
-
},
|
23
|
-
"babbage-002": {
|
24
|
-
contextWindowSize: 16384,
|
25
|
-
promptTokenCostInMillicents: 0.04,
|
26
|
-
completionTokenCostInMillicents: 0.04,
|
27
|
-
fineTunedTokenCostInMillicents: 0.16,
|
28
|
-
},
|
29
|
-
"text-davinci-003": {
|
30
|
-
contextWindowSize: 4096,
|
31
|
-
promptTokenCostInMillicents: 2,
|
32
|
-
completionTokenCostInMillicents: 2,
|
33
|
-
},
|
34
|
-
"text-davinci-002": {
|
35
|
-
contextWindowSize: 4096,
|
36
|
-
promptTokenCostInMillicents: 2,
|
37
|
-
completionTokenCostInMillicents: 2,
|
38
|
-
},
|
39
|
-
"code-davinci-002": {
|
40
|
-
contextWindowSize: 8000,
|
41
|
-
promptTokenCostInMillicents: 2,
|
42
|
-
completionTokenCostInMillicents: 2,
|
43
|
-
},
|
44
|
-
davinci: {
|
45
|
-
contextWindowSize: 2048,
|
46
|
-
promptTokenCostInMillicents: 2,
|
47
|
-
completionTokenCostInMillicents: 2,
|
48
|
-
},
|
49
|
-
"text-curie-001": {
|
50
|
-
contextWindowSize: 2048,
|
51
|
-
promptTokenCostInMillicents: 0.2,
|
52
|
-
completionTokenCostInMillicents: 0.2,
|
53
|
-
},
|
54
|
-
curie: {
|
55
|
-
contextWindowSize: 2048,
|
56
|
-
promptTokenCostInMillicents: 0.2,
|
57
|
-
completionTokenCostInMillicents: 0.2,
|
58
|
-
},
|
59
|
-
"text-babbage-001": {
|
60
|
-
contextWindowSize: 2048,
|
61
|
-
promptTokenCostInMillicents: 0.05,
|
62
|
-
completionTokenCostInMillicents: 0.05,
|
63
|
-
},
|
64
|
-
babbage: {
|
65
|
-
contextWindowSize: 2048,
|
66
|
-
promptTokenCostInMillicents: 0.05,
|
67
|
-
completionTokenCostInMillicents: 0.05,
|
68
|
-
},
|
69
|
-
"text-ada-001": {
|
70
|
-
contextWindowSize: 2048,
|
71
|
-
promptTokenCostInMillicents: 0.04,
|
72
|
-
completionTokenCostInMillicents: 0.04,
|
73
|
-
},
|
74
|
-
ada: {
|
75
|
-
contextWindowSize: 2048,
|
76
|
-
promptTokenCostInMillicents: 0.04,
|
77
|
-
completionTokenCostInMillicents: 0.04,
|
78
|
-
},
|
79
17
|
};
|
80
18
|
export function getOpenAICompletionModelInformation(model) {
|
81
|
-
|
82
|
-
if (model in OPENAI_TEXT_GENERATION_MODELS) {
|
83
|
-
const baseModelInformation = OPENAI_TEXT_GENERATION_MODELS[model];
|
84
|
-
return {
|
85
|
-
baseModel: model,
|
86
|
-
isFineTuned: false,
|
87
|
-
contextWindowSize: baseModelInformation.contextWindowSize,
|
88
|
-
promptTokenCostInMillicents: baseModelInformation.promptTokenCostInMillicents,
|
89
|
-
completionTokenCostInMillicents: baseModelInformation.completionTokenCostInMillicents,
|
90
|
-
};
|
91
|
-
}
|
92
|
-
// Extract the base model from the fine-tuned model:
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
94
|
-
const [_, baseModel, ___, ____, _____] = model.split(":");
|
95
|
-
if (["davinci-002", "babbage-002"].includes(baseModel)) {
|
96
|
-
const baseModelInformation = OPENAI_TEXT_GENERATION_MODELS[baseModel];
|
97
|
-
return {
|
98
|
-
baseModel: baseModel,
|
99
|
-
isFineTuned: true,
|
100
|
-
contextWindowSize: baseModelInformation.contextWindowSize,
|
101
|
-
promptTokenCostInMillicents: baseModelInformation.fineTunedTokenCostInMillicents,
|
102
|
-
completionTokenCostInMillicents: baseModelInformation.fineTunedTokenCostInMillicents,
|
103
|
-
};
|
104
|
-
}
|
105
|
-
throw new Error(`Unknown OpenAI chat base model ${baseModel}.`);
|
19
|
+
return OPENAI_TEXT_GENERATION_MODELS[model];
|
106
20
|
}
|
107
|
-
export const isOpenAICompletionModel = (model) => model in OPENAI_TEXT_GENERATION_MODELS
|
108
|
-
model.startsWith("ft:davinci-002:") ||
|
109
|
-
model.startsWith("ft:babbage-002:");
|
21
|
+
export const isOpenAICompletionModel = (model) => model in OPENAI_TEXT_GENERATION_MODELS;
|
110
22
|
export const calculateOpenAICompletionCostInMillicents = ({ model, response, }) => {
|
111
23
|
const modelInformation = getOpenAICompletionModelInformation(model);
|
112
24
|
return (response.usage.prompt_tokens *
|
@@ -155,7 +67,7 @@ export class OpenAICompletionModel extends AbstractOpenAICompletionModel {
|
|
155
67
|
});
|
156
68
|
const modelInformation = getOpenAICompletionModelInformation(this.settings.model);
|
157
69
|
this.tokenizer = new TikTokenTokenizer({
|
158
|
-
model:
|
70
|
+
model: this.settings.model,
|
159
71
|
});
|
160
72
|
this.contextWindowSize = modelInformation.contextWindowSize;
|
161
73
|
}
|
@@ -4,19 +4,19 @@ exports.failedOpenAICallResponseHandler = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
5
5
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
6
6
|
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
7
|
-
const openAIErrorDataSchema =
|
7
|
+
const openAIErrorDataSchema = zod_1.z.object({
|
8
8
|
error: zod_1.z.object({
|
9
9
|
message: zod_1.z.string(),
|
10
10
|
type: zod_1.z.string(),
|
11
11
|
param: zod_1.z.any().nullable(),
|
12
12
|
code: zod_1.z.string().nullable(),
|
13
13
|
}),
|
14
|
-
})
|
14
|
+
});
|
15
15
|
exports.failedOpenAICallResponseHandler = (0, postToApi_js_1.createJsonErrorResponseHandler)({
|
16
|
-
errorSchema: openAIErrorDataSchema,
|
17
|
-
errorToMessage: (
|
18
|
-
isRetryable: (
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
errorSchema: (0, ZodSchema_js_1.zodSchema)(openAIErrorDataSchema),
|
17
|
+
errorToMessage: (data) => data.error.message,
|
18
|
+
isRetryable: (response, error) => response.status >= 500 ||
|
19
|
+
(response.status === 429 &&
|
20
|
+
// insufficient_quota is also reported as a 429, but it's not retryable:
|
21
|
+
error?.error.type !== "insufficient_quota"),
|
22
22
|
});
|
@@ -1,5 +1,29 @@
|
|
1
|
-
import {
|
2
|
-
declare const openAIErrorDataSchema:
|
1
|
+
import { z } from "zod";
|
2
|
+
declare const openAIErrorDataSchema: z.ZodObject<{
|
3
|
+
error: z.ZodObject<{
|
4
|
+
message: z.ZodString;
|
5
|
+
type: z.ZodString;
|
6
|
+
param: z.ZodNullable<z.ZodAny>;
|
7
|
+
code: z.ZodNullable<z.ZodString>;
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
9
|
+
message: string;
|
10
|
+
code: string | null;
|
11
|
+
type: string;
|
12
|
+
param?: any;
|
13
|
+
}, {
|
14
|
+
message: string;
|
15
|
+
code: string | null;
|
16
|
+
type: string;
|
17
|
+
param?: any;
|
18
|
+
}>;
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
20
|
+
error: {
|
21
|
+
message: string;
|
22
|
+
code: string | null;
|
23
|
+
type: string;
|
24
|
+
param?: any;
|
25
|
+
};
|
26
|
+
}, {
|
3
27
|
error: {
|
4
28
|
message: string;
|
5
29
|
code: string | null;
|
@@ -7,6 +31,6 @@ declare const openAIErrorDataSchema: ZodSchema<{
|
|
7
31
|
param?: any;
|
8
32
|
};
|
9
33
|
}>;
|
10
|
-
export type OpenAIErrorData =
|
34
|
+
export type OpenAIErrorData = z.infer<typeof openAIErrorDataSchema>;
|
11
35
|
export declare const failedOpenAICallResponseHandler: import("../../core/api/postToApi.js").ResponseHandler<import("../../index.js").ApiCallError>;
|
12
36
|
export {};
|
@@ -1,19 +1,19 @@
|
|
1
1
|
import { z } from "zod";
|
2
2
|
import { createJsonErrorResponseHandler } from "../../core/api/postToApi.js";
|
3
|
-
import {
|
4
|
-
const openAIErrorDataSchema =
|
3
|
+
import { zodSchema } from "../../core/schema/ZodSchema.js";
|
4
|
+
const openAIErrorDataSchema = z.object({
|
5
5
|
error: z.object({
|
6
6
|
message: z.string(),
|
7
7
|
type: z.string(),
|
8
8
|
param: z.any().nullable(),
|
9
9
|
code: z.string().nullable(),
|
10
10
|
}),
|
11
|
-
})
|
11
|
+
});
|
12
12
|
export const failedOpenAICallResponseHandler = createJsonErrorResponseHandler({
|
13
|
-
errorSchema: openAIErrorDataSchema,
|
14
|
-
errorToMessage: (
|
15
|
-
isRetryable: (
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
errorSchema: zodSchema(openAIErrorDataSchema),
|
14
|
+
errorToMessage: (data) => data.error.message,
|
15
|
+
isRetryable: (response, error) => response.status >= 500 ||
|
16
|
+
(response.status === 429 &&
|
17
|
+
// insufficient_quota is also reported as a 429, but it's not retryable:
|
18
|
+
error?.error.type !== "insufficient_quota"),
|
19
19
|
});
|
@@ -1,13 +1,34 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ChatMessage = exports.Tokenizer = exports.ImageGenerator = exports.Transcriber = exports.SpeechGenerator = exports.TextEmbedder = exports.ChatTextGenerator = exports.CompletionTextGenerator = void 0;
|
3
|
+
exports.ChatMessage = exports.Tokenizer = exports.ImageGenerator = exports.Transcriber = exports.SpeechGenerator = exports.TextEmbedder = exports.ChatTextGenerator = exports.CompletionTextGenerator = exports.AzureApi = exports.Api = void 0;
|
4
|
+
const AzureOpenAIApiConfiguration_js_1 = require("./AzureOpenAIApiConfiguration.cjs");
|
5
|
+
const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
|
6
|
+
const OpenAIChatModel_js_1 = require("./OpenAIChatModel.cjs");
|
4
7
|
const OpenAICompletionModel_js_1 = require("./OpenAICompletionModel.cjs");
|
5
8
|
const OpenAIImageGenerationModel_js_1 = require("./OpenAIImageGenerationModel.cjs");
|
6
9
|
const OpenAISpeechModel_js_1 = require("./OpenAISpeechModel.cjs");
|
7
10
|
const OpenAITextEmbeddingModel_js_1 = require("./OpenAITextEmbeddingModel.cjs");
|
8
11
|
const OpenAITranscriptionModel_js_1 = require("./OpenAITranscriptionModel.cjs");
|
9
12
|
const TikTokenTokenizer_js_1 = require("./TikTokenTokenizer.cjs");
|
10
|
-
|
13
|
+
/**
|
14
|
+
* Creates an API configuration for the OpenAI API.
|
15
|
+
* It calls the API at https://api.openai.com/v1 and uses the `OPENAI_API_KEY` env variable by default.
|
16
|
+
*/
|
17
|
+
function Api(settings) {
|
18
|
+
return new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration(settings);
|
19
|
+
}
|
20
|
+
exports.Api = Api;
|
21
|
+
/**
|
22
|
+
* Configuration for the Azure OpenAI API. This class is responsible for constructing URLs specific to the Azure OpenAI deployment.
|
23
|
+
* It creates URLs of the form
|
24
|
+
* `https://[resourceName].openai.azure.com/openai/deployments/[deploymentId]/[path]?api-version=[apiVersion]`
|
25
|
+
*
|
26
|
+
* @see https://learn.microsoft.com/en-us/azure/ai-services/openai/reference
|
27
|
+
*/
|
28
|
+
function AzureApi(settings) {
|
29
|
+
return new AzureOpenAIApiConfiguration_js_1.AzureOpenAIApiConfiguration(settings);
|
30
|
+
}
|
31
|
+
exports.AzureApi = AzureApi;
|
11
32
|
/**
|
12
33
|
* Create a text generation model that calls the OpenAI text completion API.
|
13
34
|
*
|
@@ -1,10 +1,28 @@
|
|
1
|
+
import { PartialBaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlApiConfiguration.js";
|
2
|
+
import { AzureOpenAIApiConfiguration, AzureOpenAIApiConfigurationOptions } from "./AzureOpenAIApiConfiguration.js";
|
3
|
+
import { OpenAIApiConfiguration } from "./OpenAIApiConfiguration.js";
|
4
|
+
import { OpenAIChatModel, OpenAIChatSettings } from "./OpenAIChatModel.js";
|
1
5
|
import { OpenAICompletionModel, OpenAICompletionModelSettings } from "./OpenAICompletionModel.js";
|
2
6
|
import { OpenAIImageGenerationModel, OpenAIImageGenerationSettings } from "./OpenAIImageGenerationModel.js";
|
3
7
|
import { OpenAISpeechModel, OpenAISpeechModelSettings } from "./OpenAISpeechModel.js";
|
4
8
|
import { OpenAITextEmbeddingModel, OpenAITextEmbeddingModelSettings } from "./OpenAITextEmbeddingModel.js";
|
5
9
|
import { OpenAITranscriptionModel, OpenAITranscriptionModelSettings } from "./OpenAITranscriptionModel.js";
|
6
10
|
import { TikTokenTokenizer, TikTokenTokenizerSettings } from "./TikTokenTokenizer.js";
|
7
|
-
|
11
|
+
/**
|
12
|
+
* Creates an API configuration for the OpenAI API.
|
13
|
+
* It calls the API at https://api.openai.com/v1 and uses the `OPENAI_API_KEY` env variable by default.
|
14
|
+
*/
|
15
|
+
export declare function Api(settings: PartialBaseUrlPartsApiConfigurationOptions & {
|
16
|
+
apiKey?: string;
|
17
|
+
}): OpenAIApiConfiguration;
|
18
|
+
/**
|
19
|
+
* Configuration for the Azure OpenAI API. This class is responsible for constructing URLs specific to the Azure OpenAI deployment.
|
20
|
+
* It creates URLs of the form
|
21
|
+
* `https://[resourceName].openai.azure.com/openai/deployments/[deploymentId]/[path]?api-version=[apiVersion]`
|
22
|
+
*
|
23
|
+
* @see https://learn.microsoft.com/en-us/azure/ai-services/openai/reference
|
24
|
+
*/
|
25
|
+
export declare function AzureApi(settings: AzureOpenAIApiConfigurationOptions): AzureOpenAIApiConfiguration;
|
8
26
|
/**
|
9
27
|
* Create a text generation model that calls the OpenAI text completion API.
|
10
28
|
*
|
@@ -124,5 +142,5 @@ export declare function ImageGenerator(settings: OpenAIImageGenerationSettings):
|
|
124
142
|
* @returns A new instance of {@link TikTokenTokenizer}.
|
125
143
|
*/
|
126
144
|
export declare function Tokenizer(settings: TikTokenTokenizerSettings): TikTokenTokenizer;
|
127
|
-
export { OpenAIChatMessage as ChatMessage } from "./OpenAIChatMessage.js";
|
128
145
|
export { OpenAIChatPrompt as ChatPrompt } from "./AbstractOpenAIChatModel.js";
|
146
|
+
export { OpenAIChatMessage as ChatMessage } from "./OpenAIChatMessage.js";
|
@@ -1,10 +1,29 @@
|
|
1
|
+
import { AzureOpenAIApiConfiguration, } from "./AzureOpenAIApiConfiguration.js";
|
2
|
+
import { OpenAIApiConfiguration } from "./OpenAIApiConfiguration.js";
|
3
|
+
import { OpenAIChatModel } from "./OpenAIChatModel.js";
|
1
4
|
import { OpenAICompletionModel, } from "./OpenAICompletionModel.js";
|
2
5
|
import { OpenAIImageGenerationModel, } from "./OpenAIImageGenerationModel.js";
|
3
6
|
import { OpenAISpeechModel, } from "./OpenAISpeechModel.js";
|
4
7
|
import { OpenAITextEmbeddingModel, } from "./OpenAITextEmbeddingModel.js";
|
5
8
|
import { OpenAITranscriptionModel, } from "./OpenAITranscriptionModel.js";
|
6
9
|
import { TikTokenTokenizer, } from "./TikTokenTokenizer.js";
|
7
|
-
|
10
|
+
/**
|
11
|
+
* Creates an API configuration for the OpenAI API.
|
12
|
+
* It calls the API at https://api.openai.com/v1 and uses the `OPENAI_API_KEY` env variable by default.
|
13
|
+
*/
|
14
|
+
export function Api(settings) {
|
15
|
+
return new OpenAIApiConfiguration(settings);
|
16
|
+
}
|
17
|
+
/**
|
18
|
+
* Configuration for the Azure OpenAI API. This class is responsible for constructing URLs specific to the Azure OpenAI deployment.
|
19
|
+
* It creates URLs of the form
|
20
|
+
* `https://[resourceName].openai.azure.com/openai/deployments/[deploymentId]/[path]?api-version=[apiVersion]`
|
21
|
+
*
|
22
|
+
* @see https://learn.microsoft.com/en-us/azure/ai-services/openai/reference
|
23
|
+
*/
|
24
|
+
export function AzureApi(settings) {
|
25
|
+
return new AzureOpenAIApiConfiguration(settings);
|
26
|
+
}
|
8
27
|
/**
|
9
28
|
* Create a text generation model that calls the OpenAI text completion API.
|
10
29
|
*
|
@@ -4,6 +4,7 @@ exports.OpenAIImageGenerationResponseFormat = exports.OpenAIImageGenerationModel
|
|
4
4
|
const zod_1 = require("zod");
|
5
5
|
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
6
6
|
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
7
|
+
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
7
8
|
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
8
9
|
const PromptTemplateImageGenerationModel_js_1 = require("../../model-function/generate-image/PromptTemplateImageGenerationModel.cjs");
|
9
10
|
const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
|
@@ -89,28 +90,26 @@ class OpenAIImageGenerationModel extends AbstractModel_js_1.AbstractModel {
|
|
89
90
|
}
|
90
91
|
async callAPI(prompt, options) {
|
91
92
|
const api = this.settings.api ?? new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration();
|
92
|
-
const abortSignal = options
|
93
|
-
const userId = options
|
94
|
-
const responseFormat = options
|
93
|
+
const abortSignal = options.run?.abortSignal;
|
94
|
+
const userId = options.run?.userId;
|
95
|
+
const responseFormat = options.responseFormat;
|
95
96
|
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
96
97
|
retry: api.retry,
|
97
98
|
throttle: api.throttle,
|
98
|
-
call: async () => {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
});
|
113
|
-
},
|
99
|
+
call: async () => (0, postToApi_js_1.postJsonToApi)({
|
100
|
+
url: api.assembleUrl("/images/generations"),
|
101
|
+
headers: api.headers,
|
102
|
+
body: {
|
103
|
+
prompt,
|
104
|
+
n: this.settings.numberOfGenerations,
|
105
|
+
size: this.settings.size,
|
106
|
+
response_format: responseFormat.type,
|
107
|
+
user: this.settings.isUserIdForwardingEnabled ? userId : undefined,
|
108
|
+
},
|
109
|
+
failedResponseHandler: OpenAIError_js_1.failedOpenAICallResponseHandler,
|
110
|
+
successfulResponseHandler: responseFormat.handler,
|
111
|
+
abortSignal,
|
112
|
+
}),
|
114
113
|
});
|
115
114
|
}
|
116
115
|
get settingsForEvent() {
|
@@ -158,10 +157,10 @@ const openAIImageGenerationBase64JsonSchema = zod_1.z.object({
|
|
158
157
|
exports.OpenAIImageGenerationResponseFormat = {
|
159
158
|
url: {
|
160
159
|
type: "url",
|
161
|
-
handler: (0, postToApi_js_1.createJsonResponseHandler)(openAIImageGenerationUrlSchema),
|
160
|
+
handler: (0, postToApi_js_1.createJsonResponseHandler)((0, ZodSchema_js_1.zodSchema)(openAIImageGenerationUrlSchema)),
|
162
161
|
},
|
163
162
|
base64Json: {
|
164
163
|
type: "b64_json",
|
165
|
-
handler: (0, postToApi_js_1.createJsonResponseHandler)(openAIImageGenerationBase64JsonSchema),
|
164
|
+
handler: (0, postToApi_js_1.createJsonResponseHandler)((0, ZodSchema_js_1.zodSchema)(openAIImageGenerationBase64JsonSchema)),
|
166
165
|
},
|
167
166
|
};
|
@@ -11,7 +11,7 @@ export declare const OPENAI_IMAGE_MODELS: {
|
|
11
11
|
getCost(settings: OpenAIImageGenerationSettings): 2000 | 1800 | 1600 | null;
|
12
12
|
};
|
13
13
|
"dall-e-3": {
|
14
|
-
getCost(settings: OpenAIImageGenerationSettings):
|
14
|
+
getCost(settings: OpenAIImageGenerationSettings): 4000 | 8000 | 12000 | null;
|
15
15
|
};
|
16
16
|
};
|
17
17
|
/**
|