Skip to content

Commit 57f7ea3

Browse files
authored
[Release] Released for 1.0.0 (#7)
2 parents dc93097 + f384540 commit 57f7ea3

21 files changed

+684
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
- Concise and easy to understand, code specification requirements, can be used as enterprise code specification.
2727
- The steps to use are very simple, and one line of code realizes the required functions.
2828
- Support multiple proxy platforms, perfectly adapt to various APIs.
29+
- Dynamically expand Max Tokens according to the model
30+
- Rich pre-data verification to avoid direct contact with API
2931

3032
## Star History
3133

bin/publish-mavenCentral.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GPG_TTY=$(tty)
2+
export GPG_TTY
3+
4+
./mvnw clean install package deploy -DskipTests

bin/publish-newVersion.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
VERSION=$1
3+
HOME=$(pwd)
4+
5+
job_before_echo_basic() {
6+
printf "\n\tJob before echo basic \n"
7+
printf "============================================\n"
8+
printf "Released new version\n"
9+
printf "============================================\n\n"
10+
}
11+
12+
job_before_checked() {
13+
printf "\n\tJob before check parameter \n"
14+
printf "============================================\n"
15+
if test -z "$VERSION"; then
16+
printf "Please input version \n"
17+
exit 1
18+
else
19+
printf "Version checked successful | %s\n" "$VERSION"
20+
fi
21+
printf "============================================\n\n"
22+
}
23+
24+
job_runner_apply() {
25+
printf "\n\tJob runner apply \n"
26+
printf "============================================\n"
27+
printf "Apply new version for server ...\n"
28+
MAVEN_OPTS=-Dorg.slf4j.simpleLogger.defaultLogLevel=error ./mvnw versions:set -DnewVersion="$VERSION"
29+
if [ $? -ne 0 ]; then
30+
printf "\nApply new version for server failed\n\n"
31+
exit 1
32+
else
33+
printf "\nApply new version for server successful\n\n"
34+
fi
35+
printf "============================================\n\n"
36+
}
37+
38+
job_before_echo_basic
39+
job_before_checked
40+
job_runner_apply

docs/docs/index.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ hide:
3434
</a>
3535
<p/>
3636
<p/>
37-
<a href="/reference/get_started.html" title="Get Started" class="md-button">
38-
Get Started
39-
</a>
4037
<a href="https://github.com/devlive-community/openai-java-sdk" target="_blank" title="Join us on GitHub" class="md-button md-button--primary">
4138
Join us on GitHub
4239
</a>
@@ -71,4 +68,16 @@ hide:
7168

7269
Support multiple proxy platforms, perfectly adapt to various APIs.
7370

71+
- __Dynamically Configure__
72+
73+
---
74+
75+
Dynamically expand Max Tokens according to the model.
76+
77+
- __Isolate remote API__
78+
79+
---
80+
81+
Rich pre-data verification to avoid direct contact with API.
82+
7483
</div>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: Chat Completions
3+
---
4+
5+
!!! Note
6+
7+
Please build the client before calling, the build code is as follows:
8+
9+
```java
10+
OpenAiClient client = OpenAiClient.builder()
11+
.apiHost("https://api.openai.com")
12+
.apiKey(System.getProperty("openai.token"))
13+
.build();
14+
```
15+
16+
`System.getProperty("openai.token")` is the key to access the API authorization.
17+
18+
### Create chat completion
19+
20+
---
21+
22+
Creates a model response for the given chat conversation.
23+
24+
```java
25+
List<CompletionMessageEntity> messages = Lists.newArrayList();
26+
messages.add(CompletionMessageEntity.builder()
27+
.content("Hello, my name is openai-java-sdk")
28+
.build());
29+
30+
CompletionChatEntity configure = CompletionChatEntity.builder()
31+
.messages(messages)
32+
.build();
33+
34+
client.createChatCompletion(configure)
35+
.getChoices()
36+
.forEach(choice -> messages.add(choice.getMessage()));
37+
38+
messages.add(CompletionMessageEntity.builder()
39+
.content("What is my name?")
40+
.build());
41+
42+
client.createChatCompletion(configure)
43+
.getChoices()
44+
.stream()
45+
.map(v -> v.getMessage().getContent())
46+
.collect(Collectors.toList())
47+
.toString()
48+
.contains("openai-java-sdk");
49+
```
50+
51+
Body:
52+
53+
| Name | Type | Required |
54+
|:------------------:|:--------------:|----------|
55+
| `model` | `String` | Yes |
56+
| `prompt` | `String` | Yes |
57+
| `temperature` | `Number` | No |
58+
| `maxTokens` | `Number` | No |
59+
| `topP` | `Number` | No |
60+
| `bestOf` | `Number` | No |
61+
| `frequencyPenalty` | `Number` | No |
62+
| `presencePenalty` | `Number` | No |
63+
| `stop` | `List<String>` | No |
64+
65+
Returns:
66+
67+
```json
68+
{
69+
"id": "chatcmpl-123",
70+
"object": "chat.completion",
71+
"created": 1677652288,
72+
"choices": [
73+
{
74+
"index": 0,
75+
"message": {
76+
"role": "assistant",
77+
"content": "\n\nHello there, how may I assist you today?"
78+
},
79+
"finish_reason": "stop"
80+
}
81+
],
82+
"usage": {
83+
"prompt_tokens": 9,
84+
"completion_tokens": 12,
85+
"total_tokens": 21
86+
}
87+
}
88+
```

docs/docs/released.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Release Notes
3+
4+
hide:
5+
- navigation
6+
---
7+
8+
### 1.0.0
9+
10+
---
11+
12+
- Support models
13+
- List models
14+
- Retrieve model
15+
- Create completion
16+
- Create chat completion

docs/mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ nav:
4646
- Reference:
4747
- reference/models.md
4848
- reference/completions.md
49+
- reference/completions_chat.md
50+
- released.md
4951
- powered_by.md

pom.xml

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
<groupId>org.devlive.sdk</groupId>
77
<artifactId>openai-java-sdk</artifactId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.0</version>
99

1010
<name>openai-java-sdk</name>
1111
<description>
1212
Provides Java developers with a convenient, easy-to-use SDK to interact with OpenAI's apis.
1313
</description>
14-
1514
<url>https://openai-java-sdk.devlive.org</url>
1615

1716
<scm>
18-
<connection>scm:git:git://github.com/devlive-community/openai-java-sdk</connection>
1917
<url>https://github.com/devlive-community/openai-java-sdk</url>
18+
<connection>scm:git:git://github.com/devlive-community/openai-java-sdk</connection>
19+
<tag>openai,jdk,java,chatgpt</tag>
2020
</scm>
2121

2222
<organization>
@@ -56,8 +56,13 @@
5656
<okhttp.version>4.9.3</okhttp.version>
5757
<guava.version>31.1-jre</guava.version>
5858
<retrofit2.version>2.9.0</retrofit2.version>
59+
<findbugs.version>3.0.1</findbugs.version>
5960
<plugin.maven.checkstyle.version>3.0.0</plugin.maven.checkstyle.version>
6061
<plugin.maven.findbugs.version>3.0.5</plugin.maven.findbugs.version>
62+
<plugin.maven.source.version>2.2.1</plugin.maven.source.version>
63+
<plugin.maven.javadoc.version>3.5.0</plugin.maven.javadoc.version>
64+
<plugin.maven.gpg.version>1.6</plugin.maven.gpg.version>
65+
<plugin.maven.nexus.version>1.6</plugin.maven.nexus.version>
6166
</properties>
6267

6368
<dependencies>
@@ -118,6 +123,11 @@
118123
<artifactId>converter-jackson</artifactId>
119124
<version>${retrofit2.version}</version>
120125
</dependency>
126+
<dependency>
127+
<groupId>com.google.code.findbugs</groupId>
128+
<artifactId>findbugs-annotations</artifactId>
129+
<version>${findbugs.version}</version>
130+
</dependency>
121131
</dependencies>
122132

123133
<build>
@@ -165,6 +175,78 @@
165175
</execution>
166176
</executions>
167177
</plugin>
178+
<plugin>
179+
<groupId>org.apache.maven.plugins</groupId>
180+
<artifactId>maven-source-plugin</artifactId>
181+
<version>${plugin.maven.source.version}</version>
182+
<executions>
183+
<execution>
184+
<phase>package</phase>
185+
<goals>
186+
<goal>jar-no-fork</goal>
187+
</goals>
188+
</execution>
189+
</executions>
190+
</plugin>
191+
<plugin>
192+
<groupId>org.apache.maven.plugins</groupId>
193+
<artifactId>maven-javadoc-plugin</artifactId>
194+
<version>${plugin.maven.javadoc.version}</version>
195+
<executions>
196+
<execution>
197+
<phase>package</phase>
198+
<goals>
199+
<goal>jar</goal>
200+
</goals>
201+
</execution>
202+
</executions>
203+
<configuration>
204+
<tags>
205+
<tag>
206+
<name>Description</name>
207+
<placement>test</placement>
208+
<head>description</head>
209+
</tag>
210+
</tags>
211+
<additionalOptions>-Xdoclint:none</additionalOptions>
212+
<failOnError>false</failOnError>
213+
</configuration>
214+
</plugin>
215+
<plugin>
216+
<groupId>org.apache.maven.plugins</groupId>
217+
<artifactId>maven-gpg-plugin</artifactId>
218+
<version>${plugin.maven.gpg.version}</version>
219+
<executions>
220+
<execution>
221+
<phase>verify</phase>
222+
<goals>
223+
<goal>sign</goal>
224+
</goals>
225+
</execution>
226+
</executions>
227+
</plugin>
228+
<plugin>
229+
<groupId>org.sonatype.plugins</groupId>
230+
<artifactId>nexus-staging-maven-plugin</artifactId>
231+
<version>${plugin.maven.nexus.version}</version>
232+
<extensions>true</extensions>
233+
<configuration>
234+
<serverId>ossrh</serverId>
235+
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
236+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
237+
</configuration>
238+
</plugin>
168239
</plugins>
169240
</build>
241+
242+
<distributionManagement>
243+
<snapshotRepository>
244+
<id>ossrh</id>
245+
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
246+
</snapshotRepository>
247+
<repository>
248+
<id>ossrh</id>
249+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
250+
</repository>
251+
</distributionManagement>
170252
</project>

src/main/java/org/devlive/sdk/openai/DefaultApi.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.devlive.sdk.openai;
22

33
import io.reactivex.Single;
4+
import org.devlive.sdk.openai.entity.CompletionChatEntity;
45
import org.devlive.sdk.openai.entity.CompletionEntity;
56
import org.devlive.sdk.openai.entity.ModelEntity;
7+
import org.devlive.sdk.openai.response.CompleteChatResponse;
68
import org.devlive.sdk.openai.response.CompleteResponse;
79
import org.devlive.sdk.openai.response.ModelResponse;
810
import retrofit2.http.Body;
@@ -31,4 +33,10 @@ public interface DefaultApi
3133
*/
3234
@POST(value = "v1/completions")
3335
Single<CompleteResponse> fetchCompletions(@Body CompletionEntity configure);
36+
37+
/**
38+
* Creates a model response for the given chat conversation.
39+
*/
40+
@POST(value = "v1/chat/completions")
41+
Single<CompleteChatResponse> fetchChatCompletions(@Body CompletionChatEntity configure);
3442
}

src/main/java/org/devlive/sdk/openai/DefaultClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.devlive.sdk.openai;
22

3+
import org.devlive.sdk.openai.entity.CompletionChatEntity;
34
import org.devlive.sdk.openai.entity.CompletionEntity;
45
import org.devlive.sdk.openai.entity.ModelEntity;
6+
import org.devlive.sdk.openai.response.CompleteChatResponse;
57
import org.devlive.sdk.openai.response.CompleteResponse;
68
import org.devlive.sdk.openai.response.ModelResponse;
79

@@ -26,4 +28,10 @@ CompleteResponse createCompletion(CompletionEntity configure)
2628
return this.api.fetchCompletions(configure)
2729
.blockingGet();
2830
}
31+
32+
CompleteChatResponse createChatCompletion(CompletionChatEntity configure)
33+
{
34+
return this.api.fetchChatCompletions(configure)
35+
.blockingGet();
36+
}
2937
}

0 commit comments

Comments
 (0)