Skip to content

Commit 33571d2

Browse files
committed
update language model to support multi text output
- update implementation files. - update the test case. - update the sample file. - update the readme. - generate new version for maven public.
1 parent 4513ed7 commit 33571d2

File tree

13 files changed

+81
-12
lines changed

13 files changed

+81
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Intelligent Java
2-
*IntelliJava V0.6.0*
2+
*IntelliJava V0.6.1*
33

44
Intelligent java (IntelliJava) is the ultimate tool for Java developers looking to integrate with the latest language models and deep learning frameworks. The library provides a simple and intuitive API with convenient methods for sending text input to models like GPT-3 and DALL·E, and receiving generated text or images in return. With just a few lines of code, you can easily access the power of cutting-edge AI models to enhance your projects.
55

@@ -14,14 +14,14 @@ The supported models:
1414
3. Call the ``RemoteLanguageModel`` for the language models and ``RemoateImageModel`` for image generation.
1515

1616
## Integration
17-
The package released to [Maven Central Repository](https://central.sonatype.dev/artifact/io.github.barqawiz/intellijava.core/0.6.0).
17+
The package released to [Maven Central Repository](https://central.sonatype.com/artifact/io.github.barqawiz/intellijava.core/0.6.1).
1818

1919
Maven:
2020
```xml
2121
<dependency>
2222
<groupId>io.github.barqawiz</groupId>
2323
<artifactId>intellijava.core</artifactId>
24-
<version>0.6.0</version>
24+
<version>0.6.1</version>
2525
</dependency>
2626
```
2727

core/com.intellijava.core/src/main/java/com/intellijava/core/controller/RemoteLanguageModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public String generateText(LanguageModelInput langInput) throws IOException {
167167
*
168168
* @param langInput flexible builder for language model parameters.
169169
*
170-
* @return List<String> for the model responses.
170+
* @return list of model responses.
171171
* @throws IOException if there is an error when connecting to the
172172
* OpenAI API.
173173
* @throws IllegalArgumentException if the keyType passed in the constructor is

core/com.intellijava.core/src/main/java/com/intellijava/core/model/CohereLanguageResponse.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ public class CohereLanguageResponse extends BaseRemoteModel{
1515
private List<Generation> generations;
1616
private String prompt;
1717

18+
/**
19+
* CohereLanguageResponse default constructor.
20+
*/
21+
public CohereLanguageResponse() {
22+
23+
}
24+
1825
/**
1926
*
2027
* Generation is wrapper for the response
@@ -26,6 +33,13 @@ public static class Generation {
2633
private String id;
2734
private String text;
2835

36+
/**
37+
* Generation default constructor.
38+
*/
39+
public Generation() {
40+
41+
}
42+
2943
/**
3044
* Get the unique identifier for the generation.
3145
*

core/com.intellijava.core/src/main/java/com/intellijava/core/model/input/LanguageModelInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private LanguageModelInput(Builder builder) {
2828
this.prompt = builder.prompt;
2929
this.temperature = builder.temperature;
3030
this.maxTokens = builder.maxTokens;
31-
this.maxTokens = builder.numberOfOutputs;
31+
this.numberOfOutputs = builder.numberOfOutputs;
3232
}
3333
/**
3434
*

core/com.intellijava.core/src/main/java/com/intellijava/core/utils/ConnHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ public static String readStream(InputStream stream) throws IOException {
108108
}
109109
}
110110
return result.toString();
111-
}
111+
}
112112
}

core/com.intellijava.core/src/main/java/com/intellijava/core/wrappers/CohereAIWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/**
1717
*
18+
* Wrapper for the Cohere API models.
1819
*
1920
* @author github.com/Barqawiz
2021
*

core/com.intellijava.core/src/main/java/com/intellijava/core/wrappers/OpenAIWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.intellijava.core.wrappers;
1717

18+
import java.io.BufferedReader;
1819
import java.io.IOException;
1920
import java.io.InputStreamReader;
2021
import java.io.OutputStream;
@@ -70,7 +71,7 @@ public BaseRemoteModel generateText(Map<String, Object> params) throws IOExcepti
7071
String url = API_BASE_URL + Config2.getInstance().getProperty("url.openai.completions");
7172

7273
String json = ConnHelper.convertMaptToJson(params);
73-
74+
7475
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
7576
connection.setRequestMethod("POST");
7677
connection.setRequestProperty("Content-Type", "application/json");

core/com.intellijava.core/src/test/java/com/intellijava/core/CohereModelConnectionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import com.intellijava.core.utils.Config2;
1616
import com.intellijava.core.wrappers.CohereAIWrapper;
1717

18+
/**
19+
*
20+
* Unit test for Remote Language Model
21+
*/
1822
public class CohereModelConnectionTest {
1923

2024
/**

core/com.intellijava.core/src/test/java/com/intellijava/core/OpenaiModelConnectionTest.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.intellijava.core.controller.RemoteLanguageModel;
2828
import com.intellijava.core.model.OpenaiImageResponse;
2929
import com.intellijava.core.model.OpenaiImageResponse.Data;
30+
import com.intellijava.core.model.SupportedLangModels;
3031
import com.intellijava.core.model.input.ImageModelInput;
3132
import com.intellijava.core.model.input.LanguageModelInput;
3233
import com.intellijava.core.utils.Config2;
@@ -51,10 +52,10 @@ public void testOpenaiCompletionRemoteModel() {
5152

5253
try {
5354

54-
RemoteLanguageModel wrapper = new RemoteLanguageModel(openaiKey, "openai");
55+
RemoteLanguageModel wrapper = new RemoteLanguageModel(openaiKey, SupportedLangModels.openai);
5556

5657
LanguageModelInput input = new LanguageModelInput.Builder("return a java code that print hello world")
57-
.setModel("text-davinci-002").setTemperature(0.7f).setMaxTokens(50).build();
58+
.setModel("text-davinci-003").setTemperature(0.7f).setMaxTokens(50).build();
5859

5960
if (openaiKey.isBlank()) return;
6061

@@ -75,6 +76,37 @@ public void testOpenaiCompletionRemoteModel() {
7576
}
7677
}
7778

79+
80+
@Test
81+
public void testOpenaiMultiTextCompletionRemoteModel() {
82+
83+
try {
84+
85+
RemoteLanguageModel wrapper = new RemoteLanguageModel(openaiKey, "openai");
86+
87+
LanguageModelInput input = new LanguageModelInput.Builder("Summarize the plot of the 'Inception' movie in two sentences")
88+
.setModel("text-davinci-003").setTemperature(0.7f)
89+
.setMaxTokens(80).setNumberOfOutputs(2).build();
90+
91+
if (openaiKey.isBlank()) return;
92+
93+
List<String> resValues = wrapper.generateMultiText(input);
94+
95+
for (String result : resValues)
96+
System.out.print("- " + result);
97+
98+
assert resValues.size() == 2;
99+
100+
} catch (IOException e) {
101+
if (openaiKey.isBlank()) {
102+
System.out.print("testOpenaiCompletion: set the API key to run the test case.");
103+
} else {
104+
fail("Test case failed with exception: " + e.getMessage());
105+
}
106+
107+
}
108+
}
109+
78110
@Test
79111
public void testImageWrapper() {
80112

sample_code/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</attributes>
99
</classpathentry>
1010
<classpathentry kind="lib" path="jars/gson-2.8.9.jar"/>
11-
<classpathentry kind="lib" path="jars/intellijava.core-0.6.0.jar"/>
11+
<classpathentry kind="lib" path="jars/intellijava.core-0.6.1.jar"/>
1212
<classpathentry kind="output" path="bin"/>
1313
</classpath>

0 commit comments

Comments
 (0)