Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<img src="images/intelligent_java_header.png">
<img src="images/intelligent_java_header.png" width="500em">
</p>

<p align="center">
Expand All @@ -16,22 +16,21 @@
<img src="https://img.shields.io/github/license/Barqawiz/IntelliJava?style=flat-square" />
</a>

<img src="https://awesome.re/badge.svg" />
</p>

# Intelligent Java
Intelligent java (IntelliJava) is the ultimate tool to integrate with the latest language models and deep learning frameworks using java. The library provides an intuitive functions for sending input to models like GPT-3 and DALL·E, and receiving generated text, speech or images. With just a few lines of code, you can easily access the power of cutting-edge AI models to enhance your projects.
Intelligent java (IntelliJava) is the ultimate tool to integrate with the latest language models and deep learning frameworks using java. The library provides an intuitive functions for sending input to models like ChatGPT and DALL·E, and receiving generated text, speech or images. With just a few lines of code, you can easily access the power of cutting-edge AI models to enhance your projects.

The supported models:
- **OpenAI**: Access GPT-3 to generate text and DALL·E to generate images. OpenAI is preferred for quality results without tuning.
- **OpenAI**: Access ChatGPT, GPT3 to generate text and DALL·E to generate images. OpenAI is preferred for quality results without tuning.
- **Cohere.ai**: Generate text; Cohere allows you to custom your language model to suit your specific needs.
- **Google AI**: Generate audio from text; Access DeepMind’s speech models.

# How to use

1. Add the maven dependency or import the core jar file (check the Integration section).
2. Add Gson dependency if using the jar file; otherwise, it's handled by maven or Gradle.
3. Call the ``RemoteLanguageModel`` for the language models, ``RemoteImageModel`` for image generation and ``RemoteSpeechModel`` for text to speech models.
3. Call the ``RemoteLanguageModel`` for the language models, ``RemoteImageModel`` for image generation and ``RemoteSpeechModel`` for text to speech models, ``Chatbot`` for ChatGPT.

## Integration
The package released to Maven Central Repository:
Expand All @@ -41,23 +40,23 @@ Maven:
<dependency>
<groupId>io.github.barqawiz</groupId>
<artifactId>intellijava.core</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
</dependency>
```

Gradle:

```
implementation 'io.github.barqawiz:intellijava.core:0.7.0'
implementation 'io.github.barqawiz:intellijava.core:0.8.0'
```

Gradle(Kotlin):
```
implementation("io.github.barqawiz:intellijava.core:0.7.0")
implementation("io.github.barqawiz:intellijava.core:0.8.0")
```

Jar download:
[intellijava.jar](https://repo1.maven.org/maven2/io/github/barqawiz/intellijava.core/0.7.0/intellijava.core-0.7.0.jar).
[intellijava.jar](https://repo1.maven.org/maven2/io/github/barqawiz/intellijava.core/0.8.0/intellijava.core-0.8.0.jar).

## Code Example
**Language model code** (2 steps):
Expand All @@ -72,7 +71,9 @@ LanguageModelInput langInput = new LanguageModelInput.Builder("Summarize the plo
String resValue = langModel.generateText(langInput);
```
Output:```Inception follows Dom Cobb, a professional thief, who is offered a chance at redemption in exchange for planting an idea in a target's mind. He must navigate a dangerous landscape of dream-sharing technology and battle his inner demons in order to complete the mission and find his way back to reality.```
<br><br>

<br>

**Image generation code** (2 steps):
```java
// 1- initiate the remote image model
Expand All @@ -85,7 +86,9 @@ List<String> images = imageModel.generateImages(imageInput);
```
Output:<br>
<img src="images/response_image.png" height="220px">
<br><br>

<br>

**Text to speech code** (2 steps):
```java
// 1- initiate the remote speech model
Expand All @@ -101,6 +104,26 @@ Output:<br>
AudioHelper.saveTempAudio(decodedAudio);
```

<br>

**ChatGPT code**:
```java
// 1- initiate the chat model.
Chatbot bot = new Chatbot(apiKey, SupportedChatModels.openai);

// 2- prepare the chat history by calling addMessage.
String mode = "You are a helpful astronomy assistant.";
ChatModelInput input = new ChatGPTInput.Builder(mode)
.addUserMessage("what is the space between moon and earth")
.build();

// 3- call chat!
List<String> resValues = bot.chat(input);
```
Output:``` The average distance between the Moon and the Earth is about 238,855 miles (384,400 kilometers). ```

<br>

For full examples and ready integration try [the sample_code](https://github.com/Barqawiz/IntelliJava/tree/main/sample_code).

## Third-party dependencies
Expand All @@ -116,7 +139,7 @@ For jar download:

# Roadmap
Call for contributors:
- [x] Add support to OpenAI Completion API.
- [x] Add support to OpenAI Completion.
- [x] Add support to OpenAI DALL·E 2.
- [ ] Add support to other OpenAI functions.
- [x] Add support to cohere generate API.
Expand Down
2 changes: 1 addition & 1 deletion core/com.intellijava.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.barqawiz</groupId>
<artifactId>intellijava.core</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>

<name>Intellijava</name>
<description>IntelliJava allows java developers to easily integrate with the latest language models, image generation, and deep learning frameworks.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,97 @@

import com.intellijava.core.model.OpenaiImageResponse;
import com.intellijava.core.model.OpenaiImageResponse.Data;
import com.intellijava.core.model.SupportedImageModels;
import com.intellijava.core.model.input.ImageModelInput;
import com.intellijava.core.wrappers.OpenAIWrapper;

/**
*
* The RemoteImageModel class is used to generate images from text descriptions using an API key.
* It currently supports OpenAI only.
*
* The class uses the OpenAIWrapper to generate the images and returns a list of URLs for the generated images.
*
* @author github.com/Barqawiz
*/
public class RemoteImageModel {

private String keyType;
private SupportedImageModels keyType;
private OpenAIWrapper openaiWrapper;

/**
*
* Constructor for creating a new RemoteImageModel object.
*
* Creates an instance of the class and sets up the API key and the key type.
* Creates an instance of the class and set the API key value and type.
*
* @param keyValue the API key.
* @param keyType support openai only.
* @param keyTypeString support openai only.
*
* @throws IllegalArgumentException if the keyType passed is not "openai".
*
*/
public RemoteImageModel(String keyValue, String keyType) {
public RemoteImageModel(String keyValue, String keyTypeString) {

if (keyType.isEmpty() || keyType.equals("openai")) {
this.keyType = "openai";
openaiWrapper = new OpenAIWrapper(keyValue);
if (keyTypeString.isEmpty()) {
keyTypeString = SupportedImageModels.openai.toString();
}

List<String> supportedModels = this.getSupportedModels();

if (supportedModels.contains(keyTypeString)) {
this.initiate(keyValue, SupportedImageModels.valueOf(keyTypeString));
} else {
throw new IllegalArgumentException("This version support openai keyType only");
String models = String.join(" - ", supportedModels);
throw new IllegalArgumentException("The received keyValue not supported. Send any model from: " + models);
}
}

/**
*
* Constructor for creating a new RemoteImageModel object.
*
* Creates an instance of the class and set the API key value and type.
*
* @param keyValue the API key.
* @param keyType the model type from SupportedImageModels enum.
*/
public RemoteImageModel(String keyValue, SupportedImageModels keyType) {
initiate(keyValue, keyType);
}

/**
* Get the supported models names as array of string
*
* @return supportedModels
*/
public List<String> getSupportedModels() {
SupportedImageModels[] values = SupportedImageModels.values();
List<String> enumValues = new ArrayList<>();

for (int i = 0; i < values.length; i++) {
enumValues.add(values[i].name());
}

return enumValues;
}

/**
* Common function to initiate the class from any constructor.
*
* @param keyValue the API key.
* @param keyType enum of supported models.
*/
private void initiate(String keyValue, SupportedImageModels keyType) {
// set the model type
this.keyType = keyType;

// generate the related model
if (keyType.equals(SupportedImageModels.openai)) {
this.openaiWrapper = new OpenAIWrapper(keyValue);
}
}

/**
*
* Generates images from a given text description.
Expand All @@ -71,7 +124,7 @@ public RemoteImageModel(String keyValue, String keyType) {
*/
public List<String> generateImages(ImageModelInput imageInput) throws IOException {

if (this.keyType.equals("openai")) {
if (this.keyType == SupportedImageModels.openai) {
return this.generateOpenaiImage(imageInput.getPrompt(),
imageInput.getNumberOfImages(), imageInput.getImageSize());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.intellijava.core.model.OpenaiLanguageResponse;
import com.intellijava.core.model.OpenaiLanguageResponse.Choice;
import com.intellijava.core.model.SupportedLangModels;
import com.intellijava.core.model.OpenaiImageResponse.Data;
import com.intellijava.core.model.input.LanguageModelInput;
import com.intellijava.core.wrappers.CohereAIWrapper;
import com.intellijava.core.wrappers.OpenAIWrapper;
Expand Down Expand Up @@ -55,7 +54,7 @@ public class RemoteLanguageModel {
/**
* Constructor for the RemoteLanguageModel class.
*
* Creates an instance of the class and sets up the key and the API type.
* Creates an instance of the class and set the API type and key.
*
* @param keyValue the API key.
* @param keyTypeString either openai (default) or cohere or send empty string
Expand Down Expand Up @@ -83,8 +82,8 @@ public RemoteLanguageModel(String keyValue, String keyTypeString) {
/**
* Constructor for the RemoteLanguageModel class.
*
* Creates an instance of the class and sets up the API key and the enum key
* type.
* Creates an instance of the class and set the API enum type and key.
*
*
* @param keyValue the API key.
* @param keyType enum version from the key type (SupportedModels).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Map;
import com.intellijava.core.model.AudioResponse;
import com.intellijava.core.model.SpeechModels;
import com.intellijava.core.model.input.SpeechInput;
import com.intellijava.core.model.input.SpeechInput.Gender;
import com.intellijava.core.model.input.Text2SpeechInput;
import com.intellijava.core.model.input.Text2SpeechInput.Gender;
import com.intellijava.core.utils.AudioHelper;
import com.intellijava.core.wrappers.GoogleAIWrapper;

Expand Down Expand Up @@ -118,7 +118,7 @@ public List<String> getSupportedModels() {
* @return byte array of the decoded audio content.
* @throws IOException in case of communication error.
*/
public byte[] generateEnglishText(SpeechInput input) throws IOException {
public byte[] generateEnglishText(Text2SpeechInput input) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), "en-gb");
Expand Down
Loading