Skip to content

Commit a9e9ef3

Browse files
authored
Merge pull request #3 from CJCrafter/gradle
Gradle
2 parents dbd5c28 + eed126d commit a9e9ef3

File tree

10 files changed

+898
-388
lines changed

10 files changed

+898
-388
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# These are explicitly windows files and should use crlf
5+
*.bat text eol=crlf
6+

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Eclipse
2+
.classpath
3+
.project
4+
.settings/
5+
6+
# Intellij
7+
.idea/
8+
*.iml
9+
*.iws
10+
11+
# Mac
12+
.DS_Store
13+
14+
# VSCode
15+
.vscode/
16+
17+
# Netbrans
18+
nbproject/
19+
nbactions.xml
20+
21+
# Gradle
22+
.gradle/
23+
build/
24+
!gradle/wrapper/gradle-wrapper.jar
25+
gradle.properties
26+
27+
# Maven
28+
log/
29+
target/

README.md

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@ works by wrapping HTTPS requests with java variables, making the generated resul
44

55
Feel free to use, modify, and distribute this code as needed.
66

7+
# Installation
8+
For Gradle projects, add this to your `build.gradle` file in the dependencies block:
9+
```groovy
10+
dependencies {
11+
implementation 'com.cjcrafter:openai:1.0.0'
12+
}
13+
```
14+
Or, if you are using Kotlin DSL (`build.gradle.kts`), add this to your dependencies block:
15+
```kotlin
16+
dependencies {
17+
implementation("com.cjcrafter:openai:1.0.0")
18+
}
19+
```
20+
For Maven projects, add this to your `pom.xml` file in the `<dependencies>` block:
21+
```xml
22+
<dependency>
23+
<groupId>com.cjcrafter</groupId>
24+
<artifactId>openai</artifactId>
25+
<version>1.0.0</version>
26+
</dependency>
27+
```
28+
See the [maven repository](https://central.sonatype.com/artifact/com.cjcrafter/openai/1.0.0) for gradle/ant/etc.
29+
30+
731
# Working Example
832
```java
933
import java.io.IOException;
@@ -41,43 +65,6 @@ public class Main {
4165
}
4266
```
4367

44-
# Installation
45-
1. Add [okhttp](https://square.github.io/okhttp/) and [gson](https://github.com/google/gson) as dependencies (see below)
46-
2. Drag and drop the [`ChatBot.java`](https://github.com/CJCrafter/ChatGPT-Java-API/blob/master/ChatBot.java) file into your project
47-
48-
Maven:
49-
```xml
50-
<dependencies>
51-
<dependency>
52-
<groupId>com.squareup.okhttp3</groupId>
53-
<artifactId>okhttp</artifactId>
54-
<version>4.9.2</version>
55-
</dependency>
56-
<dependency>
57-
<groupId>com.google.code.gson</groupId>
58-
<artifactId>gson</artifactId>
59-
<version>2.8.9</version>
60-
</dependency>
61-
</dependencies>
62-
```
63-
64-
Gradle KTS:
65-
```gradle
66-
repositories {
67-
mavenCentral()
68-
}
69-
70-
dependencies {
71-
implementation("com.squareup.okhttp3:okhttp:4.9.2")
72-
implementation("com.google.code.gson:gson:2.8.9")
73-
}
74-
```
75-
76-
# More
77-
1. I also wrote a [Kotlin Version]() of the API.
78-
2. Need inspiration for prompts? Check out [awesome prompts](https://github.com/f/awesome-chatgpt-prompts).
79-
3. Looking for the official API? OpenAI only officially supports [python](https://github.com/openai/openai-python).
80-
8168
# Support
8269
If I have saved you time, please consider [sponsoring me](https://github.com/sponsors/CJCrafter).
8370
If you cannot financially support me, consider leaving a star on the repository and sharing it. Thanks!

build.gradle.kts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
2+
3+
group = "com.cjcrafter"
4+
version = "1.0.0"
5+
6+
plugins {
7+
`java-library`
8+
`maven-publish`
9+
signing
10+
id("com.github.breadmoirai.github-release") version "2.4.1"
11+
}
12+
13+
repositories {
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
implementation("com.squareup.okhttp3:okhttp:4.9.2")
19+
implementation("com.google.code.gson:gson:2.10.1")
20+
}
21+
22+
java {
23+
toolchain {
24+
languageVersion.set(JavaLanguageVersion.of(17))
25+
}
26+
}
27+
28+
tasks {
29+
compileJava {
30+
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
31+
options.release.set(8)
32+
}
33+
javadoc {
34+
options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything
35+
}
36+
processResources {
37+
filteringCharset = Charsets.UTF_8.name() // We want UTF-8 for everything
38+
}
39+
}
40+
41+
// Create javadocJar and sourcesJar tasks
42+
val javadocJar by tasks.registering(Jar::class) {
43+
archiveClassifier.set("javadoc")
44+
from(tasks.named("javadoc"))
45+
}
46+
47+
val sourcesJar by tasks.registering(Jar::class) {
48+
archiveClassifier.set("sources")
49+
from(sourceSets.main.get().allSource)
50+
}
51+
52+
// Signing artifacts
53+
signing {
54+
isRequired = true
55+
//useGpgCmd()
56+
57+
useInMemoryPgpKeys(
58+
findProperty("SIGNING_KEY_ID").toString(),
59+
findProperty("SIGNING_PRIVATE_KEY").toString(),
60+
findProperty("SIGNING_PASSWORD").toString()
61+
)
62+
//sign(configurations["archives"])
63+
sign(publishing.publications)
64+
}
65+
66+
publishing {
67+
publications {
68+
create<MavenPublication>("mavenJava") {
69+
from(components["java"])
70+
71+
artifact(javadocJar)
72+
artifact(sourcesJar)
73+
74+
pom {
75+
name.set("OpenAI Java API")
76+
description.set("Access OpenAI's API without the raw JSON/HTTPS requests")
77+
url.set("https://github.com/CJCrafter/ChatGPT-Java-API")
78+
79+
groupId = "com.cjcrafter"
80+
artifactId = "openai"
81+
82+
licenses {
83+
license {
84+
name.set("The MIT License")
85+
url.set("https://opensource.org/licenses/MIT")
86+
}
87+
}
88+
developers {
89+
developer {
90+
id.set("CJCrafter")
91+
name.set("Collin Barber")
92+
email.set("[email protected]")
93+
}
94+
}
95+
scm {
96+
connection.set("scm:git:https://github.com/CJCrafter/ChatGPT-Java-API.git")
97+
developerConnection.set("scm:git:ssh://github.com/CJCrafter/ChatGPT-Java-API.git")
98+
url.set("https://github.com/CJCrafter/ChatGPT-Java-API")
99+
}
100+
}
101+
}
102+
}
103+
104+
repositories {
105+
maven {
106+
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2")
107+
credentials {
108+
username = findProperty("OSSRH_USERNAME").toString()
109+
password = findProperty("OSSRH_PASSWORD").toString()
110+
}
111+
}
112+
}
113+
}
114+
115+
tasks.register<GithubReleaseTask>("createGithubRelease").configure {
116+
// https://github.com/BreadMoirai/github-release-gradle-plugin
117+
owner.set("CJCrafter")
118+
repo.set("ChatGPT-Java-API")
119+
authorization.set("Token ${findProperty("GITHUB_TOKEN").toString()}")
120+
tagName.set("$version")
121+
targetCommitish.set("master")
122+
releaseName.set("$version")
123+
draft.set(false)
124+
prerelease.set(false)
125+
generateReleaseNotes.set(true)
126+
body.set("""
127+
For Gradle projects, add this to your `build.gradle` file in the dependencies block:
128+
```groovy
129+
dependencies {
130+
implementation 'com.cjcrafter:openai:$version'
131+
}
132+
```
133+
Or, if you are using Kotlin DSL (`build.gradle.kts`), add this to your dependencies block:
134+
```kotlin
135+
dependencies {
136+
implementation("com.cjcrafter:openai:$version")
137+
}
138+
```
139+
For Maven projects, add this to your `pom.xml` file in the `<dependencies>` block:
140+
```xml
141+
<dependency>
142+
<groupId>com.cjcrafter</groupId>
143+
<artifactId>openai</artifactId>
144+
<version>$version</version>
145+
</dependency>
146+
```
147+
See the [maven repository](https://central.sonatype.com/artifact/com.cjcrafter/openai/$version) for gradle/ant/etc.
148+
""".trimIndent())
149+
overwrite.set(false)
150+
allowUploadToExisting.set(false)
151+
apiEndpoint.set("https://api.github.com")
152+
153+
setReleaseAssets(/* empty */)
154+
155+
// If set to true, you can debug that this would do
156+
dryRun.set(false)
157+
}

gradle/wrapper/gradle-wrapper.jar

58.4 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)