modelfusion 0.114.0 → 0.115.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 +12 -0
- package/README.md +5 -6
- package/model-provider/index.cjs +0 -1
- package/model-provider/index.d.ts +0 -1
- package/model-provider/index.js +0 -1
- package/model-provider/openai/AbstractOpenAIChatModel.cjs +2 -2
- package/model-provider/openai/AbstractOpenAIChatModel.d.ts +16 -16
- package/model-provider/openai/AbstractOpenAIChatModel.js +2 -2
- package/model-provider/openai/OpenAIChatFunctionCallStructureGenerationModel.d.ts +2 -2
- package/package.json +1 -1
- package/model-provider/anthropic/AnthropicApiConfiguration.cjs +0 -31
- package/model-provider/anthropic/AnthropicApiConfiguration.d.ts +0 -10
- package/model-provider/anthropic/AnthropicApiConfiguration.js +0 -27
- package/model-provider/anthropic/AnthropicError.cjs +0 -16
- package/model-provider/anthropic/AnthropicError.d.ts +0 -26
- package/model-provider/anthropic/AnthropicError.js +0 -13
- package/model-provider/anthropic/AnthropicFacade.cjs +0 -24
- package/model-provider/anthropic/AnthropicFacade.d.ts +0 -18
- package/model-provider/anthropic/AnthropicFacade.js +0 -19
- package/model-provider/anthropic/AnthropicPromptTemplate.cjs +0 -82
- package/model-provider/anthropic/AnthropicPromptTemplate.d.ts +0 -17
- package/model-provider/anthropic/AnthropicPromptTemplate.js +0 -76
- package/model-provider/anthropic/AnthropicPromptTemplate.test.cjs +0 -49
- package/model-provider/anthropic/AnthropicPromptTemplate.test.d.ts +0 -1
- package/model-provider/anthropic/AnthropicPromptTemplate.test.js +0 -47
- package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +0 -254
- package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +0 -153
- package/model-provider/anthropic/AnthropicTextGenerationModel.js +0 -250
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.cjs +0 -44
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.d.ts +0 -1
- package/model-provider/anthropic/AnthropicTextGenerationModel.test.js +0 -42
- package/model-provider/anthropic/index.cjs +0 -33
- package/model-provider/anthropic/index.d.ts +0 -5
- package/model-provider/anthropic/index.js +0 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.115.0 - 2024-01-05
|
4
|
+
|
5
|
+
### Removed
|
6
|
+
|
7
|
+
- Anthropic support. Anthropic has a strong stance against open-source models and against non-US AI. I will not support them by providing a ModelFusion integration.
|
8
|
+
|
9
|
+
## v0.114.1 - 2024-01-05
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
- Together AI text generation and text streaming using OpenAI-compatible chat models.
|
14
|
+
|
3
15
|
## v0.114.0 - 2024-01-05
|
4
16
|
|
5
17
|
### Added
|
package/README.md
CHANGED
@@ -59,7 +59,7 @@ const text = await generateText(
|
|
59
59
|
);
|
60
60
|
```
|
61
61
|
|
62
|
-
Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai), [OpenAI compatible](https://modelfusion.dev/integration/model-provider/openaicompatible), [Llama.cpp](https://modelfusion.dev/integration/model-provider/llamacpp), [Ollama](https://modelfusion.dev/integration/model-provider/ollama), [Mistral](https://modelfusion.dev/integration/model-provider/mistral), [Hugging Face](https://modelfusion.dev/integration/model-provider/huggingface), [Cohere](https://modelfusion.dev/integration/model-provider/cohere)
|
62
|
+
Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai), [OpenAI compatible](https://modelfusion.dev/integration/model-provider/openaicompatible), [Llama.cpp](https://modelfusion.dev/integration/model-provider/llamacpp), [Ollama](https://modelfusion.dev/integration/model-provider/ollama), [Mistral](https://modelfusion.dev/integration/model-provider/mistral), [Hugging Face](https://modelfusion.dev/integration/model-provider/huggingface), [Cohere](https://modelfusion.dev/integration/model-provider/cohere)
|
63
63
|
|
64
64
|
#### streamText
|
65
65
|
|
@@ -76,7 +76,7 @@ for await (const textPart of textStream) {
|
|
76
76
|
}
|
77
77
|
```
|
78
78
|
|
79
|
-
Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai), [OpenAI compatible](https://modelfusion.dev/integration/model-provider/openaicompatible), [Llama.cpp](https://modelfusion.dev/integration/model-provider/llamacpp), [Ollama](https://modelfusion.dev/integration/model-provider/ollama), [Mistral](https://modelfusion.dev/integration/model-provider/mistral), [Cohere](https://modelfusion.dev/integration/model-provider/cohere)
|
79
|
+
Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai), [OpenAI compatible](https://modelfusion.dev/integration/model-provider/openaicompatible), [Llama.cpp](https://modelfusion.dev/integration/model-provider/llamacpp), [Ollama](https://modelfusion.dev/integration/model-provider/ollama), [Mistral](https://modelfusion.dev/integration/model-provider/mistral), [Cohere](https://modelfusion.dev/integration/model-provider/cohere)
|
80
80
|
|
81
81
|
#### streamText with multi-modal prompt
|
82
82
|
|
@@ -412,9 +412,9 @@ Prompt templates let you use higher level prompt structures (such as text, instr
|
|
412
412
|
|
413
413
|
```ts
|
414
414
|
const text = await generateText(
|
415
|
-
|
416
|
-
.
|
417
|
-
|
415
|
+
openai
|
416
|
+
.ChatTextGenerator({
|
417
|
+
// ...
|
418
418
|
})
|
419
419
|
.withTextPrompt(),
|
420
420
|
"Write a short story about a robot learning to love"
|
@@ -473,7 +473,6 @@ const textStream = await streamText(
|
|
473
473
|
| Prompt Template | Text Prompt | Instruction Prompt | Chat Prompt |
|
474
474
|
| ---------------- | ----------- | ------------------ | ----------- |
|
475
475
|
| OpenAI Chat | ✅ | ✅ | ✅ |
|
476
|
-
| Anthropic | ✅ | ✅ | ✅ |
|
477
476
|
| Llama 2 | ✅ | ✅ | ✅ |
|
478
477
|
| ChatML | ✅ | ✅ | ✅ |
|
479
478
|
| NeuralChat | ✅ | ✅ | ✅ |
|
package/model-provider/index.cjs
CHANGED
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./anthropic/index.cjs"), exports);
|
18
17
|
__exportStar(require("./automatic1111/index.cjs"), exports);
|
19
18
|
__exportStar(require("./cohere/index.cjs"), exports);
|
20
19
|
__exportStar(require("./elevenlabs/index.cjs"), exports);
|
package/model-provider/index.js
CHANGED
@@ -219,7 +219,7 @@ const openAIChatResponseSchema = zod_1.z.object({
|
|
219
219
|
}))
|
220
220
|
.optional(),
|
221
221
|
}),
|
222
|
-
index: zod_1.z.number(),
|
222
|
+
index: zod_1.z.number().optional(), // optional for OpenAI compatible models
|
223
223
|
logprobs: zod_1.z.nullable(zod_1.z.any()),
|
224
224
|
finish_reason: zod_1.z
|
225
225
|
.enum([
|
@@ -279,7 +279,7 @@ const openaiChatChunkSchema = zod_1.z.object({
|
|
279
279
|
index: zod_1.z.number(),
|
280
280
|
})),
|
281
281
|
created: zod_1.z.number(),
|
282
|
-
model: zod_1.z.string(),
|
282
|
+
model: zod_1.z.string().optional(), // optional for OpenAI compatible models
|
283
283
|
system_fingerprint: zod_1.z.string().optional().nullable(),
|
284
284
|
});
|
285
285
|
exports.OpenAIChatResponseFormat = {
|
@@ -117,7 +117,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
117
117
|
id: string;
|
118
118
|
}[] | undefined;
|
119
119
|
};
|
120
|
-
index
|
120
|
+
index?: number | undefined;
|
121
121
|
logprobs?: any;
|
122
122
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
123
123
|
}[];
|
@@ -161,7 +161,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
161
161
|
id: string;
|
162
162
|
}[] | undefined;
|
163
163
|
};
|
164
|
-
index
|
164
|
+
index?: number | undefined;
|
165
165
|
logprobs?: any;
|
166
166
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
167
167
|
}[];
|
@@ -205,7 +205,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
205
205
|
id: string;
|
206
206
|
}[] | undefined;
|
207
207
|
};
|
208
|
-
index
|
208
|
+
index?: number | undefined;
|
209
209
|
logprobs?: any;
|
210
210
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
211
211
|
}[];
|
@@ -224,7 +224,6 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
224
224
|
private translateFinishReason;
|
225
225
|
doStreamText(prompt: OpenAIChatPrompt, options: FunctionCallOptions): Promise<AsyncIterable<import("../../index.js").Delta<{
|
226
226
|
object: "chat.completion.chunk";
|
227
|
-
model: string;
|
228
227
|
id: string;
|
229
228
|
created: number;
|
230
229
|
choices: {
|
@@ -247,6 +246,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
247
246
|
index: number;
|
248
247
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
249
248
|
}[];
|
249
|
+
model?: string | undefined;
|
250
250
|
system_fingerprint?: string | null | undefined;
|
251
251
|
}>>>;
|
252
252
|
extractTextDelta(delta: unknown): string | undefined;
|
@@ -278,7 +278,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
278
278
|
id: string;
|
279
279
|
}[] | undefined;
|
280
280
|
};
|
281
|
-
index
|
281
|
+
index?: number | undefined;
|
282
282
|
logprobs?: any;
|
283
283
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
284
284
|
}[];
|
@@ -322,7 +322,7 @@ export declare abstract class AbstractOpenAIChatModel<SETTINGS extends AbstractO
|
|
322
322
|
id: string;
|
323
323
|
}[] | undefined;
|
324
324
|
};
|
325
|
-
index
|
325
|
+
index?: number | undefined;
|
326
326
|
logprobs?: any;
|
327
327
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
328
328
|
}[];
|
@@ -421,7 +421,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
|
|
421
421
|
id: string;
|
422
422
|
}[] | undefined;
|
423
423
|
}>;
|
424
|
-
index: z.ZodNumber
|
424
|
+
index: z.ZodOptional<z.ZodNumber>;
|
425
425
|
logprobs: z.ZodNullable<z.ZodAny>;
|
426
426
|
finish_reason: z.ZodNullable<z.ZodOptional<z.ZodEnum<["stop", "length", "tool_calls", "content_filter", "function_call"]>>>;
|
427
427
|
}, "strip", z.ZodTypeAny, {
|
@@ -441,7 +441,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
|
|
441
441
|
id: string;
|
442
442
|
}[] | undefined;
|
443
443
|
};
|
444
|
-
index
|
444
|
+
index?: number | undefined;
|
445
445
|
logprobs?: any;
|
446
446
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
447
447
|
}, {
|
@@ -461,7 +461,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
|
|
461
461
|
id: string;
|
462
462
|
}[] | undefined;
|
463
463
|
};
|
464
|
-
index
|
464
|
+
index?: number | undefined;
|
465
465
|
logprobs?: any;
|
466
466
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
467
467
|
}>, "many">;
|
@@ -509,7 +509,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
|
|
509
509
|
id: string;
|
510
510
|
}[] | undefined;
|
511
511
|
};
|
512
|
-
index
|
512
|
+
index?: number | undefined;
|
513
513
|
logprobs?: any;
|
514
514
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
515
515
|
}[];
|
@@ -541,7 +541,7 @@ declare const openAIChatResponseSchema: z.ZodObject<{
|
|
541
541
|
id: string;
|
542
542
|
}[] | undefined;
|
543
543
|
};
|
544
|
-
index
|
544
|
+
index?: number | undefined;
|
545
545
|
logprobs?: any;
|
546
546
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
547
547
|
}[];
|
@@ -666,11 +666,10 @@ declare const openaiChatChunkSchema: z.ZodObject<{
|
|
666
666
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
667
667
|
}>, "many">;
|
668
668
|
created: z.ZodNumber;
|
669
|
-
model: z.ZodString
|
669
|
+
model: z.ZodOptional<z.ZodString>;
|
670
670
|
system_fingerprint: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
671
671
|
}, "strip", z.ZodTypeAny, {
|
672
672
|
object: "chat.completion.chunk";
|
673
|
-
model: string;
|
674
673
|
id: string;
|
675
674
|
created: number;
|
676
675
|
choices: {
|
@@ -693,10 +692,10 @@ declare const openaiChatChunkSchema: z.ZodObject<{
|
|
693
692
|
index: number;
|
694
693
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
695
694
|
}[];
|
695
|
+
model?: string | undefined;
|
696
696
|
system_fingerprint?: string | null | undefined;
|
697
697
|
}, {
|
698
698
|
object: "chat.completion.chunk";
|
699
|
-
model: string;
|
700
699
|
id: string;
|
701
700
|
created: number;
|
702
701
|
choices: {
|
@@ -719,6 +718,7 @@ declare const openaiChatChunkSchema: z.ZodObject<{
|
|
719
718
|
index: number;
|
720
719
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
721
720
|
}[];
|
721
|
+
model?: string | undefined;
|
722
722
|
system_fingerprint?: string | null | undefined;
|
723
723
|
}>;
|
724
724
|
export type OpenAIChatChunk = z.infer<typeof openaiChatChunkSchema>;
|
@@ -759,7 +759,7 @@ export declare const OpenAIChatResponseFormat: {
|
|
759
759
|
id: string;
|
760
760
|
}[] | undefined;
|
761
761
|
};
|
762
|
-
index
|
762
|
+
index?: number | undefined;
|
763
763
|
logprobs?: any;
|
764
764
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
765
765
|
}[];
|
@@ -775,7 +775,6 @@ export declare const OpenAIChatResponseFormat: {
|
|
775
775
|
response: Response;
|
776
776
|
}) => Promise<AsyncIterable<import("../../index.js").Delta<{
|
777
777
|
object: "chat.completion.chunk";
|
778
|
-
model: string;
|
779
778
|
id: string;
|
780
779
|
created: number;
|
781
780
|
choices: {
|
@@ -798,6 +797,7 @@ export declare const OpenAIChatResponseFormat: {
|
|
798
797
|
index: number;
|
799
798
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
800
799
|
}[];
|
800
|
+
model?: string | undefined;
|
801
801
|
system_fingerprint?: string | null | undefined;
|
802
802
|
}>>>;
|
803
803
|
};
|
@@ -215,7 +215,7 @@ const openAIChatResponseSchema = z.object({
|
|
215
215
|
}))
|
216
216
|
.optional(),
|
217
217
|
}),
|
218
|
-
index: z.number(),
|
218
|
+
index: z.number().optional(), // optional for OpenAI compatible models
|
219
219
|
logprobs: z.nullable(z.any()),
|
220
220
|
finish_reason: z
|
221
221
|
.enum([
|
@@ -275,7 +275,7 @@ const openaiChatChunkSchema = z.object({
|
|
275
275
|
index: z.number(),
|
276
276
|
})),
|
277
277
|
created: z.number(),
|
278
|
-
model: z.string(),
|
278
|
+
model: z.string().optional(), // optional for OpenAI compatible models
|
279
279
|
system_fingerprint: z.string().optional().nullable(),
|
280
280
|
});
|
281
281
|
export const OpenAIChatResponseFormat = {
|
@@ -154,7 +154,7 @@ OpenAIChatSettings> {
|
|
154
154
|
id: string;
|
155
155
|
}[] | undefined;
|
156
156
|
};
|
157
|
-
index
|
157
|
+
index?: number | undefined;
|
158
158
|
logprobs?: any;
|
159
159
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
160
160
|
}[];
|
@@ -171,7 +171,6 @@ OpenAIChatSettings> {
|
|
171
171
|
doStreamStructure(schema: Schema<unknown> & JsonSchemaProducer, prompt: Parameters<PROMPT_TEMPLATE["format"]>[0], // first argument of the function
|
172
172
|
options: FunctionCallOptions): Promise<AsyncIterable<import("../../index.js").Delta<{
|
173
173
|
object: "chat.completion.chunk";
|
174
|
-
model: string;
|
175
174
|
id: string;
|
176
175
|
created: number;
|
177
176
|
choices: {
|
@@ -194,6 +193,7 @@ OpenAIChatSettings> {
|
|
194
193
|
index: number;
|
195
194
|
finish_reason?: "length" | "stop" | "function_call" | "tool_calls" | "content_filter" | null | undefined;
|
196
195
|
}[];
|
196
|
+
model?: string | undefined;
|
197
197
|
system_fingerprint?: string | null | undefined;
|
198
198
|
}>>>;
|
199
199
|
extractStructureTextDelta(delta: unknown): string | undefined;
|
package/package.json
CHANGED
@@ -1,31 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.AnthropicApiConfiguration = void 0;
|
4
|
-
const BaseUrlApiConfiguration_js_1 = require("../../core/api/BaseUrlApiConfiguration.cjs");
|
5
|
-
const loadApiKey_js_1 = require("../../core/api/loadApiKey.cjs");
|
6
|
-
/**
|
7
|
-
* Creates an API configuration for the Anthropic API.
|
8
|
-
* It calls the API at https://api.anthropic.com/v1 and uses the `ANTHROPIC_API_KEY` env variable by default.
|
9
|
-
*/
|
10
|
-
class AnthropicApiConfiguration extends BaseUrlApiConfiguration_js_1.BaseUrlApiConfigurationWithDefaults {
|
11
|
-
constructor(settings = {}) {
|
12
|
-
super({
|
13
|
-
...settings,
|
14
|
-
headers: {
|
15
|
-
"x-api-key": (0, loadApiKey_js_1.loadApiKey)({
|
16
|
-
apiKey: settings.apiKey,
|
17
|
-
environmentVariableName: "ANTHROPIC_API_KEY",
|
18
|
-
description: "Anthropic",
|
19
|
-
}),
|
20
|
-
"anthropic-version": "2023-06-01",
|
21
|
-
},
|
22
|
-
baseUrlDefaults: {
|
23
|
-
protocol: "https",
|
24
|
-
host: "api.anthropic.com",
|
25
|
-
port: "443",
|
26
|
-
path: "/v1",
|
27
|
-
},
|
28
|
-
});
|
29
|
-
}
|
30
|
-
}
|
31
|
-
exports.AnthropicApiConfiguration = AnthropicApiConfiguration;
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlApiConfiguration.js";
|
2
|
-
/**
|
3
|
-
* Creates an API configuration for the Anthropic API.
|
4
|
-
* It calls the API at https://api.anthropic.com/v1 and uses the `ANTHROPIC_API_KEY` env variable by default.
|
5
|
-
*/
|
6
|
-
export declare class AnthropicApiConfiguration extends BaseUrlApiConfigurationWithDefaults {
|
7
|
-
constructor(settings?: PartialBaseUrlPartsApiConfigurationOptions & {
|
8
|
-
apiKey?: string;
|
9
|
-
});
|
10
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { BaseUrlApiConfigurationWithDefaults, } from "../../core/api/BaseUrlApiConfiguration.js";
|
2
|
-
import { loadApiKey } from "../../core/api/loadApiKey.js";
|
3
|
-
/**
|
4
|
-
* Creates an API configuration for the Anthropic API.
|
5
|
-
* It calls the API at https://api.anthropic.com/v1 and uses the `ANTHROPIC_API_KEY` env variable by default.
|
6
|
-
*/
|
7
|
-
export class AnthropicApiConfiguration extends BaseUrlApiConfigurationWithDefaults {
|
8
|
-
constructor(settings = {}) {
|
9
|
-
super({
|
10
|
-
...settings,
|
11
|
-
headers: {
|
12
|
-
"x-api-key": loadApiKey({
|
13
|
-
apiKey: settings.apiKey,
|
14
|
-
environmentVariableName: "ANTHROPIC_API_KEY",
|
15
|
-
description: "Anthropic",
|
16
|
-
}),
|
17
|
-
"anthropic-version": "2023-06-01",
|
18
|
-
},
|
19
|
-
baseUrlDefaults: {
|
20
|
-
protocol: "https",
|
21
|
-
host: "api.anthropic.com",
|
22
|
-
port: "443",
|
23
|
-
path: "/v1",
|
24
|
-
},
|
25
|
-
});
|
26
|
-
}
|
27
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.failedAnthropicCallResponseHandler = void 0;
|
4
|
-
const zod_1 = require("zod");
|
5
|
-
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
6
|
-
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
7
|
-
const anthropicErrorDataSchema = zod_1.z.object({
|
8
|
-
error: zod_1.z.object({
|
9
|
-
type: zod_1.z.string(),
|
10
|
-
message: zod_1.z.string(),
|
11
|
-
}),
|
12
|
-
});
|
13
|
-
exports.failedAnthropicCallResponseHandler = (0, postToApi_js_1.createJsonErrorResponseHandler)({
|
14
|
-
errorSchema: (0, ZodSchema_js_1.zodSchema)(anthropicErrorDataSchema),
|
15
|
-
errorToMessage: (error) => error.error.message,
|
16
|
-
});
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
declare const anthropicErrorDataSchema: z.ZodObject<{
|
3
|
-
error: z.ZodObject<{
|
4
|
-
type: z.ZodString;
|
5
|
-
message: z.ZodString;
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
7
|
-
message: string;
|
8
|
-
type: string;
|
9
|
-
}, {
|
10
|
-
message: string;
|
11
|
-
type: string;
|
12
|
-
}>;
|
13
|
-
}, "strip", z.ZodTypeAny, {
|
14
|
-
error: {
|
15
|
-
message: string;
|
16
|
-
type: string;
|
17
|
-
};
|
18
|
-
}, {
|
19
|
-
error: {
|
20
|
-
message: string;
|
21
|
-
type: string;
|
22
|
-
};
|
23
|
-
}>;
|
24
|
-
export type AnthropicErrorData = z.infer<typeof anthropicErrorDataSchema>;
|
25
|
-
export declare const failedAnthropicCallResponseHandler: import("../../core/api/postToApi.js").ResponseHandler<import("../../index.js").ApiCallError>;
|
26
|
-
export {};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
import { createJsonErrorResponseHandler } from "../../core/api/postToApi.js";
|
3
|
-
import { zodSchema } from "../../core/schema/ZodSchema.js";
|
4
|
-
const anthropicErrorDataSchema = z.object({
|
5
|
-
error: z.object({
|
6
|
-
type: z.string(),
|
7
|
-
message: z.string(),
|
8
|
-
}),
|
9
|
-
});
|
10
|
-
export const failedAnthropicCallResponseHandler = createJsonErrorResponseHandler({
|
11
|
-
errorSchema: zodSchema(anthropicErrorDataSchema),
|
12
|
-
errorToMessage: (error) => error.error.message,
|
13
|
-
});
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TextGenerator = exports.Api = void 0;
|
4
|
-
const AnthropicApiConfiguration_js_1 = require("./AnthropicApiConfiguration.cjs");
|
5
|
-
const AnthropicTextGenerationModel_js_1 = require("./AnthropicTextGenerationModel.cjs");
|
6
|
-
/**
|
7
|
-
* Creates an API configuration for the Anthropic API.
|
8
|
-
* It calls the API at https://api.anthropic.com/v1 and uses the `ANTHROPIC_API_KEY` env variable by default.
|
9
|
-
*/
|
10
|
-
function Api(settings) {
|
11
|
-
return new AnthropicApiConfiguration_js_1.AnthropicApiConfiguration(settings);
|
12
|
-
}
|
13
|
-
exports.Api = Api;
|
14
|
-
/**
|
15
|
-
* Create a text generation model that calls the Anthropic API.
|
16
|
-
*
|
17
|
-
* @see https://docs.anthropic.com/claude/reference/complete_post
|
18
|
-
*
|
19
|
-
* @return A new instance of {@link AnthropicTextGenerationModel}.
|
20
|
-
*/
|
21
|
-
function TextGenerator(settings) {
|
22
|
-
return new AnthropicTextGenerationModel_js_1.AnthropicTextGenerationModel(settings);
|
23
|
-
}
|
24
|
-
exports.TextGenerator = TextGenerator;
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { PartialBaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlApiConfiguration.js";
|
2
|
-
import { AnthropicApiConfiguration } from "./AnthropicApiConfiguration.js";
|
3
|
-
import { AnthropicTextGenerationModel, AnthropicTextGenerationModelSettings } from "./AnthropicTextGenerationModel.js";
|
4
|
-
/**
|
5
|
-
* Creates an API configuration for the Anthropic API.
|
6
|
-
* It calls the API at https://api.anthropic.com/v1 and uses the `ANTHROPIC_API_KEY` env variable by default.
|
7
|
-
*/
|
8
|
-
export declare function Api(settings: PartialBaseUrlPartsApiConfigurationOptions & {
|
9
|
-
apiKey?: string;
|
10
|
-
}): AnthropicApiConfiguration;
|
11
|
-
/**
|
12
|
-
* Create a text generation model that calls the Anthropic API.
|
13
|
-
*
|
14
|
-
* @see https://docs.anthropic.com/claude/reference/complete_post
|
15
|
-
*
|
16
|
-
* @return A new instance of {@link AnthropicTextGenerationModel}.
|
17
|
-
*/
|
18
|
-
export declare function TextGenerator(settings: AnthropicTextGenerationModelSettings): AnthropicTextGenerationModel;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { AnthropicApiConfiguration } from "./AnthropicApiConfiguration.js";
|
2
|
-
import { AnthropicTextGenerationModel, } from "./AnthropicTextGenerationModel.js";
|
3
|
-
/**
|
4
|
-
* Creates an API configuration for the Anthropic API.
|
5
|
-
* It calls the API at https://api.anthropic.com/v1 and uses the `ANTHROPIC_API_KEY` env variable by default.
|
6
|
-
*/
|
7
|
-
export function Api(settings) {
|
8
|
-
return new AnthropicApiConfiguration(settings);
|
9
|
-
}
|
10
|
-
/**
|
11
|
-
* Create a text generation model that calls the Anthropic API.
|
12
|
-
*
|
13
|
-
* @see https://docs.anthropic.com/claude/reference/complete_post
|
14
|
-
*
|
15
|
-
* @return A new instance of {@link AnthropicTextGenerationModel}.
|
16
|
-
*/
|
17
|
-
export function TextGenerator(settings) {
|
18
|
-
return new AnthropicTextGenerationModel(settings);
|
19
|
-
}
|
@@ -1,82 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.chat = exports.instruction = exports.text = void 0;
|
4
|
-
const ContentPart_js_1 = require("../../model-function/generate-text/prompt-template/ContentPart.cjs");
|
5
|
-
const InvalidPromptError_js_1 = require("../../model-function/generate-text/prompt-template/InvalidPromptError.cjs");
|
6
|
-
const HUMAN_PREFIX = "\n\nHuman:";
|
7
|
-
const ASSISTANT_PREFIX = "\n\nAssistant:";
|
8
|
-
/**
|
9
|
-
* Formats a text prompt as an Anthropic prompt.
|
10
|
-
*/
|
11
|
-
function text() {
|
12
|
-
return {
|
13
|
-
format(prompt) {
|
14
|
-
let text = "";
|
15
|
-
text += HUMAN_PREFIX;
|
16
|
-
text += prompt;
|
17
|
-
text += ASSISTANT_PREFIX;
|
18
|
-
return text;
|
19
|
-
},
|
20
|
-
stopSequences: [],
|
21
|
-
};
|
22
|
-
}
|
23
|
-
exports.text = text;
|
24
|
-
/**
|
25
|
-
* Formats an instruction prompt as an Anthropic prompt.
|
26
|
-
*/
|
27
|
-
function instruction() {
|
28
|
-
return {
|
29
|
-
format(prompt) {
|
30
|
-
const instruction = (0, ContentPart_js_1.validateContentIsString)(prompt.instruction, prompt);
|
31
|
-
let text = prompt.system ?? "";
|
32
|
-
text += HUMAN_PREFIX;
|
33
|
-
text += instruction;
|
34
|
-
text += ASSISTANT_PREFIX;
|
35
|
-
if (prompt.responsePrefix != null) {
|
36
|
-
text += prompt.responsePrefix;
|
37
|
-
}
|
38
|
-
return text;
|
39
|
-
},
|
40
|
-
stopSequences: [],
|
41
|
-
};
|
42
|
-
}
|
43
|
-
exports.instruction = instruction;
|
44
|
-
/**
|
45
|
-
* Formats a chat prompt as an Anthropic prompt.
|
46
|
-
*
|
47
|
-
* @see https://docs.anthropic.com/claude/docs/constructing-a-prompt
|
48
|
-
*/
|
49
|
-
function chat() {
|
50
|
-
return {
|
51
|
-
format(prompt) {
|
52
|
-
let text = prompt.system ?? "";
|
53
|
-
for (const { role, content } of prompt.messages) {
|
54
|
-
switch (role) {
|
55
|
-
case "user": {
|
56
|
-
const textContent = (0, ContentPart_js_1.validateContentIsString)(content, prompt);
|
57
|
-
text += HUMAN_PREFIX;
|
58
|
-
text += textContent;
|
59
|
-
break;
|
60
|
-
}
|
61
|
-
case "assistant": {
|
62
|
-
text += ASSISTANT_PREFIX;
|
63
|
-
text += content;
|
64
|
-
break;
|
65
|
-
}
|
66
|
-
case "tool": {
|
67
|
-
throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
|
68
|
-
}
|
69
|
-
default: {
|
70
|
-
const _exhaustiveCheck = role;
|
71
|
-
throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
// AI message prefix:
|
76
|
-
text += ASSISTANT_PREFIX;
|
77
|
-
return text;
|
78
|
-
},
|
79
|
-
stopSequences: [],
|
80
|
-
};
|
81
|
-
}
|
82
|
-
exports.chat = chat;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
|
2
|
-
import { ChatPrompt } from "../../model-function/generate-text/prompt-template/ChatPrompt.js";
|
3
|
-
import { InstructionPrompt } from "../../model-function/generate-text/prompt-template/InstructionPrompt.js";
|
4
|
-
/**
|
5
|
-
* Formats a text prompt as an Anthropic prompt.
|
6
|
-
*/
|
7
|
-
export declare function text(): TextGenerationPromptTemplate<string, string>;
|
8
|
-
/**
|
9
|
-
* Formats an instruction prompt as an Anthropic prompt.
|
10
|
-
*/
|
11
|
-
export declare function instruction(): TextGenerationPromptTemplate<InstructionPrompt, string>;
|
12
|
-
/**
|
13
|
-
* Formats a chat prompt as an Anthropic prompt.
|
14
|
-
*
|
15
|
-
* @see https://docs.anthropic.com/claude/docs/constructing-a-prompt
|
16
|
-
*/
|
17
|
-
export declare function chat(): TextGenerationPromptTemplate<ChatPrompt, string>;
|