|
| 1 | +# JavaAI is an open-source Java library for interacting with the OpenAI API |
| 2 | +[](https://search.maven.org/search?q=g:%22io.github.artemnefedov%22%20AND%20a:%22openaisdk%22) [](https://opensource.org/licenses/MIT) |
| 3 | + |
| 4 | +## The JavaAI Java SDK is a non-official open source library that allows Java developers to interact with OpenAI models with just a few lines of code. |
| 5 | + |
| 6 | +#### Note: |
| 7 | +> I wrote this library for myself because I couldn't find anything more convenient, so I decided to share my project with the community. I hope that I can help someone. |
| 8 | +Any help is welcome, I am always open to new ideas and criticism. |
| 9 | + |
| 10 | +## How to use it? |
| 11 | + |
| 12 | + |
| 13 | +### 1. Import the library into your project. |
| 14 | +#### Maven: |
| 15 | +```xml |
| 16 | +<dependency> |
| 17 | + <groupId>io.github.artemnefedov</groupId> |
| 18 | + <artifactId>openaisdk</artifactId> |
| 19 | + <version>0.1.1</version> |
| 20 | +</dependency> |
| 21 | +``` |
| 22 | +#### Gradle: |
| 23 | +```groovy |
| 24 | +implementation 'io.github.artemnefedov:openaisdk:0.1.1' |
| 25 | +``` |
| 26 | +#### or download the JAR file from the [releases page](https://github.com/artemnefedov/OpenAI/releases) |
| 27 | + |
| 28 | +### 2. Get the API key on the OpenAI website. |
| 29 | +[openai.com/account/api-keys](https://platform.openai.com/account/api-keys) |
| 30 | + |
| 31 | +### 3. Initialize the language model in your project. |
| 32 | +```java |
| 33 | +LanguageModel completions = new LanguageModel("YOUR_OPEN_AI_API-KEY"); |
| 34 | +``` |
| 35 | +#### Check out the [Wiki page](https://github.com/artemnefedov/OpenAI/wiki/Initialize-the-language-model-in-your-project) for other ways |
| 36 | + |
| 37 | +### 4. Set the query parameters and get the result from the OpenAI model. |
| 38 | + |
| 39 | +```java |
| 40 | +completions.setPrompt("What is the first line programmers print?") |
| 41 | + |
| 42 | +String result = completions.generateText(); |
| 43 | +``` |
| 44 | +**Conclusion:** `The first line a programmer typically prints is "Hello World!"` |
| 45 | + |
| 46 | +--- |
| 47 | +## Only [GTP-3](https://platform.openai.com/docs/models/gpt-3) is supported at the moment, already working on making it work with DALL-E 2. |
| 48 | + |
| 49 | +--- |
| 50 | +## Outside Dependencies. |
| 51 | +#### This library uses [Gson](https://github.com/google/gson), to convert JSON to Java objects. |
| 52 | + |
| 53 | +## License |
| 54 | +#### Distributed under the [MIT License](https://github.com/artemnefedov/OpenAI/blob/main/LICENSE) |
| 55 | +# JavaAI |
0 commit comments