Skip to content

Commit e2b93c4

Browse files
committed
add embedding model
1 parent d662dc6 commit e2b93c4

File tree

7 files changed

+842
-627
lines changed

7 files changed

+842
-627
lines changed

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
# OpenAI ChatModel using Official Java SDK
1+
# OpenAI ChatModel and Embedding using Official Java SDK
22

33
[![build](https://github.com/JavaAIDev/openai-chatmodel-standalone/actions/workflows/build.yaml/badge.svg)](https://github.com/JavaAIDev/openai-chatmodel-standalone/actions/workflows/build.yaml)
44
![Maven Central Version](https://img.shields.io/maven-central/v/com.javaaidev/openai-chatmodel-standalone)
55

6-
Spring AI `ChatModel` implementation for OpenAI using
6+
Spring AI `ChatModel` and `EmbeddingModel` implementations for OpenAI using
77
the [official SDK](https://github.com/openai/openai-java).
88

9-
The motivation of this `ChatModel` implementation is to use Spring AI with Spring 5.
10-
11-
Supported features:
12-
13-
- Chat completions
14-
- Function calling
15-
16-
## Use ChatModel
9+
The motivation of this `ChatModel` and `EmbeddingModel` implementations is to use Spring AI with Spring 5.
1710

1811
Add Maven dependency.
1912

@@ -26,6 +19,15 @@ Add Maven dependency.
2619
</dependency>
2720
```
2821

22+
## ChatModel
23+
24+
Supported features:
25+
26+
- Chat completions
27+
- Function calling
28+
29+
### Use ChatModel
30+
2931
To use this `ChatModel`,
3032

3133
1. Create an `OpenAIClient`,
@@ -46,3 +48,25 @@ val chatClient =
4648
val response = chatClient.prompt().user("tell me a joke")
4749
.call().content()
4850
```
51+
52+
## EmbeddingModel
53+
54+
To use this `EmbeddingModel`,
55+
56+
1. Create an `OpenAIClient`,
57+
2. Create an `OpenAIEmbeddingModel`
58+
59+
See the code below:
60+
61+
```kotlin
62+
val client = OpenAIOkHttpClient.fromEnv()
63+
val embeddingModel = OpenAIEmbeddingModel(client)
64+
val response = embeddingModel.call(
65+
EmbeddingRequest(
66+
listOf("hello", "world"),
67+
OpenAIEmbeddingOptions.builder()
68+
.model("text-embedding-3-small")
69+
.build()
70+
)
71+
)
72+
```

0 commit comments

Comments
 (0)