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

Commit 607fb4b

Browse files
Support arrays input for OpenAI embeddings (#6)
1 parent 877d822 commit 607fb4b

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22

33
## UNRELEASED
44

5+
- Update OpenAI Embeddings model to support all allowed types of input
6+
7+
## 2024-06-28 - Version 0.1.6
8+
9+
- Interface changes and fixes
10+
11+
## 2024-06-28 - Version 0.1.5
12+
13+
- Interface changes and fixes
14+
15+
## 2024-06-27 - Version 0.1.2
16+
517
- Initial Release

src/models/openai/embeddings.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,38 @@ import { Model } from "../..";
33
// Reference: https://platform.openai.com/docs/api-reference/embeddings
44

55
export class EmbeddingsModel extends Model<EmbeddingsInput, EmbeddingsOutput> {
6-
createInput(text: string): EmbeddingsInput {
6+
createInput<T>(content: T): EmbeddingsInput {
77
const model = this.info.fullName;
8-
return <EmbeddingsInput>{ model, input: text };
8+
9+
switch (idof<T>()) {
10+
case idof<string>():
11+
case idof<string[]>():
12+
case idof<i64[]>():
13+
case idof<i32[]>():
14+
case idof<i16[]>():
15+
case idof<i8[]>():
16+
case idof<u64[]>():
17+
case idof<u32[]>():
18+
case idof<u16[]>():
19+
case idof<u8[]>():
20+
case idof<i64[][]>():
21+
case idof<i32[][]>():
22+
case idof<i16[][]>():
23+
case idof<i8[][]>():
24+
case idof<u64[][]>():
25+
case idof<u32[][]>():
26+
case idof<u16[][]>():
27+
case idof<u8[][]>():
28+
return <TypedEmbeddingsInput<T>>{ model, input: content };
29+
}
30+
31+
throw new Error("Unsupported input content type.");
932
}
1033
}
1134

1235

1336
@json
1437
class EmbeddingsInput {
15-
input!: string; // todo: support other types of input (arrays, etc.)
1638
model!: string;
1739

1840

@@ -29,6 +51,12 @@ class EmbeddingsInput {
2951
}
3052

3153

54+
@json
55+
class TypedEmbeddingsInput<T> extends EmbeddingsInput {
56+
input!: T;
57+
}
58+
59+
3260
@json
3361
class EmbeddingsOutput {
3462
object!: string;

0 commit comments

Comments
 (0)