You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a no-nonsense async Scala client for OpenAI API supporting all the available endpoints and params (as defined [here](https://beta.openai.com/docs/api-reference)), provided in a single, convenient service called [OpenAIService](./openai-core/src/main/scala/io/cequence/openaiscala/service/OpenAIService.scala). The supported calls are:
3
+
This is a no-nonsense async Scala client for OpenAI API supporting all the available endpoints and params **including streaming**(as defined [here](https://beta.openai.com/docs/api-reference)), provided in a single, convenient service called [OpenAIService](./openai-core/src/main/scala/io/cequence/openaiscala/service/OpenAIService.scala). The supported calls are:
4
4
5
5
***Models**: [listModels](https://beta.openai.com/docs/api-reference/models/list), and [retrieveModel](https://beta.openai.com/docs/api-reference/models/retrieve)
Then you can obtain a service in one of the following ways:
62
+
Then you can obtain a service in one of the following ways.
61
63
62
64
- Default config (expects env. variable(s) to be set as defined in `Config` section)
63
65
```scala
@@ -79,6 +81,8 @@ Then you can obtain a service in one of the following ways:
79
81
)
80
82
```
81
83
84
+
**✔️ Important**: If you want to use streaming use `OpenAIServiceStreamedFactory` from `openai-scala-client-stream` lib instead of `OpenAIServiceFactory` (in the three examples above). Two additional functions - `createCompletionStreamed` and `listFineTuneEventsStreamed` provided by [OpenAIServiceStreamedExtra](./openai-client-stream/src/main/scala/io/cequence/openaiscala/service/OpenAIServiceStreamedExtra.scala) will be then available.
85
+
82
86
- Via dependency injection (requires `openai-scala-guice` lib)
83
87
84
88
```scala
@@ -146,6 +150,25 @@ Examples:
146
150
)
147
151
```
148
152
153
+
- Create completion with streaming and a custom setting
154
+
155
+
```scala
156
+
valsource= service.createCompletionStreamed(
157
+
prompt ="Write me a Shakespeare poem about two cats playing baseball in Russia using at least 2 pages",
158
+
settings =CreateCompletionSettings(
159
+
model =ModelId.text_davinci_003,
160
+
max_tokens =Some(1500),
161
+
temperature =Some(0.9),
162
+
presence_penalty =Some(0.2),
163
+
frequency_penalty =Some(0.2)
164
+
)
165
+
)
166
+
167
+
source.map(completion =>
168
+
println(completion.choices.head.text)
169
+
).runWith(Sink.ignore)
170
+
```
171
+
(For this to work you need to use `OpenAIServiceStreamedFactory` from `openai-scala-client-stream` lib)
This module provided the actual meat, i.e. WS client implementation ([OpenAIServiceImpl and OpenAIServiceFactory](./src/main/scala/io/cequence/openaiscala/service/OpenAIServiceImpl.scala)).
3
+
This module provides the actual meat, i.e. WS client implementation ([OpenAIServiceImpl and OpenAIServiceFactory](./src/main/scala/io/cequence/openaiscala/service/OpenAIServiceImpl.scala)).
4
4
Note that the full project documentation can be found [here](../README.md).
5
5
6
6
## Installation 🚀
@@ -10,7 +10,7 @@ The currently supported Scala versions are **2.12, 2.13**, and **3**.
10
10
To pull the library you have to add the following dependency to your *build.sbt*
11
11
12
12
```
13
-
"io.cequence" %% "openai-scala-client" % "0.1.1"
13
+
"io.cequence" %% "openai-scala-client" % "0.2.0"
14
14
```
15
15
16
16
or to *pom.xml* (if you use maven)
@@ -19,6 +19,6 @@ or to *pom.xml* (if you use maven)
This is the core module, which contains mostly domain classes and the [OpenAIService](./src/main/scala/io/cequence/openaiscala/service/OpenAIService.scala) definition.
4
4
Note that the full project documentation can be found [here](../README.md).
@@ -10,7 +10,7 @@ The currently supported Scala versions are **2.12, 2.13**, and **3**.
10
10
To pull the library you have to add the following dependency to your *build.sbt*
11
11
12
12
```
13
-
"io.cequence" %% "openai-scala-core" % "0.1.1"
13
+
"io.cequence" %% "openai-scala-core" % "0.2.0"
14
14
```
15
15
16
16
or to *pom.xml* (if you use maven)
@@ -19,6 +19,6 @@ or to *pom.xml* (if you use maven)
0 commit comments