1
- # OpenAI ChatModel using Official Java SDK
1
+ # OpenAI ChatModel and Embedding using Official Java SDK
2
2
3
3
[ ![ 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 )
4
4
![ Maven Central Version] ( https://img.shields.io/maven-central/v/com.javaaidev/openai-chatmodel-standalone )
5
5
6
- Spring AI ` ChatModel ` implementation for OpenAI using
6
+ Spring AI ` ChatModel ` and ` EmbeddingModel ` implementations for OpenAI using
7
7
the [ official SDK] ( https://github.com/openai/openai-java ) .
8
8
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.
17
10
18
11
Add Maven dependency.
19
12
@@ -26,6 +19,15 @@ Add Maven dependency.
26
19
</dependency >
27
20
```
28
21
22
+ ## ChatModel
23
+
24
+ Supported features:
25
+
26
+ - Chat completions
27
+ - Function calling
28
+
29
+ ### Use ChatModel
30
+
29
31
To use this ` ChatModel ` ,
30
32
31
33
1 . Create an ` OpenAIClient ` ,
@@ -46,3 +48,25 @@ val chatClient =
46
48
val response = chatClient.prompt().user(" tell me a joke" )
47
49
.call().content()
48
50
```
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