Skip to content

Commit 6eb5db2

Browse files
committed
Change the name and move the code to this repository.
1 parent 88951fa commit 6eb5db2

File tree

10 files changed

+1012
-0
lines changed

10 files changed

+1012
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Artyom Nefedov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

pom.xml

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.github.artemnefedov</groupId>
8+
<artifactId>javaai</artifactId>
9+
<version>0.2.3</version>
10+
<packaging>jar</packaging>
11+
12+
<name>JavaAI</name>
13+
<description>Open AI GPT-3 Java SDK</description>
14+
<url>https://github.com/artemnefedov/JavaAI</url>
15+
16+
<issueManagement>
17+
<system>GitHub</system>
18+
<url>https://github.com/artemnefedov/JavaAI/issues</url>
19+
</issueManagement>
20+
21+
<licenses>
22+
<license>
23+
<name>The MIT License</name>
24+
<url>https://github.com/artemnefedov/JavaAI/blob/main/LICENSE</url>
25+
<distribution>repo</distribution>
26+
</license>
27+
</licenses>
28+
29+
<developers>
30+
<developer>
31+
<name>Artyom Nefedov</name>
32+
<organizationUrl>https://github.com/artemnefedov</organizationUrl>
33+
</developer>
34+
</developers>
35+
36+
<scm>
37+
<connection>scm:git:git://github.com/artemnefedov/JavaAI.git</connection>
38+
<developerConnection>scm:git:ssh://github.com:artemnefedov/JavaAI.git</developerConnection>
39+
<url>https://github.com/artemnefedov/JavaAI/tree/main</url>
40+
</scm>
41+
42+
<properties>
43+
<maven.compiler.source>17</maven.compiler.source>
44+
<maven.compiler.target>17</maven.compiler.target>
45+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
46+
</properties>
47+
48+
49+
<dependencies>
50+
<dependency>
51+
<groupId>com.google.code.gson</groupId>
52+
<artifactId>gson</artifactId>
53+
<version>2.10.1</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.projectlombok</groupId>
57+
<artifactId>lombok</artifactId>
58+
<version>1.18.24</version>
59+
<scope>provided</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.junit.jupiter</groupId>
63+
<artifactId>junit-jupiter-engine</artifactId>
64+
<version>5.9.2</version>
65+
<scope>test</scope>
66+
</dependency>
67+
</dependencies>
68+
69+
<build>
70+
<pluginManagement>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.sonatype.plugins</groupId>
74+
<artifactId>nexus-staging-maven-plugin</artifactId>
75+
<version>1.6.13</version>
76+
<extensions>true</extensions>
77+
<configuration>
78+
<serverId>ossrh</serverId>
79+
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
80+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
81+
</configuration>
82+
</plugin>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-deploy-plugin</artifactId>
86+
<version>3.0.0</version>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-source-plugin</artifactId>
91+
<version>3.2.1</version>
92+
<executions>
93+
<execution>
94+
<id>attach-sources</id>
95+
<goals>
96+
<goal>jar-no-fork</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-javadoc-plugin</artifactId>
104+
<version>3.5.0</version>
105+
<executions>
106+
<execution>
107+
<id>attach-javadocs</id>
108+
<goals>
109+
<goal>jar</goal>
110+
</goals>
111+
</execution>
112+
</executions>
113+
</plugin>
114+
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
116+
<artifactId>maven-gpg-plugin</artifactId>
117+
<version>3.0.1</version>
118+
<executions>
119+
<execution>
120+
<id>sign-artifacts</id>
121+
<phase>verify</phase>
122+
<goals>
123+
<goal>sign</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
<configuration>
128+
<gpgArguments>
129+
<gpgArgument>--pinentry-mode</gpgArgument>
130+
<gpgArgument>loopback</gpgArgument>
131+
</gpgArguments>
132+
</configuration>
133+
</plugin>
134+
</plugins>
135+
</pluginManagement>
136+
137+
<plugins>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-compiler-plugin</artifactId>
141+
<version>3.10.1</version>
142+
<configuration>
143+
<source>17</source>
144+
<target>17</target>
145+
</configuration>
146+
</plugin>
147+
<plugin>
148+
<groupId>org.apache.maven.plugins</groupId>
149+
<artifactId>maven-surefire-plugin</artifactId>
150+
<version>2.22.2</version>
151+
</plugin>
152+
</plugins>
153+
</build>
154+
155+
<profiles>
156+
<profile>
157+
<id>release</id>
158+
<build>
159+
<plugins>
160+
<plugin>
161+
<groupId>org.sonatype.plugins</groupId>
162+
<artifactId>nexus-staging-maven-plugin</artifactId>
163+
<version>1.6.13</version>
164+
</plugin>
165+
<plugin>
166+
<groupId>org.apache.maven.plugins</groupId>
167+
<artifactId>maven-source-plugin</artifactId>
168+
<version>3.2.1</version>
169+
</plugin>
170+
<plugin>
171+
<groupId>org.apache.maven.plugins</groupId>
172+
<artifactId>maven-gpg-plugin</artifactId>
173+
<version>3.0.1</version>
174+
</plugin>
175+
<plugin>
176+
<groupId>org.apache.maven.plugins</groupId>
177+
<artifactId>maven-javadoc-plugin</artifactId>
178+
<version>3.5.0</version>
179+
</plugin>
180+
</plugins>
181+
</build>
182+
</profile>
183+
</profiles>
184+
<distributionManagement>
185+
<repository>
186+
<id>ossrh</id>
187+
<name>Central Repository OSSRH</name>
188+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
189+
</repository>
190+
</distributionManagement>
191+
192+
</project>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2023 Artyom Nefedov
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package io.github.artemnefedov.javaai.models.Image;
26+
27+
import io.github.artemnefedov.javaai.models.OpenAIBase;
28+
import io.github.artemnefedov.javaai.util.Config;
29+
import lombok.Getter;
30+
import lombok.Setter;
31+
32+
import java.io.IOException;
33+
34+
/**
35+
* ImageBuilder is a class for creating an image by hint, you can learn more
36+
* about the parameters by following
37+
* <a href="https://platform.openai.com/docs/api-reference/images/create">this link</a>.
38+
*
39+
* @author <a href="https://github.com/artemnefedov">Artyom Nefedov</a>.
40+
*/
41+
@Getter
42+
@Setter
43+
public class ImageBuilder extends OpenAIBase {
44+
45+
/**
46+
* API_KEY derived from <a href="https://platform.openai.com/account/api-keys">OpenAI</a>.
47+
*/
48+
private String API_KEY;
49+
50+
51+
/**
52+
* The number of images to generate. Must be between 1 and 10.
53+
*/
54+
private int n = 1;
55+
56+
/**
57+
* The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
58+
*/
59+
private String size = "1024x1024";
60+
61+
/**
62+
* The format in which the generated images are returned. Must be one of url or b64_json.
63+
*/
64+
private String response_format = "url";
65+
66+
/**
67+
* ImageBuilder constructor with the API key.
68+
*
69+
* @param API_KEY key derived from <a href="https://platform.openai.com/account/api-keys">OpenAI</a>.
70+
*/
71+
public ImageBuilder(String API_KEY) {
72+
this.API_KEY = API_KEY;
73+
}
74+
75+
/**
76+
* The createImage() method creates an image according to a given request.
77+
*
78+
* @param prompt A text description of the desired image(s). The maximum length is 1000 characters.
79+
* @return url or b64_json, depending on the given response_format.
80+
* @throws IOException if there is an error when connecting to the OpenAI API.
81+
*/
82+
public String createImage(String prompt) throws IOException {
83+
84+
params.clear();
85+
86+
params.put("prompt", prompt);
87+
params.put("size", getSize());
88+
params.put("n", getN());
89+
params.put("response_format", getResponse_format());
90+
91+
params.put("API", getAPI_KEY());
92+
params.put("url", getBaseUrl() + Config.getInstance().getProperties("url.openai.image_generator"));
93+
params.put("typeResponse", "image");
94+
95+
return enquire(params);
96+
}
97+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2023 Artyom Nefedov
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package io.github.artemnefedov.javaai.models.Image;
26+
27+
import lombok.Getter;
28+
import lombok.Setter;
29+
30+
import java.util.List;
31+
32+
/**
33+
* ImageResponse is a class for formatting the response from the API
34+
* and outputting the result in a normal form.
35+
*
36+
* @author <a href="https://github.com/artemnefedov">Artyom Nefedov</a>.
37+
*/
38+
@Getter
39+
@Setter
40+
public class ImageResponse {
41+
42+
/**
43+
* Set of values returned by the API.
44+
*/
45+
private long created;
46+
private List<Data> data;
47+
48+
@Getter
49+
@Setter
50+
private static class Data {
51+
52+
/**
53+
* Link to the finished image.
54+
*/
55+
private String url;
56+
}
57+
58+
/**
59+
* The getResponse() method returns a link to the image.
60+
*
61+
* @return a link to the image
62+
*/
63+
public String getResponse() {
64+
return getData().get(0).getUrl();
65+
}
66+
}

0 commit comments

Comments
 (0)