Skip to content

Commit 7560814

Browse files
committed
update the sample to support the library V0.6.0
Main change in V0.6.0 is the support of Cohere ai generate model and flexible constructor for the remote language model.
1 parent 7cb9d59 commit 7560814

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

sample_code/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<attribute name="module" value="true"/>
88
</attributes>
99
</classpathentry>
10-
<classpathentry kind="lib" path="jars/com.intellijava.core-0.4.0.jar"/>
1110
<classpathentry kind="lib" path="jars/gson-2.8.9.jar"/>
11+
<classpathentry kind="lib" path="jars/intellijava.core-0.6.0.jar"/>
1212
<classpathentry kind="output" path="bin"/>
1313
</classpath>

sample_code/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/
-19.4 KB
Binary file not shown.
130 KB
Binary file not shown.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.intelliJava.test;
2+
3+
import java.io.IOException;
4+
5+
import com.intellijava.core.controller.RemoteLanguageModel;
6+
import com.intellijava.core.model.input.LanguageModelInput;
7+
8+
public class CohereApp {
9+
10+
public static void main(String[] args) {
11+
12+
System.out.println("Start calling the API!");
13+
14+
try {
15+
16+
// get the api key from https://dashboard.cohere.ai/
17+
// TODO: replace <cohere-api-key> with your API key.
18+
String apiKey = "<cohere-api-key>";
19+
20+
/********************************/
21+
/** 1- Call the language model **/
22+
/********************************/
23+
tryTheLanguageModel(apiKey);
24+
25+
} catch (IOException e) {
26+
e.printStackTrace();
27+
}
28+
29+
}
30+
31+
private static void tryTheLanguageModel(String apiKey) throws IOException {
32+
// initiate the remote language model wrapper with cohere details
33+
RemoteLanguageModel langModel = new RemoteLanguageModel(apiKey, "cohere");
34+
35+
// prepare the input parameters - change the prompt to any text like "write a
36+
// funny short story"
37+
LanguageModelInput langInput = new LanguageModelInput.Builder("Once upon a time in a magical land called")
38+
.setModel("xlarge").setTemperature(0.7f).setMaxTokens(50).build();
39+
40+
String resValue = langModel.generateText(langInput);
41+
42+
// print language model output
43+
System.out.println("Language model output:\n" + resValue);
44+
}
45+
46+
}

sample_code/src/com/intelliJava/test/App.java renamed to sample_code/src/com/intelliJava/test/OpenaiApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
*
3030
*/
31-
public class App {
31+
public class OpenaiApp {
3232

3333
public static void main(String[] args) {
3434

0 commit comments

Comments
 (0)