Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 00d3fd5

Browse files
Add experimental classification and embeddings models (#9)
* Add experimental classification and embeddings models * Update CHANGELOG.md
1 parent 5410beb commit 00d3fd5

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Update OpenAI Embeddings model to support all allowed types of input [#6](https://github.com/hypermodeAI/models-as/pull/6)
66
- More updates for OpenAI Embeddings model [#7](https://github.com/hypermodeAI/models-as/pull/7)
77
- Add documentation comments for OpenAI Chat model [#8](https://github.com/hypermodeAI/models-as/pull/8)
8+
- Add experimental classification and embeddings models [#9](https://github.com/hypermodeAI/models-as/pull/9)
89

910
## 2024-06-28 - Version 0.1.6
1011

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Model } from "../..";
2+
3+
/**
4+
* A model that returns classification results for a list of text strings.
5+
*
6+
* @remarks
7+
* This model interface is experimental and may change in the future.
8+
* It is primarily intended for use with with classification models hosted on Hypermode.
9+
*/
10+
export class ClassificationModel extends Model<
11+
ClassificationInput,
12+
ClassificationOutput
13+
> {
14+
/**
15+
* Creates an input object for the classification model.
16+
*
17+
* @param instances - A list of one or more text strings to classify.
18+
* @returns An input object that can be passed to the `invoke` method.
19+
*/
20+
createInput(instances: string[]): ClassificationInput {
21+
return <ClassificationInput>{ instances };
22+
}
23+
}
24+
25+
/**
26+
* An input object for the classification model.
27+
*/
28+
@json
29+
class ClassificationInput {
30+
/**
31+
* A list of one or more text strings of text to classify.
32+
*/
33+
instances!: string[];
34+
}
35+
36+
/**
37+
* An output object for the classification model.
38+
*/
39+
@json
40+
class ClassificationOutput {
41+
/**
42+
* A list of prediction results that correspond to each input text string.
43+
*/
44+
predictions!: ClassifierResult[];
45+
}
46+
47+
/**
48+
* A classification result for a single text string.
49+
*/
50+
@json
51+
export class ClassifierResult {
52+
/**
53+
* The classification label with the highest confidence.
54+
*/
55+
label!: string;
56+
57+
/**
58+
* The confidence score for the classification label.
59+
*/
60+
confidence!: f32;
61+
62+
/**
63+
* The list of all classification labels with their corresponding probabilities.
64+
*/
65+
probabilities!: ClassifierLabel[];
66+
}
67+
68+
/**
69+
* A classification label with its corresponding probability.
70+
*/
71+
@json
72+
class ClassifierLabel {
73+
/**
74+
* The classification label.
75+
*/
76+
label!: string;
77+
78+
/**
79+
* The probability value.
80+
*/
81+
probability!: f32;
82+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Model } from "../..";
2+
3+
/**
4+
* A model that returns embeddings for a list of text strings.
5+
*
6+
* @remarks
7+
* This model interface is experimental and may change in the future.
8+
* It is primarily intended for use with with embedding models hosted on Hypermode.
9+
*/
10+
export class EmbeddingsModel extends Model<EmbeddingsInput, EmbeddingsOutput> {
11+
/**
12+
* Creates an input object for the embeddings model.
13+
*
14+
* @param instances - A list of one or more text strings to create vector embeddings for.
15+
* @returns An input object that can be passed to the `invoke` method.
16+
*/
17+
createInput(instances: string[]): EmbeddingsInput {
18+
return <EmbeddingsInput>{ instances };
19+
}
20+
}
21+
22+
/**
23+
* An input object for the embeddings model.
24+
*/
25+
@json
26+
class EmbeddingsInput {
27+
/**
28+
* A list of one or more text strings to create vector embeddings for.
29+
*/
30+
instances!: string[];
31+
}
32+
33+
/**
34+
* An output object for the embeddings model.
35+
*/
36+
@json
37+
class EmbeddingsOutput {
38+
/**
39+
* A list of vector embeddings that correspond to each input text string.
40+
*/
41+
predictions!: f32[][];
42+
}

0 commit comments

Comments
 (0)