modelfusion 0.114.1 → 0.116.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 +52 -0
- package/README.md +5 -6
- package/classifier/SemanticClassifier.cjs +75 -0
- package/classifier/SemanticClassifier.d.ts +28 -0
- package/classifier/SemanticClassifier.js +71 -0
- package/classifier/index.cjs +17 -0
- package/classifier/index.d.ts +1 -0
- package/classifier/index.js +1 -0
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- 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/mistral/MistralTextEmbeddingModel.d.ts +13 -13
- package/model-provider/ollama/OllamaChatModel.d.ts +9 -9
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
- 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,57 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.116.0 - 2024-01-05
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Semantic classifier. An easy way to determine a class of a text using embeddings. Example:
|
8
|
+
|
9
|
+
```ts
|
10
|
+
import { SemanticClassifier, openai } from "modelfusion";
|
11
|
+
|
12
|
+
const classifier = new SemanticClassifier({
|
13
|
+
embeddingModel: openai.TextEmbedder({
|
14
|
+
model: "text-embedding-ada-002",
|
15
|
+
}),
|
16
|
+
similarityThreshold: 0.82,
|
17
|
+
clusters: [
|
18
|
+
{
|
19
|
+
name: "politics" as const,
|
20
|
+
values: [
|
21
|
+
"isn't politics the best thing ever",
|
22
|
+
"why don't you tell me about your political opinions",
|
23
|
+
"don't you just love the president",
|
24
|
+
"don't you just hate the president",
|
25
|
+
"they're going to destroy this country!",
|
26
|
+
"they will save the country!",
|
27
|
+
],
|
28
|
+
},
|
29
|
+
{
|
30
|
+
name: "chitchat" as const,
|
31
|
+
values: [
|
32
|
+
"how's the weather today?",
|
33
|
+
"how are things going?",
|
34
|
+
"lovely weather today",
|
35
|
+
"the weather is horrendous",
|
36
|
+
"let's go to the chippy",
|
37
|
+
],
|
38
|
+
},
|
39
|
+
],
|
40
|
+
});
|
41
|
+
|
42
|
+
console.log(await classifier.classify("don't you love politics?")); // politics
|
43
|
+
console.log(await classifier.classify("how's the weather today?")); // chitchat
|
44
|
+
console.log(
|
45
|
+
await classifier.classify("I'm interested in learning about llama 2")
|
46
|
+
); // null
|
47
|
+
```
|
48
|
+
|
49
|
+
## v0.115.0 - 2024-01-05
|
50
|
+
|
51
|
+
### Removed
|
52
|
+
|
53
|
+
- 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.
|
54
|
+
|
3
55
|
## v0.114.1 - 2024-01-05
|
4
56
|
|
5
57
|
### Fixed
|
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 | ✅ | ✅ | ✅ |
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SemanticClassifier = void 0;
|
4
|
+
const embed_js_1 = require("../model-function/embed/embed.cjs");
|
5
|
+
const cosineSimilarity_js_1 = require("../util/cosineSimilarity.cjs");
|
6
|
+
class SemanticClassifier {
|
7
|
+
constructor({ clusters, embeddingModel, similarityThreshold, }) {
|
8
|
+
Object.defineProperty(this, "clusters", {
|
9
|
+
enumerable: true,
|
10
|
+
configurable: true,
|
11
|
+
writable: true,
|
12
|
+
value: void 0
|
13
|
+
});
|
14
|
+
Object.defineProperty(this, "embeddingModel", {
|
15
|
+
enumerable: true,
|
16
|
+
configurable: true,
|
17
|
+
writable: true,
|
18
|
+
value: void 0
|
19
|
+
});
|
20
|
+
Object.defineProperty(this, "similarityThreshold", {
|
21
|
+
enumerable: true,
|
22
|
+
configurable: true,
|
23
|
+
writable: true,
|
24
|
+
value: void 0
|
25
|
+
});
|
26
|
+
Object.defineProperty(this, "embeddings", {
|
27
|
+
enumerable: true,
|
28
|
+
configurable: true,
|
29
|
+
writable: true,
|
30
|
+
value: void 0
|
31
|
+
});
|
32
|
+
this.clusters = clusters;
|
33
|
+
this.embeddingModel = embeddingModel;
|
34
|
+
this.similarityThreshold = similarityThreshold;
|
35
|
+
}
|
36
|
+
async getEmbeddings() {
|
37
|
+
if (this.embeddings != null) {
|
38
|
+
return this.embeddings;
|
39
|
+
}
|
40
|
+
const embeddings = [];
|
41
|
+
for (const cluster of this.clusters) {
|
42
|
+
const clusterEmbeddings = await (0, embed_js_1.embedMany)(this.embeddingModel, cluster.values);
|
43
|
+
for (let i = 0; i < clusterEmbeddings.length; i++) {
|
44
|
+
embeddings.push({
|
45
|
+
embedding: clusterEmbeddings[i],
|
46
|
+
clusterValue: cluster.values[i],
|
47
|
+
clusterName: cluster.name,
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}
|
51
|
+
this.embeddings = embeddings; // lazy caching
|
52
|
+
return embeddings;
|
53
|
+
}
|
54
|
+
async classify(value) {
|
55
|
+
const valueEmbedding = await (0, embed_js_1.embed)(this.embeddingModel, value);
|
56
|
+
const clusterEmbeddings = await this.getEmbeddings();
|
57
|
+
const allMatches = [];
|
58
|
+
for (const embedding of clusterEmbeddings) {
|
59
|
+
const similarity = (0, cosineSimilarity_js_1.cosineSimilarity)(valueEmbedding, embedding.embedding);
|
60
|
+
if (similarity >= this.similarityThreshold) {
|
61
|
+
allMatches.push({
|
62
|
+
similarity,
|
63
|
+
clusterValue: embedding.clusterValue,
|
64
|
+
clusterName: embedding.clusterName,
|
65
|
+
});
|
66
|
+
}
|
67
|
+
}
|
68
|
+
// sort (highest similarity first)
|
69
|
+
allMatches.sort((a, b) => b.similarity - a.similarity);
|
70
|
+
return allMatches.length > 0
|
71
|
+
? allMatches[0].clusterName
|
72
|
+
: null;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
exports.SemanticClassifier = SemanticClassifier;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Vector } from "../core/Vector.js";
|
2
|
+
import { EmbeddingModel } from "../model-function/embed/EmbeddingModel.js";
|
3
|
+
export interface SemanticCluster<VALUE, NAME extends string> {
|
4
|
+
name: NAME;
|
5
|
+
values: VALUE[];
|
6
|
+
}
|
7
|
+
export declare class SemanticClassifier<VALUE, CLUSTERS extends Array<SemanticCluster<VALUE, string>>> {
|
8
|
+
readonly clusters: CLUSTERS;
|
9
|
+
readonly embeddingModel: EmbeddingModel<VALUE>;
|
10
|
+
readonly similarityThreshold: number;
|
11
|
+
private embeddings;
|
12
|
+
constructor({ clusters, embeddingModel, similarityThreshold, }: {
|
13
|
+
clusters: CLUSTERS;
|
14
|
+
embeddingModel: EmbeddingModel<VALUE>;
|
15
|
+
similarityThreshold: number;
|
16
|
+
});
|
17
|
+
getEmbeddings(): Promise<{
|
18
|
+
embedding: Vector;
|
19
|
+
clusterValue: VALUE;
|
20
|
+
clusterName: string;
|
21
|
+
}[]>;
|
22
|
+
classify(value: VALUE): Promise<ClusterNames<CLUSTERS> | null>;
|
23
|
+
}
|
24
|
+
type ClusterArray<T extends SemanticCluster<any, any>[]> = T;
|
25
|
+
type ClusterNames<T extends ClusterArray<SemanticCluster<any, any>[]>> = {
|
26
|
+
[K in T[number]["name"]]: Extract<T[number], SemanticCluster<any, K>>;
|
27
|
+
}[T[number]["name"]];
|
28
|
+
export {};
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import { embed, embedMany } from "../model-function/embed/embed.js";
|
2
|
+
import { cosineSimilarity } from "../util/cosineSimilarity.js";
|
3
|
+
export class SemanticClassifier {
|
4
|
+
constructor({ clusters, embeddingModel, similarityThreshold, }) {
|
5
|
+
Object.defineProperty(this, "clusters", {
|
6
|
+
enumerable: true,
|
7
|
+
configurable: true,
|
8
|
+
writable: true,
|
9
|
+
value: void 0
|
10
|
+
});
|
11
|
+
Object.defineProperty(this, "embeddingModel", {
|
12
|
+
enumerable: true,
|
13
|
+
configurable: true,
|
14
|
+
writable: true,
|
15
|
+
value: void 0
|
16
|
+
});
|
17
|
+
Object.defineProperty(this, "similarityThreshold", {
|
18
|
+
enumerable: true,
|
19
|
+
configurable: true,
|
20
|
+
writable: true,
|
21
|
+
value: void 0
|
22
|
+
});
|
23
|
+
Object.defineProperty(this, "embeddings", {
|
24
|
+
enumerable: true,
|
25
|
+
configurable: true,
|
26
|
+
writable: true,
|
27
|
+
value: void 0
|
28
|
+
});
|
29
|
+
this.clusters = clusters;
|
30
|
+
this.embeddingModel = embeddingModel;
|
31
|
+
this.similarityThreshold = similarityThreshold;
|
32
|
+
}
|
33
|
+
async getEmbeddings() {
|
34
|
+
if (this.embeddings != null) {
|
35
|
+
return this.embeddings;
|
36
|
+
}
|
37
|
+
const embeddings = [];
|
38
|
+
for (const cluster of this.clusters) {
|
39
|
+
const clusterEmbeddings = await embedMany(this.embeddingModel, cluster.values);
|
40
|
+
for (let i = 0; i < clusterEmbeddings.length; i++) {
|
41
|
+
embeddings.push({
|
42
|
+
embedding: clusterEmbeddings[i],
|
43
|
+
clusterValue: cluster.values[i],
|
44
|
+
clusterName: cluster.name,
|
45
|
+
});
|
46
|
+
}
|
47
|
+
}
|
48
|
+
this.embeddings = embeddings; // lazy caching
|
49
|
+
return embeddings;
|
50
|
+
}
|
51
|
+
async classify(value) {
|
52
|
+
const valueEmbedding = await embed(this.embeddingModel, value);
|
53
|
+
const clusterEmbeddings = await this.getEmbeddings();
|
54
|
+
const allMatches = [];
|
55
|
+
for (const embedding of clusterEmbeddings) {
|
56
|
+
const similarity = cosineSimilarity(valueEmbedding, embedding.embedding);
|
57
|
+
if (similarity >= this.similarityThreshold) {
|
58
|
+
allMatches.push({
|
59
|
+
similarity,
|
60
|
+
clusterValue: embedding.clusterValue,
|
61
|
+
clusterName: embedding.clusterName,
|
62
|
+
});
|
63
|
+
}
|
64
|
+
}
|
65
|
+
// sort (highest similarity first)
|
66
|
+
allMatches.sort((a, b) => b.similarity - a.similarity);
|
67
|
+
return allMatches.length > 0
|
68
|
+
? allMatches[0].clusterName
|
69
|
+
: null;
|
70
|
+
}
|
71
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./SemanticClassifier.cjs"), exports);
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./SemanticClassifier.js";
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./SemanticClassifier.js";
|
package/index.cjs
CHANGED
@@ -14,6 +14,7 @@ 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("./classifier/index.cjs"), exports);
|
17
18
|
__exportStar(require("./core/index.cjs"), exports);
|
18
19
|
__exportStar(require("./model-function/index.cjs"), exports);
|
19
20
|
__exportStar(require("./model-provider/index.cjs"), exports);
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
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
@@ -32,16 +32,16 @@ export declare class MistralTextEmbeddingModel extends AbstractModel<MistralText
|
|
32
32
|
doEmbedValues(texts: string[], options: FunctionCallOptions): Promise<{
|
33
33
|
response: {
|
34
34
|
object: string;
|
35
|
-
data: {
|
36
|
-
object: string;
|
37
|
-
embedding: number[];
|
38
|
-
index: number;
|
39
|
-
}[];
|
40
35
|
model: string;
|
41
36
|
usage: {
|
42
37
|
prompt_tokens: number;
|
43
38
|
total_tokens: number;
|
44
39
|
};
|
40
|
+
data: {
|
41
|
+
object: string;
|
42
|
+
embedding: number[];
|
43
|
+
index: number;
|
44
|
+
}[];
|
45
45
|
id: string;
|
46
46
|
};
|
47
47
|
embeddings: number[][];
|
@@ -77,29 +77,29 @@ declare const MistralTextEmbeddingResponseSchema: z.ZodObject<{
|
|
77
77
|
}>;
|
78
78
|
}, "strip", z.ZodTypeAny, {
|
79
79
|
object: string;
|
80
|
-
data: {
|
81
|
-
object: string;
|
82
|
-
embedding: number[];
|
83
|
-
index: number;
|
84
|
-
}[];
|
85
80
|
model: string;
|
86
81
|
usage: {
|
87
82
|
prompt_tokens: number;
|
88
83
|
total_tokens: number;
|
89
84
|
};
|
90
|
-
id: string;
|
91
|
-
}, {
|
92
|
-
object: string;
|
93
85
|
data: {
|
94
86
|
object: string;
|
95
87
|
embedding: number[];
|
96
88
|
index: number;
|
97
89
|
}[];
|
90
|
+
id: string;
|
91
|
+
}, {
|
92
|
+
object: string;
|
98
93
|
model: string;
|
99
94
|
usage: {
|
100
95
|
prompt_tokens: number;
|
101
96
|
total_tokens: number;
|
102
97
|
};
|
98
|
+
data: {
|
99
|
+
object: string;
|
100
|
+
embedding: number[];
|
101
|
+
index: number;
|
102
|
+
}[];
|
103
103
|
id: string;
|
104
104
|
}>;
|
105
105
|
export type MistralTextEmbeddingResponse = z.infer<typeof MistralTextEmbeddingResponseSchema>;
|
@@ -40,11 +40,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
|
|
40
40
|
get settingsForEvent(): Partial<OllamaChatModelSettings>;
|
41
41
|
doGenerateTexts(prompt: OllamaChatPrompt, options: FunctionCallOptions): Promise<{
|
42
42
|
response: {
|
43
|
+
model: string;
|
43
44
|
message: {
|
44
45
|
role: string;
|
45
46
|
content: string;
|
46
47
|
};
|
47
|
-
model: string;
|
48
48
|
done: true;
|
49
49
|
created_at: string;
|
50
50
|
total_duration: number;
|
@@ -61,11 +61,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
|
|
61
61
|
}>;
|
62
62
|
restoreGeneratedTexts(rawResponse: unknown): {
|
63
63
|
response: {
|
64
|
+
model: string;
|
64
65
|
message: {
|
65
66
|
role: string;
|
66
67
|
content: string;
|
67
68
|
};
|
68
|
-
model: string;
|
69
69
|
done: true;
|
70
70
|
created_at: string;
|
71
71
|
total_duration: number;
|
@@ -82,11 +82,11 @@ export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettin
|
|
82
82
|
};
|
83
83
|
private processTextGenerationResponse;
|
84
84
|
doStreamText(prompt: OllamaChatPrompt, options: FunctionCallOptions): Promise<AsyncIterable<import("../../index.js").Delta<{
|
85
|
+
model: string;
|
85
86
|
message: {
|
86
87
|
role: string;
|
87
88
|
content: string;
|
88
89
|
};
|
89
|
-
model: string;
|
90
90
|
done: false;
|
91
91
|
created_at: string;
|
92
92
|
} | {
|
@@ -141,11 +141,11 @@ declare const ollamaChatResponseSchema: z.ZodObject<{
|
|
141
141
|
eval_count: z.ZodNumber;
|
142
142
|
eval_duration: z.ZodNumber;
|
143
143
|
}, "strip", z.ZodTypeAny, {
|
144
|
+
model: string;
|
144
145
|
message: {
|
145
146
|
role: string;
|
146
147
|
content: string;
|
147
148
|
};
|
148
|
-
model: string;
|
149
149
|
done: true;
|
150
150
|
created_at: string;
|
151
151
|
total_duration: number;
|
@@ -155,11 +155,11 @@ declare const ollamaChatResponseSchema: z.ZodObject<{
|
|
155
155
|
load_duration?: number | undefined;
|
156
156
|
prompt_eval_duration?: number | undefined;
|
157
157
|
}, {
|
158
|
+
model: string;
|
158
159
|
message: {
|
159
160
|
role: string;
|
160
161
|
content: string;
|
161
162
|
};
|
162
|
-
model: string;
|
163
163
|
done: true;
|
164
164
|
created_at: string;
|
165
165
|
total_duration: number;
|
@@ -185,19 +185,19 @@ declare const ollamaChatStreamChunkSchema: z.ZodDiscriminatedUnion<"done", [z.Zo
|
|
185
185
|
content: string;
|
186
186
|
}>;
|
187
187
|
}, "strip", z.ZodTypeAny, {
|
188
|
+
model: string;
|
188
189
|
message: {
|
189
190
|
role: string;
|
190
191
|
content: string;
|
191
192
|
};
|
192
|
-
model: string;
|
193
193
|
done: false;
|
194
194
|
created_at: string;
|
195
195
|
}, {
|
196
|
+
model: string;
|
196
197
|
message: {
|
197
198
|
role: string;
|
198
199
|
content: string;
|
199
200
|
};
|
200
|
-
model: string;
|
201
201
|
done: false;
|
202
202
|
created_at: string;
|
203
203
|
}>, z.ZodObject<{
|
@@ -247,11 +247,11 @@ export declare const OllamaChatResponseFormat: {
|
|
247
247
|
requestBodyValues: unknown;
|
248
248
|
response: Response;
|
249
249
|
}) => Promise<{
|
250
|
+
model: string;
|
250
251
|
message: {
|
251
252
|
role: string;
|
252
253
|
content: string;
|
253
254
|
};
|
254
|
-
model: string;
|
255
255
|
done: true;
|
256
256
|
created_at: string;
|
257
257
|
total_duration: number;
|
@@ -271,11 +271,11 @@ export declare const OllamaChatResponseFormat: {
|
|
271
271
|
handler: ({ response }: {
|
272
272
|
response: Response;
|
273
273
|
}) => Promise<AsyncIterable<import("../../index.js").Delta<{
|
274
|
+
model: string;
|
274
275
|
message: {
|
275
276
|
role: string;
|
276
277
|
content: string;
|
277
278
|
};
|
278
|
-
model: string;
|
279
279
|
done: false;
|
280
280
|
created_at: string;
|
281
281
|
} | {
|
@@ -52,16 +52,16 @@ export declare class OpenAITextEmbeddingModel extends AbstractModel<OpenAITextEm
|
|
52
52
|
doEmbedValues(texts: string[], callOptions: FunctionCallOptions): Promise<{
|
53
53
|
response: {
|
54
54
|
object: "list";
|
55
|
-
data: {
|
56
|
-
object: "embedding";
|
57
|
-
embedding: number[];
|
58
|
-
index: number;
|
59
|
-
}[];
|
60
55
|
model: string;
|
61
56
|
usage: {
|
62
57
|
prompt_tokens: number;
|
63
58
|
total_tokens: number;
|
64
59
|
};
|
60
|
+
data: {
|
61
|
+
object: "embedding";
|
62
|
+
embedding: number[];
|
63
|
+
index: number;
|
64
|
+
}[];
|
65
65
|
};
|
66
66
|
embeddings: number[][];
|
67
67
|
}>;
|
@@ -95,28 +95,28 @@ declare const openAITextEmbeddingResponseSchema: z.ZodObject<{
|
|
95
95
|
}>;
|
96
96
|
}, "strip", z.ZodTypeAny, {
|
97
97
|
object: "list";
|
98
|
-
data: {
|
99
|
-
object: "embedding";
|
100
|
-
embedding: number[];
|
101
|
-
index: number;
|
102
|
-
}[];
|
103
98
|
model: string;
|
104
99
|
usage: {
|
105
100
|
prompt_tokens: number;
|
106
101
|
total_tokens: number;
|
107
102
|
};
|
108
|
-
}, {
|
109
|
-
object: "list";
|
110
103
|
data: {
|
111
104
|
object: "embedding";
|
112
105
|
embedding: number[];
|
113
106
|
index: number;
|
114
107
|
}[];
|
108
|
+
}, {
|
109
|
+
object: "list";
|
115
110
|
model: string;
|
116
111
|
usage: {
|
117
112
|
prompt_tokens: number;
|
118
113
|
total_tokens: number;
|
119
114
|
};
|
115
|
+
data: {
|
116
|
+
object: "embedding";
|
117
|
+
embedding: number[];
|
118
|
+
index: number;
|
119
|
+
}[];
|
120
120
|
}>;
|
121
121
|
export type OpenAITextEmbeddingResponse = z.infer<typeof openAITextEmbeddingResponseSchema>;
|
122
122
|
export {};
|
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
|
-
});
|